Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 大小为(192,1)的数组上的numpy.random.permutation_Python_Arrays_Numpy_Image Processing_Shuffle - Fatal编程技术网

Python 大小为(192,1)的数组上的numpy.random.permutation

Python 大小为(192,1)的数组上的numpy.random.permutation,python,arrays,numpy,image-processing,shuffle,Python,Arrays,Numpy,Image Processing,Shuffle,所以我有一个机器学习模型,它接受成批的图像和相应的标签。该模型应该输出一个预测,它认为一个前所未有的全新形象属于哪个类别(标签)。我的程序中有一段代码,在我手动分类每个图像时,它会洗牌训练图像和标签。洗牌前的标签如下所示:[0,0,0,0,0,1,1,1,1]。这是我当前的洗牌代码: permutation = np.random.permutation(len(train_labels)) train_images = train_images[permutation] train_label

所以我有一个机器学习模型,它接受成批的图像和相应的标签。该模型应该输出一个预测,它认为一个前所未有的全新形象属于哪个类别(标签)。我的程序中有一段代码,在我手动分类每个图像时,它会洗牌训练图像和标签。洗牌前的标签如下所示:
[0,0,0,0,0,1,1,1,1]
。这是我当前的洗牌代码:

permutation = np.random.permutation(len(train_labels))
train_images = train_images[permutation]
train_labels = train_labels[permutation]
Traceback (most recent call last):
  File "C:/Users/Mason Choi/PycharmProjects/Passion_project/main (test).py", line 43, in <module>
    train_labels = train_labels[permutation]
TypeError: only integer scalar arrays can be converted to a scalar index

Process finished with exit code 1
列车图像形状如下所示:
(192,7,36,64,1)

列车标签形状如下所示:
(192,1)

我得到的火车标签洗牌的错误和回溯:

permutation = np.random.permutation(len(train_labels))
train_images = train_images[permutation]
train_labels = train_labels[permutation]
Traceback (most recent call last):
  File "C:/Users/Mason Choi/PycharmProjects/Passion_project/main (test).py", line 43, in <module>
    train_labels = train_labels[permutation]
TypeError: only integer scalar arrays can be converted to a scalar index

Process finished with exit code 1
回溯(最近一次呼叫最后一次):
文件“C:/Users/Mason Choi/PycharmProjects/Passion_project/main(test).py”,第43行,在
序列标签=序列标签[排列]
TypeError:只能将整数标量数组转换为标量索引
进程已完成,退出代码为1

我认为
tf
中的切片没有
numpy中的切片功能那么多。我不确定您在
tf
中的行为是否合法。我正在查看您的错误消息。train_图像似乎是tf阵列,而不是numpy阵列。同时查看错误消息,如果排列是tf数组,那么这似乎可以工作。我对tf的了解还不够,不知道如何使用该框架创建一个随机排列,但应该有一个。为什么不使用tf中的内置函数洗牌数据集,比如?啊,非常感谢你为我捕捉到了这一点,我没有意识到我使用Tensorflow将numpy数组转换为浮点值。我已经更新了帖子,只包含了第二个错误,我现在被卡住了,但是再次感谢你让我通过了第一个错误!另外,我不想使用tf.random.shuffle的原因是,我必须编写更多的代码来按索引洗牌训练图像和标签,以便它们仍然配对。但是,如果有人想走这条路,这里有一个链接,指向如何做到这一点: