[英]How do I assign a 3d numpy array of different sizes to each element of a numpy vector?
Here are the situations: 这里是情况:
x.shape = (20,)
x1 = x [0,]
x2 = x [1,]
x3 = x [2,]
... ...
The shapes of x1, x2, x3 ... are all different. x1,x2,x3 ...的形状都不同。
For example, 例如,
x1.shape = (300, 400, 3)
x2.shape = (280, 520, 3)
x3.shape = (330, 400, 3)
I have a 3d numpy array of different sizes 我有一个不同大小的3d numpy数组
I want to assign it to each element of vector called x. 我想将其分配给向量的每个元素x。
What should I do? 我该怎么办?
Make your elements first, then create your x
array from them 首先制作您的元素,然后根据它们创建
x
数组
x = numpy.array([x1, x2, x3])
A modern numpy
will automatically use dtype=object
whereas in previous versions you had to add dtype=object
explicitly. 现代的
numpy
将自动使用dtype=object
而在以前的版本中,您必须显式添加dtype=object
。
This isn't really much different from using a plain Python list
though: 不过,这与使用普通的Python
list
并没有太大区别:
x = [x1, x2, x3]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.