During preparing data for NumPy calculate. I am curious about way to construct:
myarray.shape => (2,18,18)
from:
d1.shape => (18,18) d2.shape => (18,18)
I try to use NumPy command:
hstack([[d1],[d2]])
but it looks not work!
Importing the NumPy package enables us to use the array function in python. To create a three-dimensional array, we pass the object representing x by y by z in python, where x is the nested lists in the object, y is the nested lists inside the x nested lists, and z is the values inside each y nested list.
Creating arrays with more than one dimension In general numpy arrays can have more than one dimension. One way to create such array is to start with a 1-dimensional array and use the numpy reshape() function that rearranges elements of that array into a new shape.
One way is to use np. dstack which concatenates the arrays along the third axis (d is for depth). You could also use np. concatenate((a, a), axis=2) .
Just doing d3 = array([d1,d2])
seems to work for me:
>>> from numpy import array >>> # ... create d1 and d2 ... >>> d1.shape (18,18) >>> d2.shape (18,18) >>> d3 = array([d1, d2]) >>> d3.shape (2, 18, 18)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With