Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从数组中选择某些值_Python_Arrays_Numpy - Fatal编程技术网

Python 从数组中选择某些值

Python 从数组中选择某些值,python,arrays,numpy,Python,Arrays,Numpy,所以我用 numpy.genfromtxt('...', dtype=None, usecols= (0,6,7,8,9,19,24,29,31,33,34,37,39,40,41,42,43,44), names= ['sn','off1','dir1','off2','dir2','type','gal','dist','htype','d1','d2','pa','ai','b','berr ','b0','k','kerr'])) 读取一些数据 数组type包含一组不同的字符串,如Ia

所以我用

numpy.genfromtxt('...', dtype=None, usecols=
(0,6,7,8,9,19,24,29,31,33,34,37,39,40,41,42,43,44), names=
['sn','off1','dir1','off2','dir2','type','gal','dist','htype','d1','d2','pa','ai','b','berr
','b0','k','kerr']))
读取一些数据

数组
type
包含一组不同的字符串,如Ia、II等

如何创建仅使用
类型的特定字符串的变量

一、 例如,要将
TypeIa=
设置为数组
type
中的所有字符串,即“Ia”、“Iabg”和“Iat”。

您可以使用内置函数。另外,为了简单起见,我在下面的示例中使用了。你可能也会发现它很方便

首先,我准备了一些测试数据,为了简单起见,这里不公开代码

>>> type(data)
<type 'numpy.ndarray'>
>>> data['type']
['0-19' '1-19' '2-19' '3-19' '4-19' '5-19' '6-19' '7-19' '8-19' '9-19']
最后,我们准备应用out过滤功能:

>>> filter(startswith8, data['type'])
['8-19']

你到底想要什么?什么是
type
la
lat
,这些代币在你的代码摘录中没有提到我编辑了我的帖子。希望这能让事情变得更清楚一点<代码>类型只是我的数据文件中的一列
Ia
Iat
类型
数组中的字符串。
type
数组包含不同的字符串,但我只想使用
Ia
Iabg
Iat
字符串。
>>> filter(startswith8, data['type'])
['8-19']