LoginSignup
0
2

More than 5 years have passed since last update.

Numpy > 2行3列のデータを5行3列の途中の行に入れる実装

Last updated at Posted at 2017-11-25
動作環境
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 16.04 LTS desktop amd64
TensorFlow v1.2.1
cuDNN v5.1 for Linux
CUDA v8.0
Python 3.5.2
IPython 6.0.0 -- An enhanced Interactive Python.
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
scipy v0.19.1
geopandas v0.3.0
MATLAB R2017b (Home Edition)

以下とする。

  • xs: 挿入する行列
  • v1: 挿入される行列

code v0.1

test_array_assign_171125.py
import numpy as np
import sys

# preparation
x1 = [3, 1, 4]
x2 = [1, 5, 9]
xs = [x1]
xs += [x2]
xs = np.array(xs).astype(float)
print(xs)
v1 = np.zeros((5, 3))  # 5: arbitrary

# assign
kidx = 2  # given
v1[kidx:kidx+2] = xs[0:2].copy()
print(v1)
run
$ python3 test_array_assign_171125.py 
[[ 3.  1.  4.]
 [ 1.  5.  9.]]
[[ 0.  0.  0.]
 [ 0.  0.  0.]
 [ 3.  1.  4.]
 [ 1.  5.  9.]
 [ 0.  0.  0.]]

念の為.copy()を使う。

v1[kidx:kidx+2] = xs[0:2].copy()

は行の数が整合していれば以下でもいい。

v1[kidx:kidx+2] = xs.copy()

MATLAB

MATLABでの以下のような実装に対応する。

v1(k:k+1,:) = trisectEdge(x(tri(j,1),:),x(tri(j,2),:));

trisectEdge()により2行の行列が得られる。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2