1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Numpy: v1 = [[3, 1, 4],[1, 5, 9]] から [[3, 1, 4],[1, 5, 9],[3, 1, 4],[1, 5, 9]]を作る > np.concatenate()

Last updated at Posted at 2017-11-24
動作環境
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)

numpy.array()同士の結合を実装する。

test_array_plus_171125.py
import numpy as np

v1 = [
    [3, 1, 4],
    [1, 5, 9],
    ]
v1 = np.array(v1)

# case 1
vs = v1 + v1
print(vs)

# case 2
vs = []
vs += [*v1]
vs += [*v1]
vs = np.array(vs)
print(vs)
run
$ python3 test_array_plus_171125.py 
[[ 6  2  8]
 [ 2 10 18]]
[[3 1 4]
 [1 5 9]
 [3 1 4]
 [1 5 9]]

case1では要素同士の足し算になる。
case2により希望の動作になった。

v1, v2, v3がある時の結合を想定している。

教えていただいた事項

@redshoga さんのコメント
にてnp.concatenate()を教えていただきました。

実装中のコードにて使わせていただいてます。

情報感謝です。

1
1
3

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?