布尔索引与维度 1 上的索引数组不匹配;维度为 2 但对应的布尔维度为 1

发布于 2025-01-12 17:16:13 字数 1194 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文