x******a 发帖数: 6336 | 1 Int[4]:x
Out[4]:
array([['a', '1', '0.5'],
['b', '2', '0.2'],
['c', '3', '0.1']],
dtype='|S3')
我想把第一列的dtype改成str,第二列的改成int,第三列的改成float,
现在想到的办法是存到文件里再读出来,请问有没有其他简单的办法?
多谢 | k**********g 发帖数: 989 | 2 Firstly, extract by column. The colon means to extract everything in that
dimension.
http://stackoverflow.com/questions/4455076/numpy-access-an-arra
Then, use "astype" to convert from a (column) array of strings to an array
of float
http://stackoverflow.com/questions/3877209/how-to-convert-an-ar
【在 x******a 的大作中提到】 : Int[4]:x : Out[4]: : array([['a', '1', '0.5'], : ['b', '2', '0.2'], : ['c', '3', '0.1']], : dtype='|S3') : 我想把第一列的dtype改成str,第二列的改成int,第三列的改成float, : 现在想到的办法是存到文件里再读出来,请问有没有其他简单的办法? : 多谢
| x******a 发帖数: 6336 | 3 我怎么把改过的3列放到一个ndarray里还保持dtype?thanks | k**********g 发帖数: 989 | 4
Structured arrays (a.k.a. record arrays)
http://docs.scipy.org/doc/numpy/user/basics.rec.html
【在 x******a 的大作中提到】 : 我怎么把改过的3列放到一个ndarray里还保持dtype?thanks
|
|