简体   繁体   中英

Numpy merge two arrays can i make a numpy array like this?

I am trying two array like this. It's different from column_stack so I am not able to find how to do it from documentation or google search.

I have arrays a and b . How can I make c from them ?

a = [[1, 2],[3, 4]]
b = [[5 , 6]]

c = [[[1, 2],[5]],
     [3, 4],[6]]]  

I need this to input the values to theanets.

In [54]:
a = np.array([[1, 2],[3, 4]])
a
Out[54]:
array([[1, 2],
       [3, 4]])

In [55]:
b = np.array([[5 , 6]])
b
Out[55]:
array([[5, 6]])


In [96]:
c = [[a[n].tolist() , b[:,n].tolist()] for n in range(len(a))]
c
Out[96]:
[[[1, 2], [5]], [[3, 4], [6]]]

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM