Returns the real component of a complex number for each element x_i of the input array x. Parameters ---------- x : NamedArray Input array. Should have a complex floating-point data type. Returns ------- out : NamedArray An array containing the elem
(
x: NamedArray[_ShapeType, np.dtype[_SupportsReal[_ScalarType]]], # type: ignore[type-var]
/,
)
| 112 | |
| 113 | |
| 114 | def real( |
| 115 | x: NamedArray[_ShapeType, np.dtype[_SupportsReal[_ScalarType]]], # type: ignore[type-var] |
| 116 | /, |
| 117 | ) -> NamedArray[_ShapeType, np.dtype[_ScalarType]]: |
| 118 | """ |
| 119 | Returns the real component of a complex number for each element x_i of the |
| 120 | input array x. |
| 121 | |
| 122 | Parameters |
| 123 | ---------- |
| 124 | x : NamedArray |
| 125 | Input array. Should have a complex floating-point data type. |
| 126 | |
| 127 | Returns |
| 128 | ------- |
| 129 | out : NamedArray |
| 130 | An array containing the element-wise results. The returned array must have a |
| 131 | floating-point data type with the same floating-point precision as x |
| 132 | (e.g., if x is complex64, the returned array must have the floating-point |
| 133 | data type float32). |
| 134 | |
| 135 | Examples |
| 136 | -------- |
| 137 | >>> narr = NamedArray(("x",), np.asarray([1.0 + 2j, 2 + 4j])) |
| 138 | >>> real(narr) |
| 139 | <xarray.NamedArray (x: 2)> Size: 16B |
| 140 | array([1., 2.]) |
| 141 | """ |
| 142 | xp = _get_data_namespace(x) |
| 143 | out = x._new(data=xp.real(x._data)) |
| 144 | return out |
| 145 | |
| 146 | |
| 147 | # %% Manipulation functions |
no test coverage detected
searching dependent graphs…