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_)
| 82 | |
| 83 | @array_function_dispatch(_asfarray_dispatcher) |
| 84 | def 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 | |
| 116 | def _real_dispatcher(val): |