python-3.x - 值错误: cannot resize this array: it does not own its data

标签 python-3.x numpy keras

ValueError:无法调整此数组的大小:它不拥有其数据

from keras.datasets import cifar10
import numpy as np


(X_train, y_train), (X_test, y_test) = cifar10.load_data()

X_train1 = X_train.copy().ravel()
y_train1 = y_train.copy().ravel()

X_train2 = X_train1.resize(64*64*500)
y_train2 = y_train1.resize(64*64*500)

X_train = X_train2.resize(64*64*500).reshape(64, 64, 1)
y_train = y_train2.resize(64*64*500).reshape(64, 64, 1)

为什么在显式复制数据后出现此错误?如何解决这个问题?

最佳答案

使用numpy中的reshape,将行更改为

X_train2 = np.resize(X_train1, 64*64*500)
y_train2 = np.resize(y_train1, 64*64*500)

关于python-3.x - 值错误: cannot resize this array: it does not own its data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53686986/

相关文章:

python - 游戏图像识别(识别《Flappy Bird》中的得分或游戏结束)

python - TypeError : An asyncio. Future,需要协程或等待

python-3.x - 如何根据 AUC 指标在 Keras 中保存最佳模型?

python - 如何在控制台中使输入文本加粗?

python - 在 SciPy 中生成一个又高又瘦的随机正交矩阵

python - 加载 float+ 字符串表

python - 无属性 'get_default_graph'

python - 评估模型给出的准确度不等于 sklearn 分类报告准确度

python - 如何初始化现有 Keras 模型的变量?

python - 可选参数约束