MCPcopy Create free account
hub / github.com/numpy/numpy / asfarray

Function asfarray

numpy/lib/type_check.py:84–113  ·  view source on GitHub ↗

Return an array converted to a float type. Parameters ---------- a : array_like The input array. dtype : str or dtype object, optional Float type code to coerce input array `a`. If `dtype` is one of the 'int' dtypes, it is replaced with float64. Re

(a, dtype=_nx.float_)

Source from the content-addressed store, hash-verified

82
83@array_function_dispatch(_asfarray_dispatcher)
84def asfarray(a, dtype=_nx.float_):
85 """
86 Return an array converted to a float type.
87
88 Parameters
89 ----------
90 a : array_like
91 The input array.
92 dtype : str or dtype object, optional
93 Float type code to coerce input array `a`. If `dtype` is one of the
94 'int' dtypes, it is replaced with float64.
95
96 Returns
97 -------
98 out : ndarray
99 The input `a` as a float ndarray.
100
101 Examples
102 --------
103 >>> np.asfarray([2, 3])
104 array([2., 3.])
105 >>> np.asfarray([2, 3], dtype='float')
106 array([2., 3.])
107 >>> np.asfarray([2, 3], dtype='int8')
108 array([2., 3.])
109
110 """
111 if not _nx.issubdtype(dtype, _nx.inexact):
112 dtype = _nx.float_
113 return asarray(a, dtype=dtype)
114
115
116def _real_dispatcher(val):

Callers 1

test_asfarrayMethod · 0.90

Calls 1

asarrayFunction · 0.50

Tested by 1

test_asfarrayMethod · 0.72