![]() stack0 = np.stack((a1, a1, a2, a2)) # default stack along 0th axis print(stack0.shape) > (4, 12) print(stack0) > ] By default, np.stack() stacks arrays along the 0th dimension (rows) (parameter axis=0). Use np.stack()to concatenate/stack arrays. print(a1_2d) # 3_4 > ] print(a1_2d.ravel()) # ravel by row (default order='C') > print(a1_2d.ravel(order='F')) # ravel by column > Concatenate/stack arrays with np.stack() and np.hstack()Ĭreate two 1D arrays a1 = np.arange(1, 13) print(a1) > a2 = np.arange(13, 25) print(a2) > If you want to flatten/ravel along the columns (1st dimension), use the order parameter. If you don’t specify any parameters, ravel()will flatten/ravel our 2D array along the rows (0th dimension/axis). Our 2D array ( 3_4) will be flattened or raveled such that they become a 1D array with 12 elements. The ravel() method lets you convert multi-dimensional arrays to 1D arrays (see docs here). ![]() To convert to a 1_12 array, use reshape(). Test: What’s the dimension/shape of array a1?Ī1 is a 1D array - it has only 1 dimension, even though you might think it’s dimension should be 1_12 (1 row by 12 columns).
0 Comments
Leave a Reply. |