Python 3.x 如何将一个小数组复制到一个大数组上?
我正在尝试将一个大小为(829,1)的小numpy ndarray复制到一个大小为(3047,1)的大numpy ndarray上 我的代码如下Python 3.x 如何将一个小数组复制到一个大数组上?,python-3.x,numpy,numpy-ndarray,Python 3.x,Numpy,Numpy Ndarray,我正在尝试将一个大小为(829,1)的小numpy ndarray复制到一个大小为(3047,1)的大numpy ndarray上 我的代码如下 highest = 3047 features = loadmat(f"./{file}.sbow.mat") current_features = np.zeros((highest, 1), dtype=int) print(type(current_features)) print(type(features["im
highest = 3047
features = loadmat(f"./{file}.sbow.mat")
current_features = np.zeros((highest, 1), dtype=int)
print(type(current_features))
print(type(features["image_sbow"]))
print(current_features.shape)
print(features["image_sbow"].shape)
current_features[:features["image_sbow"].shape[0], :1] = features["image_sbow"]
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
(3047, 1)
(829, 1)
我得到的输出如下所示
highest = 3047
features = loadmat(f"./{file}.sbow.mat")
current_features = np.zeros((highest, 1), dtype=int)
print(type(current_features))
print(type(features["image_sbow"]))
print(current_features.shape)
print(features["image_sbow"].shape)
current_features[:features["image_sbow"].shape[0], :1] = features["image_sbow"]
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
(3047, 1)
(829, 1)
(3047, 1)
(829, 1)
下面给出了我得到的错误
highest = 3047
features = loadmat(f"./{file}.sbow.mat")
current_features = np.zeros((highest, 1), dtype=int)
print(type(current_features))
print(type(features["image_sbow"]))
print(current_features.shape)
print(features["image_sbow"].shape)
current_features[:features["image_sbow"].shape[0], :1] = features["image_sbow"]
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
(3047, 1)
(829, 1)
ValueError:无法从结构强制转换为非结构,除非
结构只有一个字段
您需要更详细地检查
功能[“image\u show”]
数组,而不仅仅是类型
和形状
。数据类型是什么。根据这个错误,我认为它不是int
。这是更复杂的事情。