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

Function iscomplex

numpy/lib/type_check.py:210–243  ·  view source on GitHub ↗

Returns a bool array, where True if input element is complex. What is tested is whether the input has a non-zero imaginary part, not if the input type is complex. Parameters ---------- x : array_like Input array. Returns ------- out : ndarray of bools

(x)

Source from the content-addressed store, hash-verified

208
209@array_function_dispatch(_is_type_dispatcher)
210def iscomplex(x):
211 """
212 Returns a bool array, where True if input element is complex.
213
214 What is tested is whether the input has a non-zero imaginary part, not if
215 the input type is complex.
216
217 Parameters
218 ----------
219 x : array_like
220 Input array.
221
222 Returns
223 -------
224 out : ndarray of bools
225 Output array.
226
227 See Also
228 --------
229 isreal
230 iscomplexobj : Return True if x is a complex type or an array of complex
231 numbers.
232
233 Examples
234 --------
235 >>> np.iscomplex([1+1j, 1+0j, 4.5, 3, 2, 2j])
236 array([ True, False, False, False, False, True])
237
238 """
239 ax = asanyarray(x)
240 if issubclass(ax.dtype.type, _nx.complexfloating):
241 return ax.imag != 0
242 res = zeros(ax.shape, bool)
243 return res[()] # convert to scalar if needed
244
245
246@array_function_dispatch(_is_type_dispatcher)

Callers 3

__str__Method · 0.90
test_failMethod · 0.90
test_passMethod · 0.90

Calls 2

asanyarrayFunction · 0.85
zerosFunction · 0.50

Tested by 2

test_failMethod · 0.72
test_passMethod · 0.72