Postscript: I'm a beginner, so I don't know how to use NumPy at all lol Instead of creating and combining Numpy arrays in a loop All you have to do is create a multidimensional list and finally convert it with np.array (). Easy to implement and fast to operate.
In short, I wanted to do something like the article below. https://kakedashi-engineer.appspot.com/2020/02/28/multi-list-numpy/
numpy_join.py
# coding:UTF-8
import numpy as np
a = np.zeros((0,3))
for i in range(5):
b = np.array([1, 2, 3])
a = np.r_[a,b.reshape(1,-1)]
print a
I want to make a two-dimensional array in the end, so in this way
python
a = np.zeros((0,3))
The point is to do like this. The number of elements in one row is 3, and a two-dimensional array with 0 rows is created. You can use np.empty, but since it has 0 lines anyway, I dared to use np.zeros.
continue
python
a = np.r_[a,b.reshape(1,-1)]
However, note that b is reshaped to make a two-dimensional array.
result
[[ 1. 2. 3.]
[ 1. 2. 3.]
[ 1. 2. 3.]
[ 1. 2. 3.]
[ 1. 2. 3.]]
The desired result was obtained.
Recommended Posts