LoginSignup
0
1

More than 5 years have passed since last update.

MATLAB: vs = [v1 v2 v3 v4] ここでv1..v4は列ベクトル > Numpy実装

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)

MATLAB

K>> wv1 = [3; 1; 4]

wv1 =

     3
     1
     4

K>> wv2 = [1; 5; 9];
K>> wv3 = [2; 6; 5];
K>> wv4 = [3; 5; 8];
K>> wvs = [wv1 wv2 wv3 wv4]

wvs =

     3     1     2     3
     1     5     6     5
     4     9     5     8

Numpy 実装

test_array_add_171125.py
import numpy as np


def add_to_array_vertical(vlist):
    ret = np.transpose(vlist).reshape(len(vlist[0]), len(vlist))
    return ret

v1 = np.array([3, 1, 4])
v2 = np.array([1, 5, 9])
v3 = np.array([2, 6, 5])
v4 = np.array([3, 5, 8])

res = add_to_array_vertical([v1, v2, v3, v4])
print(res)

run
$ python3 test_array_add_171125.py 
[[3 1 2 3]
 [1 5 6 5]
 [4 9 5 8]]
0
1
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
1