【问题标题】:create scatter plot for each two dimension for ndarray为ndarray的每两个维度创建散点图
【发布时间】:2020-12-08 13:48:59
【问题描述】:

我有形状为 (13, 2236, 1866) 的 ndarray。我想为每个维度与所有其他维度创建散点图,例如 dim1 +dim2、dim1 + dim3、dim1 +dim4 ...sdim2+dim3、dom2+4........ 直到我得到分散所有可能性的情节。

现在我有使用 while 循环的脚本,但 ofcurse 找不到所有匹配的可能性。 #array= ndarray

d=0
while d+1<13:
    x=array[d].reshape(-1)
    y=array[d+1].reshape(-1)    
    plt.figure(figsize=(8,6))
    plt.scatter(x, y, s=5, linewidth=0)
    plt.scatter(x, y,s=5, linewidth=0)
    plt.xlabel('B{band1}'.format(band1= str(d+1)))
    plt.ylabel('B{band2}'.format(band2 = str(d+2)))
    plt.show()
    d=d+1

在这里我得到了 B1+B2,B2+B3,B3+B4 的可能性... 我还尝试创建维度列表和使用 for 循环:

dims=np.arange(0,13)

然后“for d in dims”运行 while 循环,但这也没有提供所有可能性。

我的最终目标:为所有维度创建所有可能的散点图

【问题讨论】:

  • 你的代码中的数组是什么?
  • @JacksonPro arra 是 ndarray。我会把它添加到原帖中

标签: python numpy for-loop while-loop scatter-plot


【解决方案1】:

最后我使用了here的函数:

dims=np.arange(0,13)


def tessa(source):
        result = []
        for p1 in range(len(source)):
                for p2 in range(p1+1,len(source)):
                        result.append([source[p1],source[p2]])
        return result

pairings = tessa(dims)
print("%d pairings" % len(pairings))

        
        
for i in pairings:
    xd=i[0]
    xy=i[1]
    x=array[xd].reshape(-1)
    y=array[xy].reshape(-1)    
    plt.figure(figsize=(8,6))
    plt.scatter(x, y, s=5, linewidth=0)
    plt.scatter(x, y,s=5, linewidth=0)
    plt.xlabel('B{band1}'.format(band1= str(xd+1)))
    plt.ylabel('B{band2}'.format(band2 = str(xy+1)))
    plt.show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-19
    • 1970-01-01
    相关资源
    最近更新 更多