This Python 3.8 code snippet:
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
a = np.concatenate((a, b), axis=0)
print(a)
produces:
[[1 2]
[3 4]
[5 6]]
as expected. How do I define an empty array e
, such that this code produces the same result:
# define en empty array e here
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
e = np.concatenate((e, a), axis=0)
e = np.concatenate((e, b), axis=0)
print(e)
Found it:
e = np.empty((0, 2))
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
e = np.concatenate((e, a), axis=0)
e = np.concatenate((e, b), axis=0)
print(e)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.