[英]How to reshape a 1d array to a 3d array with diffrerent size of 2d arrays?
I want to reshape this array: np.array(np.arange(15))
to a 3d array that is built from a 3x3 array and a 3x2 array.我想重塑这个数组:
np.array(np.arange(15))
到一个 3d 数组,它是由一个 3x3 数组和一个 3x2 数组构建的。
I've tried to do it with the reshape method but it didn't work.我试过用 reshape 方法来做,但没有用。
I thought that maybe reshape
can get a number of tuples maybe.我想也许
reshape
可以得到一些元组。 a=np.array(np.arange(15)).reshape(1,((3,2),(3,3)))
but I then I saw it cant. a=np.array(np.arange(15)).reshape(1,((3,2),(3,3)))
但后来我看到它不能。
How can I reshape it then?那我该如何重塑呢? is there a nice way?
有什么好方法吗?
a multidimensional array can't have dimensions with different size.多维数组不能有不同大小的维度。
but if you want a tuple you will need to split the array in 2 parts, the first that match in size with the 3x3 array and the second that match the 3x2, at this point you'll have 2 one dimensional array, then reshape them但是如果你想要一个元组,你需要将数组分成两部分,第一部分与 3x3 数组的大小匹配,第二部分与 3x2 匹配,此时你将拥有 2 个一维数组,然后重塑它们
arr1 = arr1.reshape((3,3))
arr2 = arr2.reshape((3,2))
tuple = arr1, arr2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.