通过线接入线路为numpy的结构数组 [英] Access line by line to a numpy structured array

查看:112
本文介绍了通过线接入线路为numpy的结构数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过线通过迭代在它的一个字段的值,以获得一个结构化的阵列线,但即使该值迭代很好,数组的切片不会改变。这里是我的SWE:

I am trying to access to a structured array line by line by iterating on the values of one field of it but even if the value iterate well, the slice of the array doesn't change. Here is my SWE :

import numpy as np
dt=np.dtype([('name',np.unicode,80),('x',np.float),('y',np.float)])
a=np.array( [('a',0.,0.),('b',0.,0.),('c',0.,0.) ],dtype=dt)
for n in a['name']:
  print n,a['name'==n]

给我:

a (u'a', 0.0, 0.0)
b (u'a', 0.0, 0.0)
c (u'a', 0.0, 0.0)

在每次迭代中,我总是有数组的同一片......奇怪?

At each iteration, I always have the same slice of the array... strange ?

推荐答案

最后一行是不正确的。数组索引计算结果为真或假,而不是做一个名为列的查找。
试试这个:

The last line is not right. The array index evaluates to True or False rather than doing a lookup of a named column. Try this:

for n in a['name']:
    print n,a[a['name']==n]

这篇关于通过线接入线路为numpy的结构数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆