简体   繁体   English

如何将 PCA 降维应用于 3D 矩阵?

[英]How can I apply PCA dimensionality reduction to a 3D matrix?

I want to apply PCA dimensionality reduction on a 3D matrix (69,2640,7680).我想在 3D 矩阵(69,2640,7680)上应用 PCA 降维。 I have 69 2D matrices each of them has a size (2640,7680).我有 69 个二维矩阵,每个矩阵都有一个大小(2640,7680)。 I want to apply PCA on those matrices as a 3D matrix (69,2640,7680).我想在这些矩阵上应用 PCA 作为 3D 矩阵(69,2640,7680)。 I don't how to do this.我不知道如何做到这一点。

Any help would be appreciated.任何帮助,将不胜感激。

code :代码

    data=np.load('Normal_windows.npy')
    pca = PCA(n_components=1000)
    pca.fit(data)
    data_pca = pca.transform(data)
    print("original shape:   ", data.shape) ##(69,2640,7680)
    print("transformed shape:", data_pca.shape) 
 

PCA works on features if I understand correctly you have 69 items with (2640,7680) features right?如果我理解正确,您有 69 个具有 (2640,7680) 功能的项目,PCA 可以处理功能,对吗?

If that is the case then you can just flatten the last two dimensions (something like:如果是这种情况,那么您可以展平最后两个维度(例如:

data_2d = np.array([features_2d.flatten() for features_2d in data])
pca = PCA(n_components=1000)
pca.fit(data_2d)
data_pca = pca.transform(data_2d)
print("original shape:   ", data_2d.shape) ##(69,2640*7680)
print("transformed shape:", data_pca.shape)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM