简体   繁体   English

将3d矩阵转换为特征向量

[英]converting a 3d matrix into feature vectors

So I have data in shape (100,100,5000). 所以我的数据形状为(100,100,5000)。

Basically, it is a 100 by 100 pixel image which each (x,y) pixel having some spectrum vector.. So, the data is format 基本上,它是一个100 x 100像素的图像,每个(x,y)像素都具有一些光谱矢量。因此,数据为格式

     [ [ [ 0, 0.2.....],[0.1,0.3.....].. and so on]]

When we do d[0][0][0] corresponds to (0,0) pixel in image and the spectrum value is 0 当我们做d [0] [0] [0]对应于图像中的(0,0)像素,光谱值为0

Now, i want to run kmeans algorithm in it.. Thats the background. 现在,我想在其中运行kmeans算法。

To run kmeans, I want to convert it into feature vector.. as 要运行kmeans,我想将其转换为特征向量。

[0,0,0]
[0,0,0.2]
and so on..

Is there a "python" way to do this conversion. 有没有一种“ Python”的方式来进行这种转换。 I am guessing there should be some numpy reshape method which can easily achieve this, rather than writing the three for loops which I am trying to avoid. 我猜应该有一些可以轻松实现此目的的numpy重塑方法,而不是编写我试图避免的三个for循环。

Use numpy reshape http://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html eg 使用numpy重塑http://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html例如

a.reshape((m,n))

where m and n are the desired coordinates of your array a 其中mn是数组a的所需坐标

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

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