访问元素在Python阵列的列表 [英] Accessing elements in a list of arrays in python
本文介绍了访问元素在Python阵列的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
c = []
Indices = []
list_ = iter([0.10,0.16,0.25,0.50,0.75,0.90])
for i in list_:
b = around((total_*i), decimals = 2)
t = where(fcol == find_nearest(fcol,b))
c.append(b)
indices.append(t)
print t #gives:
(array([485]),)
(array([523]),)
(array([576]),)
(array([733]),)
(array([963]),)
(array([1254]),)
在我外面打印索引列表循环,它看起来像:
when I print the indices list outside for loop it looks like:
print indices #gives:
[(array([485]),), (array([523]),), (array([576]),), (array([733]),), (array([963]),), (array([1254]),)]
虽然所需的输出就像是一个列表:
While desired output is a list like:
[485, 523, 576, 733, 963, 1254]
问:
这是方法我用写一个好办法?阵列的名单(好,我觉得有可能是更有效的办法),如果是,我怎么能在列表访问数(数组的元素)?
Question: Is this method I used to write a 'list of arrays' a good approach?(well I think there may be more efficient ways) If it is, how can I access the numbers (elements of arrays) in the list?
推荐答案
这解决了我的问题:
indices.append(list(t[0]))
#which gives:
[[485], [523], [576], [733], [963], [1254]]
和则:
for x in indices:
print (x[0])
这篇关于访问元素在Python阵列的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文