我们从Python开源项目中,提取了以下31个代码示例,用于说明如何使用numpy.sctypes()。
def _clip_type(self, type_group, array_max, clip_min, clip_max, inplace=False, expected_min=None, expected_max=None): if expected_min is None: expected_min = clip_min if expected_max is None: expected_max = clip_max for T in np.sctypes[type_group]: if sys.byteorder == 'little': byte_orders = ['=', '>'] else: byte_orders = ['<', '='] for byteorder in byte_orders: dtype = np.dtype(T).newbyteorder(byteorder) x = (np.random.random(1000) * array_max).astype(dtype) if inplace: x.clip(clip_min, clip_max, x) else: x = x.clip(clip_min, clip_max) byteorder = '=' if x.dtype.byteorder == '|': byteorder = '|' assert_equal(x.dtype.byteorder, byteorder) self._check_range(x, expected_min, expected_max) return x
def test_ip_types(self): unchecked_types = [str, unicode, np.void, object] x = np.random.random(1000)*100 mask = x < 40 for val in [-100, 0, 15]: for types in np.sctypes.values(): for T in types: if T not in unchecked_types: yield self.tst_basic, x.copy().astype(T), T, mask, val
def test_ip_types(self): unchecked_types = [str, unicode, np.void, object] x = np.random.random(24)*100 x.shape = 2, 3, 4 for types in np.sctypes.values(): for T in types: if T not in unchecked_types: yield self.tst_basic, x.copy().astype(T)
def test_unsigned_max(self): types = np.sctypes['uint'] for T in types: assert_equal(iinfo(T).max, T(-1))
def chooseAttr(data,class_values): # Initialising best best={ "name":"temp", "split_entropy":999999 } # DataFrame.dtype.to_dict() returns a dictionary having keys as attribute name and value as attribute type for name,dtype in data.dtypes.to_dict().iteritems(): attr={"name":name,"type":dtype} # If data_type is not number, use subEntropyChar # Keys returned by subEntropyChar ["split_entropy"] if dtype in np.sctypes["others"] : attr.update(subEntropyChar(data,class_values, name)) # If data_type is number, use subEntropyFloat # Keys returned by subEntropyFloat ["split_entropy","split_value"] else: attr.update(subEntropyFloat(data,class_values, name)) if attr["split_entropy"] < best["split_entropy"]: best = attr best["tree_entropy"] = entropy(class_values) best["gain"] = best["tree_entropy"] - best["split_entropy"] return best
def set_preference(data,class_values,preference): preference = { "name":preference, "type":data[preference].dtype, } preference["tree_entropy"] = entropy(class_values.copy()) if preference["type"] in np.sctypes["others"] : preference.update(subEntropyChar(data.copy(),class_values.copy(), preference["name"])) else: preference.update(subEntropyFloat(data.copy(),class_values.copy(),preference["name"])) preference["gain"] = preference["tree_entropy"] - preference["split_entropy"] return preference # @param # kwargs: # data : Panda DataFrame # class_label : string if metadata is not None else integer # preference : string if metadata is not None else integer ( Attribute prefered as root ) # max_height : integer > 0 # # recursion: interger used to keep track of height # @return # tree : (type dictionary) # { # "info" : @node (type : dictionary) # attribute keys:["name","type","index","gain","sub_entropy","tree_entropy","gain","height"] # optional: ["split_value"] # # @leaf # attribute keys:["class","tree_entropy","height"] # }
def test_convert_objects_complex_number(): for dtype in np.sctypes['complex']: arr = np.array(list(1j * np.arange(20, dtype=dtype)), dtype='O') assert (arr[0].dtype == np.dtype(dtype)) result = lib.maybe_convert_objects(arr) assert (issubclass(result.dtype.type, np.complexfloating))
def test_ip_types(self): unchecked_types = [bytes, unicode, np.void, object] x = np.random.random(1000)*100 mask = x < 40 for val in [-100, 0, 15]: for types in np.sctypes.values(): for T in types: if T not in unchecked_types: yield self.tst_basic, x.copy().astype(T), T, mask, val
def test_ip_types(self): unchecked_types = [bytes, unicode, np.void, object] x = np.random.random(24)*100 x.shape = 2, 3, 4 for types in np.sctypes.values(): for T in types: if T not in unchecked_types: yield self.tst_basic, x.copy().astype(T)