ls_ord_symbols = np.zeros((len(na_csv_orders), 1), dtype='S5')
>>> print ls_ord_symbols
[['AAPL']
['IBM']
['GOOG']]
>>> print type(ls_ord_symbols)
<type 'numpy.ndarray'>
>>> print type(ls_ord_symbols[0])
<type 'numpy.ndarray'>
>>> print ls_ord_symbols[0][0]
AAPL
>>> print type(ls_ord_symbols[0][0])
<type 'numpy.string_'>
>>> print str(ls_ord_symbols[0][0])
AAPL
>>> print type(str(ls_ord_symbols[0][0]))
<type 'str'>
问题&GT;我需要使用原始类型提取存储在numpy.array中的每个元素。这里,ls_ord_symbols
将字符串存储在numpy.array中。
我必须使用以下方法来提取原始元素:
str(ls_ord_symbols[i][0])
在索引i
的情况下,有更好的方法吗?基本上,我希望简单地将['AAPL','IBM','GOOG']或'AAPL','IBM','GOOG'列表作为每个单独的字符串,同时使用索引{{迭代通过此numpy.array 1}}
答案 0 :(得分:0)
#!/usr/bin/env python
import numpy as np
ls_ord_symbols = np.zeros((3, 1), dtype='S5')
ls_ord_symbols[0,0] = 'AAPL'
ls_ord_symbols[1,0] = 'IBM'
ls_ord_symbols[2,0] = 'GOOG'
mylist = [ls_ord_symbols[i,0]
for i in xrange(ls_ord_symbols.shape[0])]
print repr(mylist)