Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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
Arrays 如何使用Python 2.7在条件IF语句中检查和使用numpy数组的数据类型_Arrays_Python 2.7_Numpy_Dtype - Fatal编程技术网

Arrays 如何使用Python 2.7在条件IF语句中检查和使用numpy数组的数据类型

Arrays 如何使用Python 2.7在条件IF语句中检查和使用numpy数组的数据类型,arrays,python-2.7,numpy,dtype,Arrays,Python 2.7,Numpy,Dtype,我在ArcGIS中有一个数据表,其中我将某些属性字段转换为numpy数组。由于数组的数据类型可以是f8(float64)或i4(int32),我想使用if语句检查数据类型,然后执行一些操作 import arcpy import numpy as np sorted_data = arcpy.da.FeatureClassToNumPyArray(feature_class, (volume_field)) sorted_data.dtype 这使得: dtype(['OIL_RECOVERA

我在ArcGIS中有一个数据表,其中我将某些属性字段转换为numpy数组。由于数组的数据类型可以是f8(float64)或i4(int32),我想使用if语句检查数据类型,然后执行一些操作

import arcpy
import numpy as np
sorted_data = arcpy.da.FeatureClassToNumPyArray(feature_class, (volume_field))
sorted_data.dtype
这使得:

dtype(['OIL_RECOVERABLE_VOL', '<i4)])

dtype(['OIL\u RECOVERABLE\u VOL',”您可以将复合数据类型拉开:

In [299]: dt=np.dtype([('OIL_RECOVERABLE_VOL', '<i4')])                                                      
In [300]: dt.descr                                                                                           
Out[300]: [('OIL_RECOVERABLE_VOL', '<i4')]
In [301]: dt.descr[0]                                                                                        
Out[301]: ('OIL_RECOVERABLE_VOL', '<i4')
In [302]: dt.descr[0][1]                                                                                     
Out[302]: '<i4'
In [299]: dt=np.dtype([('OIL_RECOVERABLE_VOL', '<i4')])                                                      
In [300]: dt.descr                                                                                           
Out[300]: [('OIL_RECOVERABLE_VOL', '<i4')]
In [301]: dt.descr[0]                                                                                        
Out[301]: ('OIL_RECOVERABLE_VOL', '<i4')
In [302]: dt.descr[0][1]                                                                                     
Out[302]: '<i4'
In [304]: dt['OIL_RECOVERABLE_VOL']                                                                          
Out[304]: dtype('int32')