MCPcopy Index your code
hub / github.com/numpy/numpy / sqrt

Function sqrt

numpy/lib/_scimath_impl.py:187–238  ·  view source on GitHub ↗

Compute the square root of x. For negative input elements, a complex value is returned (unlike `numpy.sqrt` which returns NaN). Parameters ---------- x : array_like The input value(s). Returns ------- out : ndarray or scalar The square root of `x

(x)

Source from the content-addressed store, hash-verified

185@set_module('numpy.lib.scimath')
186@array_function_dispatch(_unary_dispatcher)
187def sqrt(x):
188 """
189 Compute the square root of x.
190
191 For negative input elements, a complex value is returned
192 (unlike `numpy.sqrt` which returns NaN).
193
194 Parameters
195 ----------
196 x : array_like
197 The input value(s).
198
199 Returns
200 -------
201 out : ndarray or scalar
202 The square root of `x`. If `x` was a scalar, so is `out`,
203 otherwise an array is returned.
204
205 See Also
206 --------
207 numpy.sqrt
208
209 Examples
210 --------
211 For real, non-negative inputs this works just like `numpy.sqrt`:
212
213 >>> import numpy as np
214
215 >>> np.emath.sqrt(1)
216 1.0
217 >>> np.emath.sqrt([1, 4])
218 array([1., 2.])
219
220 But it automatically handles negative inputs:
221
222 >>> np.emath.sqrt(-1)
223 1j
224 >>> np.emath.sqrt([-1,4])
225 array([0.+1.j, 2.+0.j])
226
227 Different results are expected because:
228 floating point 0.0 and -0.0 are distinct.
229
230 For more control, explicitly use complex() as follows:
231
232 >>> np.emath.sqrt(complex(-4.0, 0.0))
233 2j
234 >>> np.emath.sqrt(complex(-4.0, -0.0))
235 -2j
236 """
237 x = _fix_real_lt_zero(x)
238 return nx.sqrt(x)
239
240
241@set_module('numpy.lib.scimath')

Callers 12

__init__Method · 0.90
test_complexMethod · 0.90
test_testUfuncs1Method · 0.90
corrcoefFunction · 0.85
_i0_2Function · 0.85
kaiserFunction · 0.85
normFunction · 0.85
stdMethod · 0.85
test_basic_ufuncsMethod · 0.85
_raw_fftFunction · 0.85

Calls 1

_fix_real_lt_zeroFunction · 0.85

Tested by 5

__init__Method · 0.72
test_complexMethod · 0.72
test_testUfuncs1Method · 0.72
test_basic_ufuncsMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…