布尔索引与维度 1 上的索引数组不匹配;维度为 2 但对应的布尔维度为 1
我正在尝试使用 PCA 和 T-SNE 来解决降维问题。我被困在这一步了。错误是“ IndexError: 布尔索引与维度 0 上的索引数组不匹配;维度为 180000 但相应的布尔维度为 60000” 我尝试在网上查找可能的解决方案,我找到了解决方案,它说要降低我的张量流版本和keras 和我做到了,但没有成功。我试图寻找更多可能的解决方案,但没有找到任何相关的内容。我将我的代码添加到这个问题中。谁能指导我这个吗?
from keras.datasets import cifar10
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
from matplotlib import pyplot as plt
import numpy as np
%matplotlib inline
plt.rcParams['figure.figsize'] = [12, 9]
(x_train, x_test), (y_train, y_test) = cifar10.load_data()
train = np.concatenate((x_train, y_train))
test = np.concatenate((x_test, y_test))
(x_train.shape)
y_train
print(x_train.shape)
print(y_train.shape)
print(x_test.shape)
print(y_test.shape)
train=np.concatenate((x_train,y_train))
test=np.concatenate((x_test,y_test))
print(train.shape)
print(test.shape)
pca = PCA(n_components=2)
%%time
reduced = pca.fit_transform(train.reshape(-1, 32 * 32))
for i in range(10):
num = reduced[test == i]
plt.scatter(num[:, 0], num[:, 1], s=5, label=f'{i}')
plt.legend()
plt.show()
IndexError: boolean index did not match indexed array along dimension 0; dimension is 180000 but corresponding boolean dimension is 60000
I'm trying to solve Dimensionality reduction using PCA and T-SNE. I am stuck at this step. the error is " IndexError: boolean index did not match indexed array along dimension 0; dimension is 180000 but corresponding boolean dimension is 60000" i tried looking up online for possible solutions and i found solutions where it said to lower my version of tensior flow and keras and i did it but it did'nt work. i tried to look for more possible solutions but didnt find anything relevant.I am adding my code to this Question. Can anyone guide me with this?
from keras.datasets import cifar10
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
from matplotlib import pyplot as plt
import numpy as np
%matplotlib inline
plt.rcParams['figure.figsize'] = [12, 9]
(x_train, x_test), (y_train, y_test) = cifar10.load_data()
train = np.concatenate((x_train, y_train))
test = np.concatenate((x_test, y_test))
(x_train.shape)
y_train
print(x_train.shape)
print(y_train.shape)
print(x_test.shape)
print(y_test.shape)
train=np.concatenate((x_train,y_train))
test=np.concatenate((x_test,y_test))
print(train.shape)
print(test.shape)
pca = PCA(n_components=2)
%%time
reduced = pca.fit_transform(train.reshape(-1, 32 * 32))
for i in range(10):
num = reduced[test == i]
plt.scatter(num[:, 0], num[:, 1], s=5, label=f'{i}')
plt.legend()
plt.show()
IndexError: boolean index did not match indexed array along dimension 0; dimension is 180000 but corresponding boolean dimension is 60000
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论