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

Function angle

numpy/lib/function_base.py:1607–1656  ·  view source on GitHub ↗

Return the angle of the complex argument. Parameters ---------- z : array_like A complex number or sequence of complex numbers. deg : bool, optional Return angle in degrees if True, radians if False (default). Returns ------- angle : ndarray or scal

(z, deg=False)

Source from the content-addressed store, hash-verified

1605
1606@array_function_dispatch(_angle_dispatcher)
1607def angle(z, deg=False):
1608 """
1609 Return the angle of the complex argument.
1610
1611 Parameters
1612 ----------
1613 z : array_like
1614 A complex number or sequence of complex numbers.
1615 deg : bool, optional
1616 Return angle in degrees if True, radians if False (default).
1617
1618 Returns
1619 -------
1620 angle : ndarray or scalar
1621 The counterclockwise angle from the positive real axis on the complex
1622 plane in the range ``(-pi, pi]``, with dtype as numpy.float64.
1623
1624 .. versionchanged:: 1.16.0
1625 This function works on subclasses of ndarray like `ma.array`.
1626
1627 See Also
1628 --------
1629 arctan2
1630 absolute
1631
1632 Notes
1633 -----
1634 Although the angle of the complex number 0 is undefined, ``numpy.angle(0)``
1635 returns the value 0.
1636
1637 Examples
1638 --------
1639 >>> np.angle([1.0, 1.0j, 1+1j]) # in radians
1640 array([ 0. , 1.57079633, 0.78539816]) # may vary
1641 >>> np.angle(1+1j, deg=True) # in degrees
1642 45.0
1643
1644 """
1645 z = asanyarray(z)
1646 if issubclass(z.dtype.type, _nx.complexfloating):
1647 zimag = z.imag
1648 zreal = z.real
1649 else:
1650 zimag = 0
1651 zreal = z
1652
1653 a = arctan2(zimag, zreal)
1654 if deg:
1655 a *= 180/pi
1656 return a
1657
1658
1659def _unwrap_dispatcher(p, discont=None, axis=None, *, period=None):

Callers 3

test_basicMethod · 0.90
test_subclassMethod · 0.90
test_basic_ufuncsMethod · 0.85

Calls 1

asanyarrayFunction · 0.85

Tested by 3

test_basicMethod · 0.72
test_subclassMethod · 0.72
test_basic_ufuncsMethod · 0.68