Compute the variance of an array of ‘Value’ objects with respect
to all the ‘Value’ objects in ‘vals’ using the standard deviations
of the values and a first order taylor approximation using the
partial derivatives.
Decorator that adds numpy functions as methods to the Value class while overloading
them with their analytical derivatives to propagate the gradient with the chain rule.
Dual number ‘Value’ definition for small autograd framework.
The dunder methods of the ‘Value’ class are overloaded to simultaneously compute
the partial derivatives with respect to the instance itself and other instances
of the value class.
This is realized by a dictionary that handles the reference tracking via the id
of the ‘Value’ instances.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
absolute – An ndarray containing the absolute value of
each element in x. For complex input, a+ib, the
absolute value is \(\sqrt{ a^2 + b^2 }\).
This is a scalar if x is a scalar.
The inverse of cos so that, if y=cos(x), then x=arccos(y).
Parameters:
x (array_like) – x-coordinate on the unit circle.
For real arguments, the domain is [-1, 1].
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
angle – The angle of the ray intersecting the unit circle at the given
x-coordinate in radians [0, pi].
This is a scalar if x is a scalar.
arccos is a multivalued function: for each x there are infinitely
many numbers z such that cos(z)=x. The convention is to return
the angle z whose real part lies in [0, pi].
For real-valued input data types, arccos always returns real output.
For each value that cannot be expressed as a real number or infinity,
it yields nan and sets the invalid floating point error flag.
For complex-valued input, arccos is a complex analytic function that
has branch cuts [-inf,-1] and [1, inf] and is continuous from
above on the former and from below on the latter.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
arccosh – Array of the same shape as x.
This is a scalar if x is a scalar.
arccosh is a multivalued function: for each x there are infinitely
many numbers z such that cosh(z) = x. The convention is to return the
z whose imaginary part lies in [-pi,pi] and the real part in
[0,inf].
For real-valued input data types, arccosh always returns real output.
For each value that cannot be expressed as a real number or infinity, it
yields nan and sets the invalid floating point error flag.
For complex-valued input, arccosh is a complex analytical function that
has a branch cut [-inf, 1] and is continuous from above on it.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
angle – The inverse sine of each element in x, in radians and in the
closed interval [-pi/2,pi/2].
This is a scalar if x is a scalar.
arcsin is a multivalued function: for each x there are infinitely
many numbers z such that \(sin(z) = x\). The convention is to
return the angle z whose real part lies in [-pi/2, pi/2].
For real-valued input data types, arcsin always returns real output.
For each value that cannot be expressed as a real number or infinity,
it yields nan and sets the invalid floating point error flag.
For complex-valued input, arcsin is a complex analytic function that
has, by convention, the branch cuts [-inf, -1] and [1, inf] and is
continuous from above on the former and from below on the latter.
The inverse sine is also known as asin or sin^{-1}.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
out – Array of the same shape as x.
This is a scalar if x is a scalar.
Return type:
ndarray or scalar
Notes
arcsinh is a multivalued function: for each x there are infinitely
many numbers z such that sinh(z) = x. The convention is to return the
z whose imaginary part lies in [-pi/2, pi/2].
For real-valued input data types, arcsinh always returns real output.
For each value that cannot be expressed as a real number or infinity, it
returns nan and sets the invalid floating point error flag.
For complex-valued input, arccos is a complex analytical function that
has branch cuts [1j, infj] and [-1j, -infj] and is continuous from
the right on the former and from the left on the latter.
The inverse hyperbolic sine is also known as asinh or sinh^-1.
The inverse of tan, so that if y=tan(x) then x=arctan(y).
Parameters:
x (array_like)
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
out – Out has the same shape as x. Its real part is in
[-pi/2,pi/2] (arctan(+/-inf) returns +/-pi/2).
This is a scalar if x is a scalar.
Return type:
ndarray or scalar
See also
arctan2
The “four quadrant” arctan of the angle formed by (x, y) and the positive x-axis.
arctan is a multi-valued function: for each x there are infinitely
many numbers z such that tan(z) = x. The convention is to return
the angle z whose real part lies in [-pi/2, pi/2].
For real-valued input data types, arctan always returns real output.
For each value that cannot be expressed as a real number or infinity,
it yields nan and sets the invalid floating point error flag.
For complex-valued input, arctan is a complex analytic function that
has [1j,infj] and [-1j,-infj] as branch cuts, and is continuous
from the left on the former and from the right on the latter.
The inverse tangent is also known as atan or tan^{-1}.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
out – Array of the same shape as x.
This is a scalar if x is a scalar.
Return type:
ndarray or scalar
See also
emath.arctanh
Notes
arctanh is a multivalued function: for each x there are infinitely
many numbers z such that tanh(z)=x. The convention is to return
the z whose imaginary part lies in [-pi/2, pi/2].
For real-valued input data types, arctanh always returns real output.
For each value that cannot be expressed as a real number or infinity,
it yields nan and sets the invalid floating point error flag.
For complex-valued input, arctanh is a complex analytical function
that has branch cuts [-1, -inf] and [1, inf] and is continuous from
above on the former and from below on the latter.
The inverse hyperbolic tangent is also known as atanh or tanh^-1.
x (array_like) – The values whose cube-roots are required.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
y – An array of the same shape as x, containing the cube
cube-root of each element in x.
If out was provided, y is a reference to it.
This is a scalar if x is a scalar.
The complex conjugate of a complex number is obtained by changing the
sign of its imaginary part.
Parameters:
x (array_like) – Input value.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
y – The complex conjugate of x, with same dtype as y.
This is a scalar if x is a scalar.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
y – The corresponding cosine values.
This is a scalar if x is a scalar.
Return type:
ndarray
Notes
If out is provided, the function writes the result into it,
and returns a reference to out. (See Examples)
References
M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions.
New York, NY: Dover, 1972.
Examples
>>> np.cos(np.array([0,np.pi/2,np.pi]))array([ 1.00000000e+00, 6.12303177e-17, -1.00000000e+00])>>>>>> # Example of providing the optional output parameter>>> out1=np.array([0],dtype='d')>>> out2=np.cos([0.1],out1)>>> out2isout1True>>>>>> # Example of ValueError due to provision of shape mis-matched `out`>>> np.cos(np.zeros((3,3)),np.zeros((2,2)))Traceback (most recent call last):
File "<stdin>", line 1, in <module>ValueError: operands could not be broadcast together with shapes (3,3) (2,2)
Equivalent to 1/2*(np.exp(x)+np.exp(-x)) and np.cos(1j*x).
Parameters:
x (array_like) – Input array.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
out – Output array of same shape as x.
This is a scalar if x is a scalar.
Return type:
ndarray or scalar
Examples
>>> np.cosh(0)1.0
The hyperbolic cosine describes the shape of a hanging cable:
Calculate the exponential of all elements in the input array.
Parameters:
x (array_like) – Input values.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
out – Output array, element-wise exponential of x.
This is a scalar if x is a scalar.
The irrational number e is also known as Euler’s number. It is
approximately 2.718281, and is the base of the natural logarithm,
ln (this means that, if \(x = \ln y = \log_e y\),
then \(e^x = y\). For real input, exp(x) is always positive.
For complex arguments, x=a+ib, we can write
\(e^x = e^a e^{ib}\). The first term, \(e^a\), is already
known (it is the real argument, described above). The second term,
\(e^{ib}\), is \(\cos b + i \sin b\), a function with
magnitude 1 and a periodic phase.
References
Examples
Plot the magnitude and phase of exp(x) in the complex plane:
>>> importmatplotlib.pyplotasplt
>>> x=np.linspace(-2*np.pi,2*np.pi,100)>>> xx=x+1j*x[:,np.newaxis]# a + ib over complex plane>>> out=np.exp(xx)
>>> plt.subplot(121)>>> plt.imshow(np.abs(out),... extent=[-2*np.pi,2*np.pi,-2*np.pi,2*np.pi],cmap='gray')>>> plt.title('Magnitude of exp(x)')
>>> plt.subplot(122)>>> plt.imshow(np.angle(out),... extent=[-2*np.pi,2*np.pi,-2*np.pi,2*np.pi],cmap='hsv')>>> plt.title('Phase (angle) of exp(x)')>>> plt.show()
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
out – Element-wise 2 to the power x.
This is a scalar if x is a scalar.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
out – Element-wise exponential minus one: out=exp(x)-1.
This is a scalar if x is a scalar.
The natural logarithm log is the inverse of the exponential function,
so that log(exp(x)) = x. The natural logarithm is logarithm in base
e.
Parameters:
x (array_like) – Input value.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
y – The natural logarithm of x, element-wise.
This is a scalar if x is a scalar.
Logarithm is a multivalued function: for each x there is an infinite
number of z such that exp(z) = x. The convention is to return the
z whose imaginary part lies in (-pi, pi].
For real-valued input data types, log always returns real output. For
each value that cannot be expressed as a real number or infinity, it
yields nan and sets the invalid floating point error flag.
For complex-valued input, log is a complex analytical function that
has a branch cut [-inf, 0] and is continuous from above on it. log
handles the floating-point negative zero as an infinitesimal negative
number, conforming to the C99 standard.
In the cases where the input has a negative real part and a very small
negative complex part (approaching 0), the result is so close to -pi
that it evaluates to exactly -pi.
Return the base 10 logarithm of the input array, element-wise.
Parameters:
x (array_like) – Input values.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
y – The logarithm to the base 10 of x, element-wise. NaNs are
returned where x is negative.
This is a scalar if x is a scalar.
Return type:
ndarray
See also
emath.log10
Notes
Logarithm is a multivalued function: for each x there is an infinite
number of z such that 10**z = x. The convention is to return the
z whose imaginary part lies in (-pi, pi].
For real-valued input data types, log10 always returns real output.
For each value that cannot be expressed as a real number or infinity,
it yields nan and sets the invalid floating point error flag.
For complex-valued input, log10 is a complex analytical function that
has a branch cut [-inf, 0] and is continuous from above on it.
log10 handles the floating-point negative zero as an infinitesimal
negative number, conforming to the C99 standard.
In the cases where the input has a negative real part and a very small
negative complex part (approaching 0), the result is so close to -pi
that it evaluates to exactly -pi.
Return the natural logarithm of one plus the input array, element-wise.
Calculates log(1+x).
Parameters:
x (array_like) – Input values.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
y – Natural logarithm of 1 + x, element-wise.
This is a scalar if x is a scalar.
For real-valued input, log1p is accurate also for x so small
that 1 + x == 1 in floating-point accuracy.
Logarithm is a multivalued function: for each x there is an infinite
number of z such that exp(z) = 1 + x. The convention is to return
the z whose imaginary part lies in [-pi, pi].
For real-valued input data types, log1p always returns real output.
For each value that cannot be expressed as a real number or infinity,
it yields nan and sets the invalid floating point error flag.
For complex-valued input, log1p is a complex analytical function that
has a branch cut [-inf, -1] and is continuous from above on it.
log1p handles the floating-point negative zero as an infinitesimal
negative number, conforming to the C99 standard.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
y – Base-2 logarithm of x.
This is a scalar if x is a scalar.
Logarithm is a multivalued function: for each x there is an infinite
number of z such that 2**z = x. The convention is to return the z
whose imaginary part lies in (-pi, pi].
For real-valued input data types, log2 always returns real output.
For each value that cannot be expressed as a real number or infinity,
it yields nan and sets the invalid floating point error flag.
For complex-valued input, log2 is a complex analytical function that
has a branch cut [-inf, 0] and is continuous from above on it. log2
handles the floating-point negative zero as an infinitesimal negative
number, conforming to the C99 standard.
In the cases where the input has a negative real part and a very small
negative complex part (approaching 0), the result is so close to -pi
that it evaluates to exactly -pi.
First array elements raised to powers from second array, element-wise.
Raise each base in x1 to the positionally-corresponding power in
x2. x1 and x2 must be broadcastable to the same shape.
An integer type raised to a negative integer power will raise a
ValueError.
Negative values raised to a non-integral value will return nan.
To get complex results, cast the input to complex, or specify the
dtype to be complex (see the example below).
Parameters:
x1 (array_like) – The bases.
x2 (array_like) – The exponents.
If x1.shape!=x2.shape, they must be broadcastable to a common
shape (which becomes the shape of the output).
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
y – The bases in x1 raised to the exponents in x2.
This is a scalar if both x1 and x2 are scalars.
Returns an element-wise indication of the sign of a number.
The sign function returns -1ifx<0,0ifx==0,1ifx>0. nan
is returned for nan inputs.
For complex inputs, the sign function returns
sign(x.real)+0jifx.real!=0elsesign(x.imag)+0j.
complex(nan, 0) is returned for complex nan inputs.
Parameters:
x (array_like) – Input values.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
y – The sign of x.
This is a scalar if x is a scalar.
Return type:
ndarray
Notes
There is more than one definition of sign in common use for complex
numbers. The definition used here is equivalent to \(x/\sqrt{x*x}\)
which is different from a common alternative, \(x/|x|\).
x (array_like) – Angle, in radians (\(2 \pi\) rad equals 360 degrees).
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
y – The sine of each element of x.
This is a scalar if x is a scalar.
The sine is one of the fundamental functions of trigonometry (the
mathematical study of triangles). Consider a circle of radius 1
centered on the origin. A ray comes in from the \(+x\) axis, makes
an angle at the origin (measured counter-clockwise from that axis), and
departs from the origin. The \(y\) coordinate of the outgoing
ray’s intersection with the unit circle is the sine of that angle. It
ranges from -1 for \(x=3\pi / 2\) to +1 for \(\pi / 2.\) The
function has zeroes where the angle is a multiple of \(\pi\).
Sines of angles between \(\pi\) and \(2\pi\) are negative.
The numerous properties of the sine and related functions are included
in any standard trigonometry text.
Examples
Print sine of one angle:
>>> np.sin(np.pi/2.)1.0
Print sines of an array of angles given in degrees:
Equivalent to 1/2*(np.exp(x)-np.exp(-x)) or
-1j*np.sin(1j*x).
Parameters:
x (array_like) – Input array.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
y – The corresponding hyperbolic sine values.
This is a scalar if x is a scalar.
Return type:
ndarray
Notes
If out is provided, the function writes the result into it,
and returns a reference to out. (See Examples)
References
M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions.
New York, NY: Dover, 1972, pg. 83.
Examples
>>> np.sinh(0)0.0>>> np.sinh(np.pi*1j/2)1j>>> np.sinh(np.pi*1j)# (exact value is 0)1.2246063538223773e-016j>>> # Discrepancy due to vagaries of floating point arithmetic.
>>> # Example of providing the optional output parameter>>> out1=np.array([0],dtype='d')>>> out2=np.sinh([0.1],out1)>>> out2isout1True
>>> # Example of ValueError due to provision of shape mis-matched `out`>>> np.sinh(np.zeros((3,3)),np.zeros((2,2)))Traceback (most recent call last):
File "<stdin>", line 1, in <module>ValueError: operands could not be broadcast together with shapes (3,3) (2,2)
Return the non-negative square-root of an array, element-wise.
Parameters:
x (array_like) – The values whose square-roots are required.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
y – An array of the same shape as x, containing the positive
square-root of each element in x. If any element in x is
complex, a complex array is returned (and the square-roots of
negative reals are calculated). If all of the elements in x
are real, so is y, with negative elements returning nan.
If out was provided, y is a reference to it.
This is a scalar if x is a scalar.
Return type:
ndarray
See also
emath.sqrt
A version which returns complex numbers when given negative reals. Note that 0.0 and -0.0 are handled differently for complex inputs.
Notes
sqrt has–consistent with common convention–as its branch cut the
real “interval” [-inf, 0), and is continuous from above on it.
A branch cut is a curve in the complex plane across which a given
complex function fails to be continuous.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
out – Element-wise x*x, of the same shape and dtype as x.
This is a scalar if x is a scalar.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
y – The corresponding tangent values.
This is a scalar if x is a scalar.
Return type:
ndarray
Notes
If out is provided, the function writes the result into it,
and returns a reference to out. (See Examples)
References
M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions.
New York, NY: Dover, 1972.
Examples
>>> frommathimportpi>>> np.tan(np.array([-pi,pi/2,pi]))array([ 1.22460635e-16, 1.63317787e+16, -1.22460635e-16])>>>>>> # Example of providing the optional output parameter illustrating>>> # that what is returned is a reference to said parameter>>> out1=np.array([0],dtype='d')>>> out2=np.cos([0.1],out1)>>> out2isout1True>>>>>> # Example of ValueError due to provision of shape mis-matched `out`>>> np.cos(np.zeros((3,3)),np.zeros((2,2)))Traceback (most recent call last):
File "<stdin>", line 1, in <module>ValueError: operands could not be broadcast together with shapes (3,3) (2,2)
Equivalent to np.sinh(x)/np.cosh(x) or -1j*np.tan(1j*x).
Parameters:
x (array_like) – Input array.
out (ndarray, None, or tuple of ndarray and None, optional) – A location into which the result is stored. If provided, it must have
a shape that the inputs broadcast to. If not provided or None,
a freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where (array_like, optional) – This condition is broadcast over the input. At locations where the
condition is True, the out array will be set to the ufunc result.
Elsewhere, the out array will retain its original value.
Note that if an uninitialized out array is created via the default
out=None, locations within it where the condition is False will
remain uninitialized.
**kwargs – For other keyword-only arguments, see the
ufunc docs.
Returns:
y – The corresponding hyperbolic tangent values.
This is a scalar if x is a scalar.
Return type:
ndarray
Notes
If out is provided, the function writes the result into it,
and returns a reference to out. (See Examples)
>>> # Example of providing the optional output parameter illustrating>>> # that what is returned is a reference to said parameter>>> out1=np.array([0],dtype='d')>>> out2=np.tanh([0.1],out1)>>> out2isout1True
>>> # Example of ValueError due to provision of shape mis-matched `out`>>> np.tanh(np.zeros((3,3)),np.zeros((2,2)))Traceback (most recent call last):
File "<stdin>", line 1, in <module>ValueError: operands could not be broadcast together with shapes (3,3) (2,2)