0

我有一个二维数组,其中子列表的索引是 y 坐标,子列表中的元素是 x 坐标。

nested_lst = [ [32.6, 45.1, 22.1, ..., 36.8], [41.5, 33.2, ...], [12.8, 37.8, ...], ... , [34.4, 35.1, ...] ]

这是一个大数组 - (2048, 2098) - 浮点数。我想绘制一个散点图,其中的点是满足条件的元素,if item > 45例如。

到目前为止,我有这个:

xcoord = []
ycoord = []

for sublist in nested_lst:
    for (index, item) in enumerate(sublist):
        if item > (45):
            xcord.append(index)
            ycord.append(nested_lst.index(sublist))

我运行它,但它给了我这个错误消息:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

不确定我是否应该提到嵌套列表是 FITS 文件中 CCD 图像的数据数组,我已将其放大到中心以聚焦于对象。我制作这个散点图的目的是为了测量图像的某些特征,所以我想首先绘制特征边界的图,因为我可以通过它们的亮度来区分它们,即子列表的值,然后找到上的点对应于其轴的椭圆特征,然后从特征的一端到另一端绘制一条线并找到它的距离。由于值错误,我一直坚持将嵌套列表分成坐标。我真的很感激一个新的视角!

4

3 回答 3

0

如果值,你在 y 轴上想要什么,那么这将起作用

  xcord = []
  ycord = []
    
  for sublist in nested_lst:
  for (index, item) in enumerate(sublist):
      if item > (45):
          xcord.append(index)
          ycord.append(item)
于 2021-01-16T19:16:31.657 回答
0

我认为您的错误是由于其中一个items 不是浮点数,但鉴于您的nested_lst 的结构,我不明白为什么会这样。您需要提供完整的 nested_lst 数组让我告诉您。

其次,你有一个小错字;您正在尝试附加到 xcord 和 ycord,这应该是 xcoord 和 ycoord。

于 2021-02-19T18:55:09.853 回答
0
xcoord = []
ycoord = []

for (ycord,sublist) in enumerate(nested_lst):
    for (xcord, item) in enumerate(sublist):
        if item > 45:
            xcord.append(xcord)
            ycord.append(ycord)
于 2021-01-16T19:07:35.823 回答