Replace NaN with zero and infinity with large finite numbers (default behaviour) or with the numbers defined by the user using the nan, posinf and/or neginf keywords.
Test whether all array elements along a given axis evaluate to True.
Parameters:
a (_Symbol) – Input array or object that can be converted to an array.
axis (None or int or tuple of ints, optional) – Axis or axes along which a logical AND reduction is performed.
The default (axis = None) is to perform a logical AND over
all the dimensions of the input array.
keepdims (bool, optional) – If this is set to True, the axes which are reduced are left in
the result as dimensions with size one. With this option,
the result will broadcast correctly against the input array.
out (ndarray, optional) – Alternate output array in which to place the result. It must have
the same shape as the expected output and its type is preserved
Returns:
all – A new boolean or array is returned unless out is specified,
in which case a reference to out is returned.
axis (int, optional) – Axis along which to operate. By default, flattened input is used.
out (ndarray, optional) – Alternative output array in which to place the result. Must
be of the same shape and buffer length as the expected output.
See doc.ufuncs (Section “Output arguments”) for more details.
keepdims (bool, optional) – If this is set to True, the axes which are reduced are left
in the result as dimensions with size one. With this option,
the result will broadcast correctly against the original arr.
Returns:
max – Maximum of a. If axis is None, the result is an array of dimension 1.
If axis is given, the result is an array of dimension
a.ndim-1.
axis (int, optional) – Axis along which to operate. By default, flattened input is used.
out (ndarray, optional) – Alternative output array in which to place the result. Must
be of the same shape and buffer length as the expected output.
See doc.ufuncs (Section “Output arguments”) for more details.
keepdims (bool, optional) – If this is set to True, the axes which are reduced are left
in the result as dimensions with size one. With this option,
the result will broadcast correctly against the original arr.
Returns:
min – Minimum of a. If axis is None, the result is an array of dimension 1.
If axis is given, the result is an array of dimension
a.ndim-1.
Test whether any array element along a given axis evaluates to True.
Returns single boolean unless axis is not None
Parameters:
a (_Symbol) – Input array or object that can be converted to an array.
axis (None or int or tuple of ints, optional) – Axis or axes along which a logical AND reduction is performed.
The default (axis = None) is to perform a logical AND over
all the dimensions of the input array.
keepdims (bool, optional) – If this is set to True, the axes which are reduced are left in
the result as dimensions with size one. With this option,
the result will broadcast correctly against the input array.
out (ndarray, optional) – Alternate output array in which to place the result. It must have
the same shape as the expected output and its type is preserved
Returns:
any – A new boolean or ndarray is returned unless out is specified,
in which case a reference to out is returned.
arr (_Symbol) – Values are appended to a copy of this array.
values (_Symbol) – These values are appended to a copy of arr. It must be of the
correct shape (the same shape as arr, excluding axis). If
axis is not specified, values can be any shape and will be
flattened before use.
axis (int, optional) – The axis along which values are appended. If axis is not
given, both arr and values are flattened before use.
Returns:
append – A copy of arr with values appended to axis. Note that
append does not occur in-place: a new array is allocated and
filled. If axis is None, out is a flattened array.
Return evenly spaced values within a given interval.
Values are generated within the half-open interval [start,stop)
(in other words, the interval including start but excluding stop).
For integer arguments the function is equivalent to the Python built-in
range function, but returns an ndarray rather than a list.
Parameters:
start (number, optional) – Start of interval. The interval includes this value. The default
start value is 0.
stop (number) – End of interval. The interval does not include this value, except
in some cases where step is not an integer and floating point
round-off affects the length of out.
step (number, optional) – Spacing between values. For any output out, this is the distance
between two adjacent values, out[i+1]-out[i]. The default
step size is 1. If step is specified as a position argument,
start must also be given.
dtype (dtype) – The type of the output array.
When npx.is_np_default_dtype() returns False, default dtype is float32;
When npx.is_np_default_dtype() returns True, default dtype is float64.
Returns:
arange – Array of evenly spaced values.
For floating point arguments, the length of the result is
ceil((stop-start)/step). Because of floating point overflow,
this rule may result in the last element of out being greater
than stop.
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.
The inverse cos is also known as acos or cos^-1.
out (_Symbol or None, optional) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
arccosh – Array of the same shape as x.
This is a scalar if x is a scalar.
Return type:
_Symbol
Notes
arccosh is a multivalued function: for each x there are infinitely
many numbers z such that cosh(z) = x.
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.
This function differs from the original numpy.arccosh in the following aspects:
Do not support where, a parameter in numpy which indicates where to calculate.
Do not support complex-valued input.
Cannot cast type automatically. Dtype of out must be same as the expected one.
Cannot broadcast automatically. Shape of out must be same as the expected one.
If x is plain python numeric, the result won’t be stored in out.
x (_Symbol or scalar) – The values whose reciprocals are required.
out (_Symbol, or None, optional) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
angle – Output array is same shape and type as x. This is a scalar if x is a scalar.
Return type:
_Symbol or scalar
Notes
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.
The inverse sine is also known as asin or sin^{-1}.
The output symbol has the same ctx as the input symbol.
This function differs from the original numpy.arcsin in
the following aspects:
- Only support _Symbol or scalar now.
- where argument is not supported.
- Complex input is not supported.
References
Abramowitz, M. and Stegun, I. A., Handbook of Mathematical Functions,
10th printing, New York: Dover, 1964, pp. 79ff.
http://www.math.sfu.ca/~cbm/aands/
out (_Symbol or None, optional) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
arcsinh – Array of the same shape as x.
This is a scalar if x is a scalar.
Return type:
_Symbol
Notes
arcsinh is a multivalued function: for each x there are infinitely
many numbers z such that sinh(z) = x.
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
yields nan and sets the invalid floating point error flag.
This function differs from the original numpy.arcsinh in the following aspects:
Do not support where, a parameter in numpy which indicates where to calculate.
Do not support complex-valued input.
Cannot cast type automatically. DType of out must be same as the expected one.
Cannot broadcast automatically. Shape of out must be same as the expected one.
If x is plain python numeric, the result won’t be stored in out.
Trigonometric inverse tangent, element-wise.
The inverse of tan, so that if y=tan(x) then x=arctan(y).
Parameters:
x (_Symbol or scalar) – Input values.
out (_Symbol or None) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
out – Out has the same shape as x. It lies is in
[-pi/2,pi/2] (arctan(+/-inf) returns +/-pi/2).
This is a scalar if x is a scalar.
Return type:
_Symbol
Notes
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, we do not have support for them yet.
The inverse tangent is also known as atan or tan^{-1}.
Element-wise arc tangent of x1/x2 choosing the quadrant correctly.
The quadrant (i.e., branch) is chosen so that arctan2(x1,x2) is
the signed angle in radians between the ray ending at the origin and
passing through the point (1,0), and the ray ending at the origin and
passing through the point (x2, x1). (Note the role reversal: the
“y-coordinate” is the first function parameter, the “x-coordinate”
is the second.) By IEEE convention, this function is defined for
x2 = +/-0 and for either or both of x1 and x2 = +/-inf (see
Notes for specific values).
This function is not defined for complex-valued arguments; for the
so-called argument of complex values, use angle.
Parameters:
x1 (_Symbol or scalar) – y-coordinates.
x2 (_Symbol or scalar) – x-coordinates. x2 must be broadcastable to match the shape of
x1 or vice versa.
out (_Symbol or 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.
Returns:
out – Array of angles in radians, in the range [-pi,pi]. This is a scalar if
x1 and x2 are scalars.
Return type:
_Symbol or scalar
Notes
arctan2 is identical to the atan2 function of the underlying
C library. The following special values are defined in the C
standard: [1]_
Note that +0 and -0 are distinct floating point numbers, as are +inf
and -inf.
This function differs from the original numpy.arange in the following aspects:
out (_Symbol or None, optional) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
arctanh – Array of the same shape as x.
This is a scalar if x is a scalar.
Return type:
_Symbol
Notes
arctanh is a multivalued function: for each x there are infinitely
many numbers z such that tanh(z) = x.
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.
This function differs from the original numpy.arctanh in the following aspects:
Do not support where, a parameter in numpy which indicates where to calculate.
Do not support complex-valued input.
Cannot cast type automatically. Dtype of out must be same as the expected one.
Cannot broadcast automatically. Shape of out must be same as the expected one.
If x is plain python numeric, the result won’t be stored in out.
Returns the indices that would sort an array.
Perform an indirect sort along the given axis using the algorithm specified
by the kind keyword. It returns an array of indices of the same shape as
a that index data along the given axis in sorted order.
Parameters:
a (_Symbol) – Array to sort.
axis (int or None, optional) – Axis along which to sort. The default is -1 (the last axis). If None,
the flattened array is used.
kind (string, optional) – This argument can take any string, but it does not have any effect on the
final result.
order (str or list of str, optional) – Not supported yet, will raise NotImplementedError if not None.
Returns:
index_array – Array of indices that sort a along the specified axis.
If a is one-dimensional, a[index_array] yields a sorted a.
More generally, np.take_along_axis(a,index_array,axis=axis)
always yields the sorted a, irrespective of dimensionality.
decimals (int, optional) – Number of decimal places to round to (default: 0). If
decimals is negative, it specifies the number of positions to
the left of the decimal point.
out (_Symbol, optional) – Alternative output array in which to place the result. It must have
the same shape and type as the expected output.
Returns:
rounded_array – An array of the same type as x, containing the rounded values.
A reference to the result is returned.
Return type:
_Symbol or scalar
Notes
For values exactly halfway between rounded decimal values, NumPy
rounds to the nearest even value. Thus 1.5 and 2.5 round to 2.0,
-0.5 and 0.5 round to 0.0, etc.
This function differs from the original numpy.prod in the following aspects:
Cannot cast type automatically. Dtype of out must be same as the expected one.
If indices_or_sections is an integer, N, the array will be divided
into N equal arrays along axis. If such a split is not possible,
an array of length l that should be split into n sections, it returns
l % n sub-arrays of size l//n + 1 and the rest of size l//n.
If indices_or_sections is a 1-D array of sorted integers, the entries
indicate where along axis the array is split. For example,
[2,3] would, for axis=0, result in
ary[:2]
ary[2:3]
ary[3:]
If an index exceeds the dimension of the array along axis,
an empty sub-array is returned correspondingly.
Parameters:
ary (_Symbol) – Array to be divided into sub-arrays.
indices_or_sections (int or 1-D Python tuple, list or set.) – Param used to determine the number and size of the subarray.
axis (int, optional) – The axis along which to split, default is 0.
Convert inputs to arrays with at least three dimension.
Parameters:
arys1 (_Symbol) – One or more input arrays.
arys2 (_Symbol) – One or more input arrays.
... (_Symbol) – One or more input arrays.
Returns:
ret – An array, or list of arrays, each with a.ndim >= 3.
For example, a 1-D array of shape (N,) becomes a view of shape (1, N, 1),
and a 2-D array of shape (M, N) becomes a view of shape (M, N, 1).
Compute the weighted average along the specified axis.
Parameters:
a (_Symbol) – Array containing data to be averaged.
axis (None or int or tuple of ints, optional) – Axis or axes along which to average a.
The default, axis=None, will average over
all of the elements of the input array.
If axis is negative it counts from the last to the first axis.
New in version 1.7.0.
If axis is a tuple of ints, averaging is
performed on all of the axes specified in the tuple
instead of a single axis or all the axes as before.
weights (_Symbol, optional) – An array of weights associated with the values in a, must be the same dtype with a.
Each value in a contributes to the average according to its associated weight.
The weights array can either be 1-D (in which case its length must be
the size of a along the given axis) or of the same shape as a.
If weights=None, then all data in a are assumed to have a weight equal to one.
The 1-D calculation is: avg = sum(a * weights) / sum(weights)
The only constraint on weights is that sum(weights) must not be 0.
returned (bool, optional) – Default is False.
If True, the tuple (average, sum_of_weights) is returned,
otherwise only the average is returned.
If weights=None, sum_of_weights is equivalent to
the number of elements over which the average is taken.
out (_Symbol, optional) – If provided, the calculation is done into this array.
Returns:
retval, [sum_of_weights] – Return the average along the specified axis.
When returned is True, return a tuple with the average as the first element
and the sum of the weights as the second element. sum_of_weights is of the same type as retval.
If a is integral, the result dtype will beyour current default dtype,
When npx.is_np_default_dtype() returns False, default dtype is float32,
When npx.is_np_default_dtype() returns True, default dtype is float64;
otherwise it will be the same as dtype of a.
Return type:
_Symbol
Raises:
MXNetError –
- When all weights along axis sum to zero. –
- When the length of 1D weights is not the same as the shape of a along axis. –
- When given 1D weights, the axis is not specified or is not int. –
- When the shape of weights and a differ, but weights are not 1D. –
Compute the bit-wise XOR of two arrays element-wise.
Parameters:
x1 (_Symbol or scalar) – Only integer and boolean types are handled. If x1.shape != x2.shape,
they must be broadcastable to a common shape (which becomes the shape of the output).
x2 (_Symbol or scalar) – Only integer and boolean types are handled. If x1.shape != x2.shape,
they must be broadcastable to a common shape (which becomes the shape of the output).
out (_Symbol or 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.
Compute bit-wise inversion, or bit-wise NOT, element-wise.
Computes the bit-wise NOT of the underlying binary representation of
the integers in the input arrays. This ufunc implements the C/Python
operator ~.
Parameters:
x (array_like) – Only integer and boolean types are handled.
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.
Return the binary representation of the input number as a string.
Examples
We’ve seen that 13 is represented by 00001101.
The invert or bit-wise NOT of 13 is then:
>>> x = np.invert(np.array(13, dtype=np.uint8))
>>> x
242
>>> np.binary_repr(x, width=8)
‘11110010’
Notes
bitwise_not is an alias for invert:
>>> np.bitwise_not is np.invert
True
Compute the bit-wise OR of two arrays element-wise.
Parameters:
x1 (_Symbol or scalar) – Only integer and boolean types are handled. If x1.shape != x2.shape,
they must be broadcastable to a common shape (which becomes the shape of the output).
x2 (_Symbol or scalar) – Only integer and boolean types are handled. If x1.shape != x2.shape,
they must be broadcastable to a common shape (which becomes the shape of the output).
out (_Symbol or 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.
Compute the bit-wise XOR of two arrays element-wise.
Parameters:
x1 (_Symbol or scalar) – Only integer and boolean types are handled. If x1.shape != x2.shape,
they must be broadcastable to a common shape (which becomes the shape of the output).
x2 (_Symbol or scalar) – Only integer and boolean types are handled. If x1.shape != x2.shape,
they must be broadcastable to a common shape (which becomes the shape of the output).
out (_Symbol or 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.
The Blackman window is a taper formed by using the first three
terms of a summation of cosines. It was designed to have close to the
minimal leakage possible. It is close to optimal, only slightly worse
than a Kaiser window.
Parameters:
M (int) – Number of points in the output window. If zero or less, an
empty array is returned.
ctx (Context, optional) – An optional device context (default is the current default context).
Returns:
out – The window, with the maximum value normalized to one (the value one
appears only if the number of samples is odd).
When npx.is_np_default_dtype() returns False, default dtype is float32;
When npx.is_np_default_dtype() returns True, default dtype is float64.
Note that you need select numpy.float32 or float64 in this operator.
Most references to the Blackman window come from the signal processing
literature, where it is used as one of many windowing functions for
smoothing values. It is also known as an apodization (which means
“removing the foot”, i.e. smoothing discontinuities at the beginning
and end of the sampled signal) or tapering function. It is known as a
“near optimal” tapering function, almost as good (by some measures)
as the kaiser window.
References
Blackman, R.B. and Tukey, J.W., (1958) The measurement of power spectra,
Dover Publications, New York.
Oppenheim, A.V., and R.W. Schafer. Discrete-Time Signal Processing.
Upper Saddle River, NJ: Prentice-Hall, 1999, pp. 468-471.
broadcast – A readonly view on the original array with the given shape. It is
typically not contiguous. Furthermore, more than one element of a
broadcasted array may refer to a single memory location.
Return type:
array
Raises:
MXNetError – If the array is not compatible with the new shape according to NumPy’s
broadcasting rules.
x (_Symbol) – The values whose cube-roots are required.
out (_Symbol or None) – Dummy parameter to keep the consistency with the ndarray counterpart.
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.
Return the ceiling of the input, element-wise.
The ceil of the ndarray x is the smallest integer i, such that
i >= x. It is often denoted as \(\lceil x \rceil\).
Parameters:
x (_Symbol or scalar) – Input array.
out (_Symbol or None) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
y – The ceiling of each element in x, with float dtype.
This is a scalar if x is a scalar.
Return type:
_Symbol or scalar
Examples
>>> a=np.array([-1.7,-1.5,-0.2,0.2,1.5,1.7,2.0])>>> np.ceil(a)array([-1., -1., -0., 1., 2., 2., 2.])>>> #if you use parameter out, x and out must be ndarray. if not, you will get an error!>>> a=np.array(1)>>> np.ceil(np.array(3.5),a)array(4.)>>> aarray(4.)
Clip (limit) the values in an array.
Given an interval, values outside the interval are clipped to
the interval edges. For example, if an interval of [0,1]
is specified, values smaller than 0 become 0, and values larger
than 1 become 1.
Parameters:
a (_Symbol) – Array containing elements to clip.
a_min (scalar or None) – Minimum value. If None, clipping is not performed on lower
interval edge. Not more than one of a_min and a_max may be
None.
a_max (scalar or None) – Maximum value. If None, clipping is not performed on upper
interval edge. Not more than one of a_min and a_max may be
None.
out (_Symbol or None) – The results will be placed in this array. It may be the input
array for in-place clipping. out must be of the right shape
to hold the output. Its type is preserved.
Returns:
clipped_array – An array with the elements of a, but where values
< a_min are replaced with a_min, and those > a_max
with a_max.
Take a sequence of 1-D arrays and stack them as columns
to make a single 2-D array. 2-D arrays are stacked as-is,
just like with hstack. 1-D arrays are turned into 2-D columns
first.
Parameters:
tup (sequence of 1-D or 2-D arrays.) – Arrays to stack. All of them must have the same first dimension.
Returns:
stacked – The array formed by stacking the given arrays.
a1 (sequence of _Symbols) – The arrays must have the same shape, except in the dimension
corresponding to axis (the first, by default).
a2 (sequence of _Symbols) – The arrays must have the same shape, except in the dimension
corresponding to axis (the first, by default).
... (sequence of _Symbols) – The arrays must have the same shape, except in the dimension
corresponding to axis (the first, by default).
axis (int, optional) – The axis along which the arrays will be joined. If axis is None,
arrays are flattened before use. Default is 0.
out (ndarray, optional) – If provided, the destination to place the result. The shape must be
correct, matching that of what concatenate would have returned if no
out argument were specified.
Return the cross product of two (arrays of) vectors.
The cross product of a and b in \(R^3\) is a vector perpendicular
to both a and b. If a and b are arrays of vectors, the vectors
are defined by the last axis of a and b by default, and these axes
can have dimensions 2 or 3. Where the dimension of either a or b is
2, the third component of the input vector is assumed to be zero and the
cross product calculated accordingly. In cases where both input vectors
have dimension 2, the z-component of the cross product is returned.
Parameters:
a (_Symbol) – Components of the first vector(s).
b (_Symbol) – Components of the second vector(s).
axisa (int, optional) – Axis of a that defines the vector(s). By default, the last axis.
axisb (int, optional) – Axis of b that defines the vector(s). By default, the last axis.
axisc (int, optional) – Axis of c containing the cross product vector(s). Ignored if
both input vectors have dimension 2, as the return is scalar.
By default, the last axis.
axis (int, optional) – If defined, the axis of a, b and c that defines the vector(s)
and cross product(s). Overrides axisa, axisb and axisc.
Returns:
c – Vector cross product(s).
Return type:
_Symbol
Raises:
ValueError – When the dimension of the vector(s) in a and/or b does not
equal 2 or 3.
Return the cumulative sum of the elements along a given axis.
Parameters:
a (_Symbol) – Input array.
axis (int, optional) – Axis along which the cumulative sum is computed. The default
(None) is to compute the cumsum over the flattened array.
dtype (dtype, optional) – Type of the returned array and of the accumulator in which the
elements are summed. If dtype is not specified, it defaults
to the dtype of a, unless a has an integer dtype with a
precision less than that of the default platform integer. In
that case, the default platform integer is used.
out (_Symbol, optional) – Alternative output array in which to place the result. It must
have the same shape and buffer length as the expected output
but the type will be cast if necessary. See doc.ufuncs
(Section “Output arguments”) for more details.
Returns:
cumsum_along_axis – A new array holding the result is returned unless out is
specified, in which case a reference to out is returned. The
result has the same size as a, and the same shape as a if
axis is not None or a is a 1-d array.
x (_Symbol) – Input value. Elements must be of real value.
out (_Symbol or None, optional) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
y – The corresponding degree values; if out was supplied this is a
reference to it.
This is a scalar if x is a scalar.
Return type:
_Symbol of floats
Notes
This function differs from the original numpy.degrees in
the following aspects:
- Input type does not support Python native iterables(list, tuple, …). Only ndarray is supported.
- out param: cannot perform auto broadcasting. out symbol’s shape must be the same as the expected output.
- out param: cannot perform auto type cast. out symbol’s dtype must be the same as the expected output.
- out param does not support scalar input case.
Extracts a diagonal or constructs a diagonal array.
- 1-D arrays: constructs a 2-D array with the input as its diagonal, all other elements are zero.
- 2-D arrays: extracts the k-th Diagonal
Parameters:
array (_Symbol) – The array to apply diag method.
k (offset) – extracts or constructs kth diagonal given input array
Returns:
out (_Symbol)
The extracted diagonal or constructed diagonal array.
This returns a tuple of indices that can be used to access the main diagonal of an array
a with a.ndim >= 2 dimensions and shape (n, n, …, n). For a.ndim = 2 this is
the usual diagonal, for a.ndim > 2 this is the set of indices to access
a[i, i, …, i] for i = [0..n-1].
Create a two-dimensional array with the flattened input as a diagonal.
Parameters:
v (array_like) – Input data, which is flattened and set as the k-th
diagonal of the output.
k (int, optional) – Diagonal to set; 0, the default, corresponds to the “main” diagonal,
a positive (negative) k giving the number of the diagonal above
(below) the main.
If a is 2-D, returns the diagonal of a with the given offset, i.e., the collection of elements of
the form a[i, i+offset]. If a has more than two dimensions, then the axes specified by axis1 and
axis2 are used to determine the 2-D sub-array whose diagonal is returned. The shape of the
resulting array can be determined by removing axis1 and axis2 and appending an index to the
right equal to the size of the resulting diagonals.
Parameters:
a (_Symbol) – Input data from which diagonal are taken.
offset (int, Optional) – Offset of the diagonal from the main diagonal
axis1 (int, Optional) – Axis to be used as the first axis of the 2-D sub-arrays
axis2 (int, Optional) – Axis to be used as the second axis of the 2-D sub-arrays
Returns:
out – Output result
Return type:
_Symbol
Raises:
ValueError – If the dimension of a is less than 2.:
Calculate the n-th discrete difference along the given axis.
Parameters:
a (_Symbol) – Input array
n (int, optional) – The number of times values are differenced. If zero, the input is returned as-is.
axis (int, optional) – The axis along which the difference is taken, default is the last axis.
prepend (_Symbol, optional) – Not supported yet
append (_Symbol, optional) – Not supported yet
Returns:
diff – The n-th differences.
The shape of the output is the same as a except along axis where the dimension is smaller by n.
The type of the output is the same as the type of the difference between any two elements of a.
This is the same as the type of a in most cases.
If both a and b are 1-D arrays, it is inner product of vectors
If both a and b are 2-D arrays, it is matrix multiplication,
If either a or b is 0-D (scalar), it is equivalent to multiply()
and using np.multiply(a,b) or a*b is preferred.
If a is an N-D array and b is a 1-D array, it is a sum product over
the last axis of a and b.
If a is an N-D array and b is a 2-D array, it is a
sum product over the last axis of a and the second-to-last axis of b:
dot(a,b)[i,j,k]=sum(a[i,j,:]*b[:,k])
Parameters:
a (_Symbol) – First argument.
b (_Symbol) – Second argument.
out (_Symbol, optional) – Output argument. It must have the same shape and type as the expected output.
Returns:
output – Returns the dot product of a and b. If a and b are both
scalars or both 1-D arrays then a scalar is returned; otherwise
an array is returned.
If out is given, then it is returned
Split array into multiple sub-arrays along the 3rd axis (depth).
Please refer to the split documentation. dsplit is equivalent
to split with axis=2, the array is always split along the third
axis provided the array dimension is greater than or equal to 3.
Parameters:
ary (_Symbol) – Array to be divided into sub-arrays.
indices_or_sections (int or 1-D Python tuple, list or set.) –
If indices_or_sections is an integer, N, the array will be divided into N equal arrays
along axis 2. If such a split is not possible, an error is raised.
If indices_or_sections is a 1-D array of sorted integers, the entries indicate where
along axis 2 the array is split. For example, [2,3] would result in
ary[:, :, :2]
ary[:, :, 2:3]
ary[:, :, 3:]
If an index exceeds the dimension of the array along axis 2, an error will be thrown.
Stack arrays in sequence depth wise (along third axis).
This is equivalent to concatenation along the third axis after 2-D arrays
of shape (M,N) have been reshaped to (M,N,1) and 1-D arrays of shape
(N,) have been reshaped to (1,N,1). Rebuilds arrays divided by
dsplit.
This function makes most sense for arrays with up to 3 dimensions. For
instance, for pixel-data with a height (first axis), width (second axis),
and r/g/b channels (third axis). The functions concatenate, stack and
block provide more general stacking and concatenation operations.
Parameters:
tup (sequence of _Symbol) – The arrays must have the same shape along all but the first axis.
1-D arrays must have the same length.
Returns:
stacked – The array formed by stacking the given arrays, will be at least 2-D.
Evaluates the Einstein summation convention on the operands.
Using the Einstein summation convention, many common multi-dimensional,
linear algebraic array operations can be represented in a simple fashion.
In implicit mode einsum computes these values.
In explicit mode, einsum provides further flexibility to compute
other array operations that might not be considered classical Einstein
summation operations, by disabling, or forcing summation over specified
subscript labels.
See the notes and examples for clarification.
Parameters:
subscripts (str) – Specifies the subscripts for summation as comma separated list of
subscript labels. An implicit (classical Einstein summation)
calculation is performed unless the explicit indicator ‘->’ is
included as well as subscript labels of the precise output form.
operands (list of _Symbol) – These are the arrays for the operation.
out (_Symbol, optional) – If provided, the calculation is done into this array.
optimize ({False, True}, optional) – Controls if intermediate optimization should occur. No optimization
will occur if False. Defaults to False.
Returns:
output – The calculation based on the Einstein summation convention.
Return type:
_Symbol
Notes
The Einstein summation convention can be used to compute
many multi-dimensional, linear algebraic array operations. einsum
provides a succinct way of representing these.
A non-exhaustive list of these operations,
which can be computed by einsum, is shown below along with examples:
Trace of an array, np.trace().
Return a diagonal, np.diag().
Array axis summations, np.sum().
Transpositions and permutations, np.transpose().
Matrix multiplication and dot product, np.matmul()np.dot().
Vector inner and outer products, np.inner()np.outer().
Broadcasting, element-wise and scalar multiplication, np.multiply().
Tensor contractions, np.tensordot().
The subscripts string is a comma-separated list of subscript labels,
where each label refers to a dimension of the corresponding operand.
Whenever a label is repeated it is summed, so np.einsum('i,i',a,b)
is equivalent to np.inner(a,b). If a label
appears only once, it is not summed, so np.einsum('i',a) produces a
view of a with no changes. A further example np.einsum('ij,jk',a,b)
describes traditional matrix multiplication and is equivalent to
np.matmul(a,b). Repeated subscript labels in one
operand take the diagonal. For example, np.einsum('ii',a) is equivalent
to np.trace(a).
In implicit mode, the chosen subscripts are important
since the axes of the output are reordered alphabetically. This
means that np.einsum('ij',a) doesn’t affect a 2D array, while
np.einsum('ji',a) takes its transpose. Additionally,
np.einsum('ij,jk',a,b) returns a matrix multiplication, while,
np.einsum('ij,jh',a,b) returns the transpose of the
multiplication since subscript ‘h’ precedes subscript ‘i’.
In explicit mode the output can be directly controlled by
specifying output subscript labels. This requires the
identifier ‘->’ as well as the list of output subscript labels.
This feature increases the flexibility of the function since
summing can be disabled or forced when required. The call
np.einsum('i->',a) is like np.sum(a,axis=-1),
and np.einsum('ii->i',a) is like np.diag(a).
The difference is that einsum does not allow broadcasting by default.
Additionally np.einsum('ij,jh->ih',a,b) directly specifies the
order of the output subscript labels and therefore returns matrix
multiplication, unlike the example above in implicit mode.
To enable and control broadcasting, use an ellipsis. Default
NumPy-style broadcasting is done by adding an ellipsis
to the left of each term, like np.einsum('...ii->...i',a).
To take the trace along the first and last axes,
you can do np.einsum('i...i',a), or to do a matrix-matrix
product with the left-most indices instead of rightmost, one can do
np.einsum('ij...,jk...->ik...',a,b).
When there is only one operand, no axes are summed, and no output
parameter is provided, a view into the operand is returned instead
of a new array. Thus, taking the diagonal as np.einsum('ii->i',a)
produces a view.
The optimize argument which will optimize the contraction order
of an einsum expression. For a contraction with three or more operands this
can greatly increase the computational efficiency at the cost of a larger
memory footprint during computation.
Typically a ‘greedy’ algorithm is applied which empirical tests have shown
returns the optimal path in the majority of cases. ‘optimal’ is not supported
for now.
This function differs from the original numpy.einsum in
the following way(s):
Return a new array with the same shape and type as a given array.
Parameters:
prototype (_Symbol) – The shape and data-type of prototype define these same attributes
of the returned array.
dtype (data-type, optional) – Overrides the data type of the result.
order ({'C'}, optional) – Whether to store multidimensional data in C- or Fortran-contiguous
(row- or column-wise) order in memory. Currently only supports C order.
subok (bool, optional.) – If True, then the newly created array will use the sub-class
type of ‘a’, otherwise it will be a base-class array. Defaults
to False.
(Only support False at this moment)
shape (int or sequence of ints, optional.) – Overrides the shape of the result. If order=’K’ and the number of
dimensions is unchanged, will try to keep order, otherwise,
order=’C’ is implied.
(This parameter is not supported at this moment)
Returns:
out – Array of uninitialized (arbitrary) data with the same
shape and type as prototype.
Return a new array with shape of input filled with value.
empty
Return a new uninitialized array.
Notes
This function does not initialize the returned array; to do that use
zeros_like or ones_like instead. It may be marginally faster than
the functions that do set the array values.
x1 (_Symbol or scalars) – Input arrays. If x1.shape!=x2.shape, they must be broadcastable to
a common shape (which becomes the shape of the output).
x2 (_Symbol or scalars) – Input arrays. If x1.shape!=x2.shape, they must be broadcastable to
a common shape (which becomes the shape of the output).
out (Dummy parameter, 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.
Returns:
out – Output array of type bool, element-wise comparison of x1 and x2.
This is a scalar if both x1 and x2 are scalars.
M (int, optional) – Number of columns in the output. If None, defaults to N.
k (int, optional) – Index of the diagonal: 0 (the default) refers to the main diagonal,
a positive value refers to an upper diagonal,
and a negative value to a lower diagonal.
dtype (data-type, optional) – Data-type of the returned array.
When npx.is_np_default_dtype() returns False, default dtype is float32;
When npx.is_np_default_dtype() returns True, default dtype is float64.
Returns:
I – An array where all elements are equal to zero,
except for the k-th diagonal, whose values are equal to one.
This function returns the absolute values (positive magnitude) of the
data in x. Complex values are not handled, use absolute to find the
absolute values of complex data.
Parameters:
x (_Symbol or scalar) – Input array.
out (_Symbol or None) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
absolute – An ndarray containing the absolute value of
each element in x. This is a scalar if x is a scalar.
Axis or axes along which to flip over. The default,
axis=None, will flip over all of the axes of the input array.
If axis is negative it counts from the last to the first axis.
If axis is a tuple of ints, flipping is performed on all of the axes
specified in the tuple.
out (_Symbol or scalar, optional) – Alternative output array in which to place the result. It must have
the same shape and type as the expected output.
Returns:
out – A view of m with the entries of axis reversed. Since a view is
returned, this operation is done in constant time.
Return the floor of the input, element-wise.
The floor of the ndarray x is the largest integer i, such that
i <= x. It is often denoted as \(\lfloor x \rfloor\).
Parameters:
x (_Symbol or scalar) – Input array.
out (_Symbol or None) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
y – The floor of each element in x, with float dtype.
This is a scalar if x is a scalar.
Return type:
_Symbol or scalar
Examples
>>> a=np.array([-1.7,-1.5,-0.2,0.2,1.5,1.7,2.0])>>> np.floor(a)array([-2., -2., -1., 0., 1., 1., 2.])>>> # if you use parameter out, x and out must be ndarray. if not, you will get an error!>>> a=np.array(1)>>> np.floor(np.array(3.5),a)array(3.)>>> aarray(3.)
Return a new array of given shape and type, filled with fill_value.
Parameters:
shape (int or sequence of ints) – Shape of the new array, e.g., (2,3) or 2.
fill_value (scalar or _Symbol) – Fill value.
dtype (data-type, optional) – When npx.is_np_default_dtype() returns False, default dtype is float32;
When npx.is_np_default_dtype() returns True, default dtype is float64.
The desired data-type for the array. The default, None, means
np.array(fill_value).dtype.
order ({'C'}, optional) – Whether to store multidimensional data in C- or Fortran-contiguous
(row- or column-wise) order in memory. Currently only supports C order.
ctx (to specify the device, e.g. the i-th GPU.)
out (ndarray or None, optional) – A location into which the result is stored.
If provided, it must have the same shape and dtype as input ndarray.
If not provided or None, a freshly-allocated array is returned.
Returns:
out – Array of fill_value with the given shape, dtype, and order.
Return a full array with the same shape and type as a given array.
Parameters:
a (_Symbol) – The shape and data-type of a define these same attributes of
the returned array.
fill_value (scalar) – Fill value.
dtype (data-type, optional) – Overrides the data type of the result.
Temporarily do not support boolean type.
order ({'C'}, optional) – Whether to store multidimensional data in C- or Fortran-contiguous
(row- or column-wise) order in memory. Currently only supports C order.
ctx (to specify the device, e.g. the i-th GPU.)
out (ndarray or None, optional) – A location into which the result is stored.
If provided, it must have the same shape and dtype as input ndarray.
If not provided or None, a freshly-allocated array is returned.
Returns:
out – Array fill_value with the same shape and type as a.
Returns the greatest common divisor of |x1| and |x2|
Parameters:
x1 (ndarrays or scalar values) – The arrays for computing greatest common divisor. If x1.shape != x2.shape,
they must be broadcastable to a common shape (which may be the shape of
one or the other).
x2 (ndarrays or scalar values) – The arrays for computing greatest common divisor. If x1.shape != x2.shape,
they must be broadcastable to a common shape (which may be the shape of
one or the other).
out (ndarray or 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.
Returns:
y – The greatest common divisor of the absolute value of the inputs
This is a scalar if both x1 and x2 are scalars.
x1 (_Symbol or scalars) – Input arrays. If x1.shape!=x2.shape, they must be broadcastable to
a common shape (which becomes the shape of the output).
x2 (_Symbol or scalars) – Input arrays. If x1.shape!=x2.shape, they must be broadcastable to
a common shape (which becomes the shape of the output).
out (Dummy parameter, 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.
Returns:
out – Output array of type bool, element-wise comparison of x1 and x2.
This is a scalar if both x1 and x2 are scalars.
Return the truth value of (x1 >= x2) element-wise.
Parameters:
x1 (_Symbol or scalars) – Input arrays. If x1.shape!=x2.shape, they must be broadcastable to
a common shape (which becomes the shape of the output).
x2 (_Symbol or scalars) – Input arrays. If x1.shape!=x2.shape, they must be broadcastable to
a common shape (which becomes the shape of the output).
out (Dummy parameter, 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.
Returns:
out – Output array of type bool, element-wise comparison of x1 and x2.
This is a scalar if both x1 and x2 are scalars.
The hamming window is a taper formed by using a weighted cosine.
Parameters:
M (int) – Number of points in the output window. If zero or less, an
empty array is returned.
ctx (Context, optional) – An optional device context (default is the current default context).
Returns:
out – The window, with the maximum value normalized to one (the value
one appears only if M is odd).
When npx.is_np_default_dtype() returns False, default dtype is float32;
When npx.is_np_default_dtype() returns True, default dtype is float64.
Note that you need select numpy.float32 or float64 in this operator.
The Hamming was named for R. W. Hamming, an associate of J. W. Tukey
and is described in Blackman and Tukey. It was recommended for
smoothing the truncated autocovariance function in the time domain.
Most references to the Hamming window come from the signal processing
literature, where it is used as one of many windowing functions for
smoothing values. It is also known as an apodization (which means
“removing the foot”, i.e. smoothing discontinuities at the beginning
and end of the sampled signal) or tapering function.
The Hanning window is a taper formed by using a weighted cosine.
Parameters:
M (int) – Number of points in the output window. If zero or less, an
empty array is returned.
ctx (Context, optional) – An optional device context (default is the current default context).
Returns:
out – The window, with the maximum value normalized to one (the value
one appears only if M is odd).
When npx.is_np_default_dtype() returns False, default dtype is float32;
When npx.is_np_default_dtype() returns True, default dtype is float64.
Note that you need select numpy.float32 or float64 in this operator.
The Hanning was named for Julius von Hann, an Austrian meteorologist.
It is also known as the Cosine Bell. Some authors prefer that it be
called a Hann window, to help avoid confusion with the very similar
Hamming window.
Most references to the Hanning window come from the signal processing
literature, where it is used as one of many windowing functions for
smoothing values. It is also known as an apodization (which means
“removing the foot”, i.e. smoothing discontinuities at the beginning
and end of the sampled signal) or tapering function.
a (Symbol) – Input data. The histogram is computed over the flattened array.
bins (int or Symbol) – If bins is an int, it defines the number of equal-width
bins in the given range (10, by default). If bins is a
sequence, it defines a monotonically increasing array of bin edges,
including the rightmost edge, allowing for non-uniform bin widths.
.. versionadded:: 1.11.0
If bins is a string, it defines the method used to calculate the
optimal bin width, as defined by histogram_bin_edges.
range ((float, float)) – The lower and upper range of the bins. Required when bins is an integer.
Values outside the range are ignored. The first element of the range must
be less than or equal to the second.
normed (bool, optional) – Not supported yet, coming soon.
weights (array_like, optional) – Not supported yet, coming soon.
density (bool, optional) – Not supported yet, coming soon.
Split an array into multiple sub-arrays horizontally (column-wise).
This is equivalent to split with axis=0 if ary has one
dimension, and otherwise that with axis=1.
Parameters:
ary (_Symbol) – Array to be divided into sub-arrays.
indices_or_sections (int, list of ints or tuple of ints.) –
If indices_or_sections is an integer, N, the array will be divided
into N equal arrays along axis. If such a split is not possible,
an error is raised.
If indices_or_sections is a list of sorted integers, the entries
indicate where along axis the array is split.
If an index exceeds the dimension of the array along axis,
it will raises errors. so index must less than or euqal to
the dimension of the array along axis.
Returns:
sub-arrays – A list of sub-arrays.
Return type:
_Symbol
Notes
If indices_or_sections is given as an integer, but a split
does not result in equal division.It will raises ValueErrors.
If indices_or_sections is an integer, and the number is 1, it will
raises an error. Because single output from split is not supported yet…
If ary has one dimension, ‘axis’ = 0.
>>> x = np.arange(4)
array([0., 1., 2., 3.])
>>> np.hsplit(x, 2)
[array([0., 1.]), array([2., 3.])]
If you want to produce an empty sub-array, you can see an example.
>>> np.hsplit(x, [2, 2])
[array([0., 1.]), array([], dtype=float32), array([2., 3.])]
Stack arrays in sequence horizontally (column wise).
This is equivalent to concatenation along the second axis,
except for 1-D arrays where it concatenates along the first axis.
Rebuilds arrays divided by hsplit.
This function makes most sense for arrays with up to 3 dimensions.
For instance, for pixel-data with a height (first axis), width (second axis),
and r/g/b channels (third axis). The functions concatenate,
stack and block provide more general stacking and concatenation operations.
Parameters:
tup (_Symbol) – The arrays must have the same shape along all but the second axis, except 1-D arrays which can be any length.
Returns:
stacked – The array formed by stacking the given arrays.
Given the “legs” of a right triangle, return its hypotenuse.
Equivalent to sqrt(x1**2+x2**2), element-wise. If x1 or
x2 is scalar_like (i.e., unambiguously cast-able to a scalar type),
it is broadcast for use with each element of the other argument.
Parameters:
x1 (_Symbol or scalar) – Leg of the triangle(s).
x2 (_Symbol or scalar) – Leg of the triangle(s).
out (_Symbol or 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.
Returns:
z – The hypotenuse of the triangle(s).
This is a scalar if both x1 and x2 are scalars.
Return type:
_Symbol or scalar
Notes
This function differs from the original numpy.arange in the following aspects:
The identity array is a square array with ones on
the main diagonal.
Parameters:
n (int) – Number of rows (and columns) in n x n output.
dtype (data-type, optional) – Data-type of the output.
When npx.is_np_default_dtype() returns False, default dtype is float32;
When npx.is_np_default_dtype() returns True, default dtype is float64.
ctx (Context, optional) – An optional device context (default is the current default context).
Returns:
out – n x n array with its main diagonal set to one,
and all other elements 0.
Return an array representing the indices of a grid.
Compute an array where the subarrays contain index values 0,1,…
varying only along the corresponding axis.
Parameters:
dimensions (sequence of ints) – The shape of the grid.
dtype (data-type, optional) – The desired data-type for the array. Default is int64.
ctx (device context, optional) – Device context on which the memory is allocated. Default is
mxnet.context.current_context().
Returns:
grid – The array of grid indices,
grid.shape=(len(dimensions),)+tuple(dimensions).
Return type:
_Symbol
Notes
The output shape is obtained by prepending the number of dimensions
in front of the tuple of dimensions, i.e. if dimensions is a tuple
(r0,...,rN-1) of length N, the output shape is
(N,r0,...,rN-1).
The subarrays grid[k] contains the N-D array of indices along the
k-th axis. Explicitly:
Inner product of two arrays.
Ordinary inner product of vectors for 1-D arrays (without complex
conjugation), in higher dimensions a sum product over the last axes.
Parameters:
a (_Symbol) – If a and b are nonscalar, their last dimensions must match.
b (_Symbol) – If a and b are nonscalar, their last dimensions must match.
Returns:
out – out.shape = a.shape[:-1] + b.shape[:-1]
Return type:
_Symbol
Raises:
ValueError – If the last dimension of a and b has different size.
For vectors (1-D arrays) it computes the ordinary inner-product::
np.inner(a, b) = sum(a[:]*b[:])
More generally, if ndim(a) = r > 0 and ndim(b) = s > 0::
np.inner(a, b) = np.tensordot(a, b, axes=(-1,-1))
or explicitly::
np.inner(a, b)[i0,…,ir-1,j0,…,js-1]
= sum(a[i0,…,ir-1,:]*b[j0,…,js-1,:])
In addition a or b may be scalars, in which case::
np.inner(a,b) = a*b
Examples
Ordinary inner product for vectors:
>>> a = np.array([1,2,3])
>>> b = np.array([0,1,0])
>>> np.inner(a, b)
2
A multidimensional example:
>>> a = np.arange(24).reshape((2,3,4))
>>> b = np.arange(4)
>>> np.inner(a, b)
array([[ 14, 38, 62],
Insert values along the given axis before the given indices.
Parameters:
arr (_Symbol) – Input array.
obj (int, slice or ndarray of int64) – Object that defines the index or indices before which values is
inserted.
Support for multiple insertions when obj is a single scalar or a
sequence with one element (only support int32 and int64 element).
values (_Symbol) – Values to insert into arr.
If the type of values is different from that of arr, values is converted
to the type of arr.
axis (int, optional) – Axis along which to insert values. If axis is None then arr
is flattened first.
Returns:
out – A copy of arr with values inserted. Note that insert
does not occur in-place: a new array is returned. If
axis is None, out is a flattened array.
Return type:
_Symbol
Notes
Note that for higher dimensional inserts obj=0 behaves very different
from obj=[0] just like arr[:,0,:] = values is different from
arr[:,[0],:] = values.
- If obj is a ndarray, it’s dtype only supports int64
One-dimensional linear interpolation.
Returns the one-dimensional piecewise linear interpolant to a function
with given values at discrete data-points.
Parameters:
x (_Symbol) – The x-coordinates of the interpolated values.
xp (_Symbol) – The x-coordinates of the data points, must be increasing if argument
period is not specified. Otherwise, xp is internally sorted after
normalizing the periodic boundaries with xp=xp%period.
fp (_Symbol) – The y-coordinates of the data points, same length as xp.
left (optional float corresponding to fp) – Value to return for x < xp[0], default is fp[0].
right (optional float corresponding to fp) – Value to return for x > xp[-1], default is fp[-1].
period (None or float, optional) – A period for the x-coordinates. This parameter allows the proper
interpolation of angular x-coordinates. Parameters left and right
are ignored if period is specified.
.. versionadded:: 1.10.0
Returns:
y – The interpolated values, same shape as x.
Return type:
_Symbol
Raises:
ValueError – If xp and fp have different length
If xp or fp are not 1-D sequences
If period == 0
Notes
Does not check that the x-coordinate sequence xp is increasing.
If xp is not increasing, the results are nonsense.
A simple check for increasing is:
Compute bit-wise inversion, or bit-wise NOT, element-wise.
Computes the bit-wise NOT of the underlying binary representation of
the integers in the input arrays. This ufunc implements the C/Python
operator ~.
Parameters:
x (array_like) – Only integer and boolean types are handled.
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.
Return the binary representation of the input number as a string.
Examples
We’ve seen that 13 is represented by 00001101.
The invert or bit-wise NOT of 13 is then:
>>> x = np.invert(np.array(13, dtype=np.uint8))
>>> x
242
>>> np.binary_repr(x, width=8)
‘11110010’
Notes
bitwise_not is an alias for invert:
>>> np.bitwise_not is np.invert
True
Test element-wise for finiteness (not infinity or not Not a Number).
Parameters:
x (_Symbol or scalar) – Input array.
out (_Symbol or None, optional) – A location into which the result is stored.
If provided, it must have the same shape and dtype as input ndarray.
If not provided or None, a freshly-allocated array is returned.
Returns:
y – True where x is negative infinity, false otherwise.
This is a scalar if x is a scalar.
Not a Number, positive infinity and negative infinity are considered to be non-finite.
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754).
This means that Not a Number is not equivalent to infinity.
Also that positive infinity is not equivalent to negative infinity.
But infinity is equivalent to positive infinity. Errors result if the second argument
is also supplied when x is a scalar input, or if first and second arguments have different shapes.
Test element-wise for positive or negative infinity.
Parameters:
x (_Symbol or scalar) – Input array.
out (_Symbol or None, optional) – A location into which the result is stored.
If provided, it must have the same shape and dtype as input ndarray.
If not provided or None, a freshly-allocated array is returned.
Returns:
y – True where x is positive or negative infinity, false otherwise.
This is a scalar if x is a scalar.
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754).
This function differs from the original numpy.isinf in
the following aspects:
- Does not support complex number for now
- Input type does not support Python native iterables(list, tuple, …).
- out param: cannot perform auto broadcasting. out ndarray’s shape must be the same as the expected output.
- out param: cannot perform auto type cast. out ndarray’s dtype must be the same as the expected output.
- out param does not support scalar input case.
Test element-wise for NaN and return result as a boolean array.
Parameters:
x (_Symbol or scalar) – Input array.
out (_Symbol or None, optional) – A location into which the result is stored.
If provided, it must have the same shape and dtype as input ndarray.
If not provided or None, a freshly-allocated array is returned.
Returns:
y – True where x is NaN, false otherwise.
This is a scalar if x is a scalar.
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754).
This means that Not a Number is not equivalent to infinity.
This function differs from the original numpy.isnan in
the following aspects:
- Does not support complex number for now
- Input type does not support Python native iterables(list, tuple, …).
- out param: cannot perform auto broadcasting. out ndarray’s shape must be the same as the expected output.
- out param: cannot perform auto type cast. out ndarray’s dtype must be the same as the expected output.
- out param does not support scalar input case.
Test element-wise for negative infinity, return result as bool array.
Parameters:
x (_Symbol or scalar) – Input array.
out (_Symbol or None, optional) – A location into which the result is stored.
If provided, it must have the same shape and dtype as input ndarray.
If not provided or None, a freshly-allocated array is returned.
Returns:
y – True where x is negative infinity, false otherwise.
This is a scalar if x is a scalar.
Test element-wise for positive infinity, return result as bool array.
Parameters:
x (_Symbol or scalar) – Input array.
out (_Symbol or None, optional) – A location into which the result is stored.
If provided, it must have the same shape and dtype as input ndarray.
If not provided or None, a freshly-allocated array is returned.
Returns:
y – True where x is positive infinity, false otherwise.
This is a scalar if x is a scalar.
The function assumes that the number of dimensions of a and b
are the same, if necessary prepending the smallest with ones.
If a.shape = (r0,r1,..,rN) and b.shape = (s0,s1,…,sN),
the Kronecker product has shape (r0*s0, r1*s1, …, rN*SN).
The elements are products of elements from a and b, organized
explicitly by:
Returns the lowest common multiple of |x1| and |x2|
Parameters:
x1 (_Symbols or scalar values) – The arrays for computing lowest common multiple. If x1.shape != x2.shape,
they must be broadcastable to a common shape (which may be the shape of
one or the other).
x2 (_Symbols or scalar values) – The arrays for computing lowest common multiple. If x1.shape != x2.shape,
they must be broadcastable to a common shape (which may be the shape of
one or the other).
out (_Symbol or 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.
Returns:
y – The lowest common multiple of the absolute value of the inputs
This is a scalar if both x1 and x2 are scalars.
Returns x1 * 2**x2, element-wise.
The mantissas x1 and twos exponents x2 are used to construct
floating point numbers x1*2**x2.
Parameters:
x1 (_Symbol) – Array of multipliers.
x2 (_Symbol) – Array of twos exponents.
out (_Symbol or None) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
y – The result of x1*2**x2.
Return type:
_Symbol
Notes
Complex dtypes are not supported, they will raise a TypeError.
Different from numpy, we allow x2 to be float besides int.
ldexp is useful as the inverse of frexp, if used by itself it is
more clear to simply use the expression x1*2**x2.
x1 (_Symbol or scalars) – Input arrays. If x1.shape!=x2.shape, they must be broadcastable to
a common shape (which becomes the shape of the output).
x2 (_Symbol or scalars) – Input arrays. If x1.shape!=x2.shape, they must be broadcastable to
a common shape (which becomes the shape of the output).
out (Dummy parameter, 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.
Returns:
out – Output array of type bool, element-wise comparison of x1 and x2.
This is a scalar if both x1 and x2 are scalars.
Return the truth value of (x1 <= x2) element-wise.
Parameters:
x1 (_Symbol or scalars) – Input arrays. If x1.shape!=x2.shape, they must be broadcastable to
a common shape (which becomes the shape of the output).
x2 (_Symbol or scalars) – Input arrays. If x1.shape!=x2.shape, they must be broadcastable to
a common shape (which becomes the shape of the output).
out (Dummy parameter, 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.
Returns:
out – Output array of type bool, element-wise comparison of x1 and x2.
This is a scalar if both x1 and x2 are scalars.
Return evenly spaced numbers over a specified interval.
Returns num evenly spaced samples, calculated over the interval [start, stop].
The endpoint of the interval can optionally be excluded.
Parameters:
start (real number) – The starting value of the sequence.
stop (real number) – The end value of the sequence, unless endpoint is set to False. In
that case, the sequence consists of all but the last of num + 1
evenly spaced samples, so that stop is excluded. Note that the step
size changes when endpoint is False.
num (int, optional) – Number of samples to generate. Default is 50. Must be non-negative.
endpoint (bool, optional) – If True, stop is the last sample. Otherwise, it is not included.
Default is True.
retstep (bool, optional) – If True, return (samples, step), where step is the spacing between samples.
dtype (dtype, optional) – The type of the output array. If dtype is not given, infer the data
type from the other input arguments.
axis (int, optional) – The axis in the result to store the samples. Relevant only if start or
stop are array-like. By default (0), the samples will be along a new
axis inserted at the beginning. Use -1 to get an axis at the end.
Returns:
samples (_Symbol) – There are num equally spaced samples in the closed interval
[start, stop] or the half-open interval [start, stop)
(depending on whether endpoint is True or False).
step (float, optional) – Only returned if retstep is True
Size of spacing between samples.
Natural logarithm, element-wise.
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 (_Symbol) – Input value. Elements must be of real value.
out (_Symbol or None, optional) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
y – The natural logarithm of x, element-wise.
This is a scalar if x is a scalar.
Return type:
_Symbol
Notes
Currently only supports data of real values and inf as input. Returns data of real value, inf, -inf and
nan according to the input.
This function differs from the original numpy.log in
the following aspects:
- Does not support complex number for now
- Input type does not support Python native iterables(list, tuple, …). Only ndarray is supported.
- out param: cannot perform auto braodcasting. out symbol’s shape must be the same as the expected output.
- out param: cannot perform auto type cast. out symbol’s dtype must be the same as the expected output.
- out param does not support scalar input case.
Return the natural logarithm of one plus the input array, element-wise.
Calculates log(1+x).
Parameters:
x (_Symbol or scalar) – Input array.
out (_Symbol or None) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
y – Natural logarithm of 1 + x, element-wise. This is a scalar
if x is a scalar.
Return type:
_Symbol or scalar
Notes
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.
cannot support complex-valued input.
out (_Symbol or None) – A location into which the result is stored.
If provided, it must have the same shape and type as the input.
If not provided or None, a freshly-allocated array is returned.
Returns:
y – The logarithm base two of x, element-wise.
This is a scalar if x is a scalar.
Return type:
_Symbol
Notes
This function differs from the original numpy.log2 in
the following way(s):
- only ndarray or scalar is accpted as valid input, tuple of ndarray is not supported
- broadcasting to out of different shape is currently not supported
- when input is plain python numerics, the result will not be stored in the out param
Compute the truth value of x1 AND x2 element-wise.
Parameters:
x1 (array_like) – Logical AND is applied to the elements of x1 and x2.
If x1.shape!=x2.shape, they must be broadcastable to a common
shape (which becomes the shape of the output).
x2 (array_like) – Logical AND is applied to the elements of x1 and x2.
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.
Returns:
y – Boolean result of the logical AND operation applied to the elements
of x1 and x2; the shape is determined by broadcasting.
This is a scalar if both x1 and x2 are scalars.
x1 (array_like) – Logical OR is applied to the elements of x1 and x2.
If x1.shape!=x2.shape, they must be broadcastable to a common
shape (which becomes the shape of the output).
x2 (array_like) – Logical OR is applied to the elements of x1 and x2.
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.
Returns:
y – Boolean result of the logical OR operation applied to the elements
of x1 and x2; the shape is determined by broadcasting.
This is a scalar if both x1 and x2 are scalars.
Compute the truth value of x1 XOR x2 element-wise.
Parameters:
x1 (array_like) – Logical XOR is applied to the elements of x1 and x2.
If x1.shape!=x2.shape, they must be broadcastable to a common
shape (which becomes the shape of the output).
x2 (array_like) – Logical XOR is applied to the elements of x1 and x2.
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.
Returns:
y – Boolean result of the logical XOR operation applied to the elements
of x1 and x2; the shape is determined by broadcasting.
This is a scalar if both x1 and x2 are scalars.
In linear space, the sequence starts at base**start
(base to the power of start) and ends with base**stop
(see endpoint below).
Non-scalar start and stop are now supported.
Parameters:
start (scalar) – base**start is the starting value of the sequence.
stop (scalar) – base**stop is the final value of the sequence, unless endpoint
is False. In that case, num+1 values are spaced over the
interval in log-space, of which all but the last (a sequence of
length num) are returned.
num (scalar, optional) – Number of samples to generate. Default is 50.
endpoint (boolean, optional) – If true, stop is the last sample. Otherwise, it is not included.
Default is True.
base (scalar, optional) – The base of the log space. The step size between the elements in
ln(samples)/ln(base) (or log_base(samples)) is uniform.
Default is 10.0.
dtype (dtype) – The type of the output array. If dtype is not given, infer the data
type from the other input arguments.
axis (scalar, optional) – The axis in the result to store the samples. Relevant only if start
or stop are array-like. By default (0), the samples will be along a
new axis inserted at the beginning. Now, axis only support axis = 0.
ctx (Context, optional) – An optional device context (default is the current default context).
Returns:
samples – num samples, equally spaced on a log scale.
Similar to linspace, with the step size specified instead of the number of samples. Note that, when used with a float endpoint, the endpoint may or may not be included.
out (_Symbol, optional) – A location into which the result is stored.
If provided, it must have a shape that matches the signature (n,k),(k,m)->(n,m).
If not provided or None, a freshly-allocated array is returned.
Returns:
y – The matrix product of the inputs.
This is a scalar only when both x1, x2 are 1-d vectors.
Return type:
_Symbol
Raises:
MXNetError – If the last dimension of a is not the same size as the second-to-last dimension of b.
If a scalar value is passed in.
Return the maximum of an array or maximum along an axis.
Parameters:
a (_Symbol) – Input data.
axis (int, optional) – Axis along which to operate. By default, flattened input is used.
out (ndarray, optional) – Alternative output array in which to place the result. Must
be of the same shape and buffer length as the expected output.
See doc.ufuncs (Section “Output arguments”) for more details.
keepdims (bool, optional) – If this is set to True, the axes which are reduced are left
in the result as dimensions with size one. With this option,
the result will broadcast correctly against the original arr.
Returns:
max – Maximum of a. If axis is None, the result is an array of dimension 1.
If axis is given, the result is an array of dimension
a.ndim-1.
Compute the arithmetic mean along the specified axis.
Returns the average of the array elements.
The average is taken over the flattened array by default, otherwise over the specified axis.
Parameters:
a (_Symbol) – _Symbol containing numbers whose mean is desired.
axis (None or int or tuple of ints, optional) – Axis or axes along which the means are computed. The default is to compute the mean of the flattened array.
If this is a tuple of ints, a mean is performed over multiple axes,
instead of a single axis or all the axes as before.
dtype (data-type, optional) – Type to use in computing the mean.
For integer inputs, When npx.is_np_default_dtype() returns False, default dtype is float32,
When npx.is_np_default_dtype() returns True, default dtype is float64;
for floating point inputs, it is the same as the input dtype.
out (_Symbol, optional) – Dummy parameter to keep the consistency with the ndarray counterpart.
keepdims (bool, optional) – If this is set to True, the axes which are reduced are left in the result
as dimensions with size one. With this option, the result will broadcast correctly
against the input array.
If the default value is passed, then keepdims will not be passed through to the mean
method of sub-classes of _Symbol, however any non-default value will be. If the sub-class
method does not implement keepdims any exceptions will be raised.
Returns:
m – If out=None, returns a new array containing the mean values,
otherwise a reference to the output array is returned.
Return type:
_Symbol, see dtype parameter above
Notes
This function differs from the original numpy.mean in
the following way(s):
only _Symbol is accepted as valid input, python iterables or scalar is not supported
default data type for integer input is float32 or float64, which depends on your current default dtype
Compute the median along the specified axis.
Returns the median of the array elements.
Parameters:
a (_Symbol) – Input array or object that can be converted to an array.
axis ({int, sequence of int, None}, optional) – Axis or axes along which the medians are computed. The default
is to compute the median along a flattened version of the array.
A sequence of axes is supported since version 1.9.0.
out (_Symbol, optional) – Alternative output array in which to place the result. It must
have the same shape and buffer length as the expected output,
but the type (of the output) will be cast if necessary.
keepdims (bool, optional) – If this is set to True, the axes which are reduced are left
in the result as dimensions with size one. With this option,
the result will broadcast correctly against the original arr.
Returns:
median – A new array holding the result. If the input contains integers
or floats smaller than float32, then the output data-type is
np.float32. Otherwise, the data-type of the output is the
same as that of the input. If out is specified, that array is
returned instead.
axis (int, optional) – Axis along which to operate. By default, flattened input is used.
out (ndarray, optional) – Alternative output array in which to place the result. Must
be of the same shape and buffer length as the expected output.
See doc.ufuncs (Section “Output arguments”) for more details.
keepdims (bool, optional) – If this is set to True, the axes which are reduced are left
in the result as dimensions with size one. With this option,
the result will broadcast correctly against the original arr.
Returns:
min – Minimum of a. If axis is None, the result is an array of dimension 1.
If axis is given, the result is an array of dimension
a.ndim-1.
Move axes of an array to new positions.
Other axes remain in their original order.
Parameters:
a (_Symbol) – The array whose axes should be reordered.
source : int or sequence of int
Original positions of the axes to move. These must be unique.
destination : int or sequence of int
Destination positions for each of the original axes. These must also be
unique.
Returns:
result – Array with moved axes. This array is a view of the input array.
Replace NaN with zero and infinity with large finite numbers (default
behaviour) or with the numbers defined by the user using the nan,
posinf and/or neginf keywords.
If x is inexact, NaN is replaced by zero or by the user defined value in
nan keyword, infinity is replaced by the largest finite floating point
values representable by x.dtype or by the user defined value in
posinf keyword and -infinity is replaced by the most negative finite
floating point values representable by x.dtype or by the user defined
value in neginf keyword.
For complex dtypes, the above is applied to each of the real and
imaginary components of x separately.
If x is not inexact, then no replacements are made.
Parameters:
x (_Symbol) – Input data.
copy (bool, optional) – Whether to create a copy of x (True) or to replace values
in-place (False). The in-place operation only occurs if
casting to an array does not require a copy.
Default is True.
nan (int, float, optional) – Value to be used to fill NaN values. If no value is passed
then NaN values will be replaced with 0.0.
posinf (int, float, optional) – Value to be used to fill positive infinity values. If no value is
passed then positive infinity values will be replaced with a very
large number.
Value to be used to fill negative infinity values. If no value is
passed then negative infinity values will be replaced with a very
small (or negative) number.
Added in version 1.13.
Returns:
out – x, with the non-finite values replaced. If copy is False, this may
be x itself.
Return type:
_Symbol
Notes
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic
(IEEE 754). This means that Not a Number is not equivalent to infinity.
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.
x1 (_Symbol or scalars) – Input arrays. If x1.shape!=x2.shape, they must be broadcastable to
a common shape (which becomes the shape of the output).
x2 (_Symbol or scalars) – Input arrays. If x1.shape!=x2.shape, they must be broadcastable to
a common shape (which becomes the shape of the output).
out (Dummy parameter, 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.
Returns:
out – Output array of type bool, element-wise comparison of x1 and x2.
This is a scalar if both x1 and x2 are scalars.
Return a new array of given shape and type, filled with ones.
This function currently only supports storing multi-dimensional data
in row-major (C-style).
Parameters:
shape (int or tuple of int) – The shape of the empty array.
dtype (str or numpy.dtype, optional) – An optional value type.
When npx.is_np_default_dtype() returns False, default dtype is float32;
When npx.is_np_default_dtype() returns True, default dtype is float64.
Note that this behavior is different from NumPy’s ones function where
float64 is the default value.
order ({'C'}, optional, default: 'C') – How to store multi-dimensional data in memory, currently only row-major
(C-style) is supported.
ctx (Context, optional) – An optional device context (default is the current default context).
Returns:
out – Array of ones with the given shape, dtype, and ctx.
Return an array of ones with the same shape and type as a given array.
Parameters:
a (_Symbol) – The shape and data-type of a define these same attributes of
the returned array.
fill_value (scalar) – Fill value.
dtype (data-type, optional) – Overrides the data type of the result.
Temporarily do not support boolean type.
order ({'C'}, optional) – Whether to store multidimensional data in C- or Fortran-contiguous
(row- or column-wise) order in memory. Currently only supports C order.
ctx (to specify the device, e.g. the i-th GPU.)
out (ndarray or None, optional) – A location into which the result is stored.
If provided, it must have the same shape and dtype as input ndarray.
If not provided or None, a freshly-allocated array is returned.
Returns:
out – Array of ones with the same shape and type as a.
Compute the outer product of two vectors.
Given two vectors, a=[a0,a1,...,aM] and
b=[b0,b1,...,bN],
the outer product [1]_ is::
[[a0*b0 a0*b1 … a0*bN ]
[a1*b0 .
[ … .
[aM*b0 aM*bN ]]
Parameters:
a ((M,) _Symbol) – First input vector. Input is flattened if
not already 1-dimensional.
b ((N,) _Symbol) – Second input vector. Input is flattened if
not already 1-dimensional.
pad_width ({sequence, array_like, int}) – Number of values padded to the edges of each axis.
((before_1, after_1), … (before_N, after_N)) unique pad widths
for each axis.
((before, after),) yields same before and after pad for each axis.
(pad,) or int is a shortcut for before = after = pad width for all
axes.
mxnet.symbol.numpy.percentile(a, q, axis=None, out=None, overwrite_input=None, interpolation='linear', keepdims=False)¶
Compute the q-th percentile of the data along the specified axis.
Returns the q-th percentile(s) of the array elements.
Parameters:
a (_Symbol) – Input array
q (_Symbol) – Percentile or sequence of percentiles to compute.
axis ({int, tuple of int, None}, optional) – Axis or axes along which the percentiles are computed. The default is to
compute the percentile(s) along a flattened version of the array.
out (ndarray, optional) – Alternative output array in which to place the result. It must have the same
shape and buffer length as the expected output, but the type (of the output)
will be cast if necessary.
overwrite_input (bool, optional (Not supported yet)) – If True, then allow the input array a to be modified by intermediate calculations,
to save memory. In this case, the contents of the input a after this function
completes is undefined.
interpolation ({'linear', 'lower', 'higher', 'midpoint', 'nearest'}) – This optional parameter specifies the interpolation method to use when the
desired percentile lies between two data points i < j:
‘linear’: i + (j - i) * fraction, where fraction is the fractional part of the
index surrounded by i and j.
‘lower’: i.
‘higher’: j.
‘nearest’: i or j, whichever is nearest.
‘midpoint’: (i + j) / 2.
keepdims (bool, optional) – If this is set to True, the axes which are reduced are left in the result as
dimensions with size one. With this option, the result will broadcast
correctly against the original array a.
Evaluate a polynomial at specific values.
If p is of length N, this function returns the value:
p[0]*x**(N-1) + p[1]*x**(N-2) + … + p[N-2]*x + p[N-1]
If x is a sequence, then p(x) is returned for each element of x.
If x is another polynomial then the composite polynomial p(x(t)) is returned.
Parameters:
p (_Symbol) – 1D array of polynomial coefficients (including coefficients equal to zero)
from highest degree to the constant term.
x (_Symbol) – An array of numbers, at which to evaluate p.
Returns:
values – Result array of polynomials
Return type:
_Symbol
Notes
This function differs from the original numpy.polyval in
the following way(s):
- Does not support poly1d.
- X should be ndarray type even if it contains only one element.
Return the product of array elements over a given axis.
Parameters:
a (array_like) – Input data.
axis (None or int or tuple of ints, optional) – Axis or axes along which a product is performed. The default,
axis=None, will calculate the product of all the elements in the
input array. If axis is negative it counts from the last to the
first axis.
.. versionadded:: 1.7.0
If axis is a tuple of ints, a product is performed on all of the
axes specified in the tuple instead of a single axis or all the
axes as before.
dtype (dtype, optional) – The type of the returned array, as well as of the accumulator in
which the elements are multiplied. The dtype of a is used by
default unless a has an integer dtype of less precision than the
default platform integer. In that case, if a is signed then the
platform integer is used while if a is unsigned then an unsigned
integer of the same precision as the platform integer is used.
out (ndarray, optional) – Alternative output array in which to place the result. It must have
the same shape as the expected output, but the type of the output
values will be cast if necessary.
keepdims (bool, optional) – If this is set to True, the axes which are reduced are left in the
result as dimensions with size one. With this option, the result
will broadcast correctly against the input array.
If the default value is passed, then keepdims will not be
passed through to the prod method of sub-classes of
ndarray, however any non-default value will be. If the
sub-class’ method does not implement keepdims any
exceptions will be raised.
initial (scalar, optional) – The starting value for this product. See ~numpy.ufunc.reduce for details.
where (not supported)
Returns:
product_along_axis – An array shaped as a but with the specified axis removed.
Returns a reference to out if specified.
Return type:
ndarray, see dtype parameter above.
Examples
By default, calculate the product of all elements:
>>> np.prod([1.,2.])
2.0
Even when the input array is two-dimensional:
>>> np.prod([[1.,2.],[3.,4.]])
24.0
But we can also specify the axis over which to multiply:
>>> np.prod([[1.,2.],[3.,4.]], axis=1)
array([ 2., 12.])
Or select specific elements to include:
>>> np.prod([1., np.nan, 3.], where=[True, False, True])
3.0
If the type of x is unsigned, then the output type is
the unsigned platform integer:
>>> x = np.array([1, 2, 3], dtype=np.uint8)
>>> np.prod(x).dtype == np.uint
True
If x is of a signed integer type, then the output type
is the default platform integer:
>>> x = np.array([1, 2, 3], dtype=np.int8)
>>> np.prod(x).dtype == int
True
You can also start the product with a value other than one:
>>> np.prod([1, 2], initial=5)
10
mxnet.symbol.numpy.quantile(a, q, axis=None, out=None, overwrite_input=None, interpolation='linear', keepdims=False)¶
Compute the q-th quantile of the data along the specified axis.
New in version 1.15.0.
Parameters:
a (_Symbol) – Input array or object that can be converted to an array.
q (_Symbol) – Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive.
axis ({int, tuple of int, None}, optional) – Axis or axes along which the quantiles are computed.
The default is to compute the quantile(s) along a flattened version of the array.
out (ndarray, optional) – Alternative output array in which to place the result.
It must have the same shape and buffer length as the expected output,
but the type (of the output) will be cast if necessary.
This optional parameter specifies the interpolation method to use
when the desired quantile lies between two data points i < j:
linear: i + (j - i) * fraction, where fraction is the fractional part of the index surrounded by i and j.
lower: i.
higher: j.
nearest: i or j, whichever is nearest.
midpoint: (i + j) / 2.
keepdims (bool, optional) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one.
With this option, the result will broadcast correctly against the original array a.
Returns:
quantile – If q is a single quantile and axis=None, then the result is a scalar.
If multiple quantiles are given, first axis of the result corresponds to the quantiles.
The other axes are the axes that remain after the reduction of a.
If out is specified, that array is returned instead.
Given a vector V of length N, the q-th quantile of V is the value q of the way from the minimum
to the maximum in a sorted copy of V. The values and distances of the two nearest neighbors
as well as the interpolation parameter will determine the quantile if the normalized ranking
does not match the location of q exactly. This function is the same as the median if q=0.5,
the same as the minimum if q=0.0 and the same as the maximum if q=1.0.
This function differs from the original numpy.quantile in
the following aspects:
- q must be _Symbol type even if it is a scalar
- do not support overwrite_input
out (_Symbol or None) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
y – The corresponding radian values. This is a scalar if x is a scalar.
Return type:
_Symbol
Notes
This function differs from the original numpy.radians in
the following way(s):
- only _Symbol or scalar is accpted as valid input, tuple of _Symbol is not supported
- broadcasting to out of different shape is currently not supported
- when input is plain python numerics, the result will not be stored in the out param
Return a contiguous flattened array.
A 1-D array, containing the elements of the input, is returned. A copy is
made only if needed.
Parameters:
x (_Symbol) – Input array. The elements in x are read in row-major, C-style order and
packed as a 1-D array.
order (C, optional) – Only support row-major, C-style order.
Returns:
y – y is an array of the same subtype as x, with shape (x.size,).
Note that matrices are special cased for backward compatibility, if x
is a matrix, then y is a 1-D ndarray.
Return type:
_Symbol
Notes
This function differs from the original numpy.arange in the following aspects:
Return the reciprocal of the argument, element-wise.
Calculates 1/x.
Parameters:
x (_Symbol or scalar) – The values whose reciprocals are required.
out (_Symbol, or None, optional) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
y – Output array is same shape and type as x. This is a scalar if x is a scalar.
Return type:
_Symbol or scalar
Notes
Note
This function is not designed to work with integers.
For integer arguments with absolute value larger than 1 the result is
always zero because of the way Python handles integer division. For
integer zero the result is an overflow.
The output symbol has the same ctx as the input symbol.
This function differs from the original numpy.reciprocal in
the following aspects:
- Only support _Symbol and scalar now.
- where argument is not supported.
Gives a new shape to an array without changing its data.
This function always returns a copy of the input array if
out is not provided.
Parameters:
a (_Symbol) – Array to be reshaped.
newshape (int or tuple of ints) – The new shape should be compatible with the original shape. If
an integer, then the result will be a 1-D array of that length.
One shape dimension can be -1. In this case, the value is
inferred from the length of the array and remaining dimensions.
order ({'C'}, optional) – Read the elements of a using this index order, and place the
elements into the reshaped array using this index order. ‘C’
means to read / write the elements using C-like index order,
with the last axis index changing fastest, back to the first
axis index changing slowest. Other order types such as ‘F’/’A’
may be added in the future.
Returns:
reshaped_array – It will be always a copy of the original array. This behavior is different
from the official NumPy reshape operator where views of the original array may be
generated.
Return a new array with the specified shape.
If the new array is larger than the original array, then the new
array is filled with repeated copies of a. Note that this behavior
is different from a.resize(new_shape) which fills with zeros instead
of repeated copies of a.
Parameters:
a (_Symbol) – Array to be resized.
new_shape (int or tuple of int) – Shape of resized array.
Returns:
reshaped_array – The new array is formed from the data in the old array, repeated
if necessary to fill out the required number of elements. The
data are repeated in the order that they are stored in memory.
Return type:
_Symbol
See also
ndarray.resize
resize an array in-place.
Notes
Warning: This functionality does not consider axes separately,
i.e. it does not apply interpolation/extrapolation.
It fills the return array with the required number of elements, taken
from a as they are laid out in memory, disregarding strides and axes.
(This is in case the new shape is smaller. For larger, see above.)
This functionality is therefore not suitable to resize images,
or data where each axis represents a separate and distinct entity.
Round elements of the array to the nearest integer.
Parameters:
x (_Symbol or scalar) – Input array.
out (_Symbol or None) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
out – Output array is same shape and type as x. This is a scalar if x is a scalar.
Return type:
_Symbol or scalar
Notes
This function differs from the original numpy.rint in
the following way(s):
- only _Symbol or scalar is accpted as valid input, tuple of _Symbol is not supported
broadcasting to out of different shape is currently not supported
when input is plain python numerics, the result will not be stored in the out param
Elements that roll beyond the last position are re-introduced at
the first.
Parameters:
a (_Symbol) – Input array.
shift (int or tuple of ints) – The number of places by which elements are shifted. If a tuple,
then axis must be a tuple of the same size, and each of the
given axes is shifted by the corresponding number. If an int
while axis is a tuple of ints, then the same value is used for
all given axes.
axis (int or tuple of ints, optional) – Axis or axes along which elements are shifted. By default, the
array is flattened before shifting, after which the original
shape is restored.
Returns:
res – Output array, with the same shape as a.
Return type:
_Symbol
Notes
Supports rolling over multiple dimensions simultaneously.
Stack arrays in sequence vertically (row wise).
This is equivalent to concatenation along the first axis after 1-D arrays
of shape (N,) have been reshaped to (1,N). Rebuilds arrays divided by
vsplit.
This function makes most sense for arrays with up to 3 dimensions. For
instance, for pixel-data with a height (first axis), width (second axis),
and r/g/b channels (third axis). The functions concatenate and stack
provide more general stacking and concatenation operations.
Parameters:
tup (sequence of _Symbol) – The arrays must have the same shape along all but the first axis.
1-D arrays must have the same length.
Returns:
stacked – The array formed by stacking the given arrays, will be at least 2-D.
ary (_Symbol) – Array to be divided into sub-arrays.
indices_or_sections (int or 1-D python tuple, list or set.) –
If indices_or_sections is an integer, N, the array will be divided
into N equal arrays along axis. If such a split is not possible,
an error is raised.
If indices_or_sections is a 1-D array of sorted integers, the entries
indicate where along axis the array is split. For example,
[2,3] would, for axis=0, result in
ary[:2]
ary[2:3]
ary[3:]
If an index exceeds the dimension of the array along axis,
an empty sub-array is returned correspondingly.
axis (int, optional) – The axis along which to split, default is 0.
Returns:
sub-arrays – A list of sub-arrays.
Return type:
_Symbol
Raises:
ValueError – If indices_or_sections is given as an integer, but
a split does not result in equal division.
x (_Symbol or scalar) – The values whose reciprocals are required.
out (_Symbol, or None, optional) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
y – Output array is same shape and type as x. This is a scalar if x is a scalar.
Return type:
_Symbol or scalar
Notes
The output symbol has the same ctx as the input symbol.
This function differs from the original numpy.square in
the following aspects:
- Only support _Symbol and scalar now.
- where argument is not supported.
Insert, remove, and combine dimensions, and resize existing ones
Examples
>>> x=np.array([[[0],[1],[2]]])>>> x.shape(1, 3, 1)>>> np.squeeze(x).shape(3,)>>> np.squeeze(x,axis=0).shape(3, 1)>>> np.squeeze(x,axis=1).shapeTraceback (most recent call last):...ValueError: cannot select an axis to squeeze out which has size not equal to one>>> np.squeeze(x,axis=2).shape(1, 3)
The axis parameter specifies the index of the new axis in the dimensions of the result.
For example, if axis=0 it will be the first dimension and if axis=-1 it will be the last dimension.
Parameters:
arrays (sequence of _Symbols) – Each array must have the same shape.
axis (int, optional) – The axis in the result array along which the input arrays are stacked.
out (_Symbol, optional) – If provided, the destination to place the result. The shape must be correct,
matching that of what stack would have returned if no out argument were specified.
Returns:
stacked – The stacked array has one more dimension than the input arrays.
Compute the standard deviation along the specified axis.
Returns the standard deviation, a measure of the spread of a distribution,
of the array elements. The standard deviation is computed for the
flattened array by default, otherwise over the specified axis.
Parameters:
a (_Symbol) – _Symbol containing numbers whose standard deviation is desired.
axis (None or int or tuple of ints, optional) – Axis or axes along which the standard deviations are computed.
The default is to compute the standard deviation of the flattened array.
If this is a tuple of ints, computation is performed over multiple axes,
instead of a single axis or all the axes as before.
dtype (data-type, optional) – Type to use in computing the standard deviation. For integer inputs, the default is float32;
for floating point inputs, it is the same as the input dtype.
out (_Symbol, optional) – Dummy parameter to keep the consistency with the ndarray counterpart.
keepdims (bool, optional) – If this is set to True, the axes which are reduced are left in the result
as dimensions with size one. With this option, the result will broadcast correctly
against the input array.
If the default value is passed, then keepdims will not be passed through to the mean
method of sub-classes of _Symbol, however any non-default value will be. If the sub-class
method does not implement keepdims any exceptions will be raised.
Returns:
m – If out=None, returns a new array containing the standard deviation values,
otherwise a reference to the output array is returned.
Return type:
_Symbol, see dtype parameter above
Notes
This function differs from the original numpy.std in
the following way(s):
only _Symbol is accepted as valid input, python iterables or scalar is not supported
default output data type for integer input is float32
axis (None or int, optional) – Axis or axes along which a sum is performed. The default,
axis=None, will sum all of the elements of the input array. If
axis is negative it counts from the last to the first axis.
dtype (dtype, optional) – The type of the returned array and of the accumulator in which the
elements are summed. The default type is float32.
If this is set to True, the axes which are reduced are left
in the result as dimensions with size one. With this option,
the result will broadcast correctly against the input array.
If the default value is passed, then keepdims will not be
passed through to the sum method of sub-classes of
ndarray, however any non-default value will be. If the
sub-classes sum method does not implement keepdims any
exceptions will be raised.
initial (Currently only supports None as input, optional) – Starting value for the sum.
Currently not implemented. Please use None as input or skip this argument.
out (ndarray or None, optional) – Alternative output array in which to place the result. It must have
the same shape and dtype as the expected output.
Returns:
sum_along_axis – An ndarray with the same shape as a, with the specified
axis removed. If an output array is specified, a reference to
out is returned.
When axis is not None, this function does the same thing as “fancy”
indexing (indexing arrays using arrays); however, it can be easier to use
if you need elements along a given axis. A call such as
np.take(arr,indices,axis=3) is equivalent to
arr[:,:,:,indices,...].
Explained without fancy indexing, this is equivalent to the following use
of ndindex, which sets each of ii, jj, and kk to a tuple of
indices:
indices (_Symbol) – The indices of the values to extract. Also allow scalars for indices.
axis (int, optional) – The axis over which to select values. By default, the flattened
input array is used.
out (_Symbol or None, optional) – Dummy parameter to keep the consistency with the ndarray counterpart.
mode ({'clip', 'wrap'}, optional) –
Specifies how out-of-bounds indices will behave.
’clip’ – clip to the range (default)
’wrap’ – wrap around
’clip’ mode means that all indices that are too large are replaced
by the index that addresses the last element along that axis. Note
that this disables indexing with negative numbers.
Returns:
out – The returned array has the same type as a.
Return type:
_Symbol
Notes
This function differs from the original numpy.take in
the following way(s):
Only ndarray or scalar ndarray is accepted as valid input.
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.
Compute hyperbolic tangent element-wise.
Equivalent to np.sinh(x)/np.cosh(x).
Parameters:
x (_Symbol) – Input array.
out (_Symbol or None) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
y – The corresponding hyperbolic tangent values.
Return type:
_Symbol
Notes
If out is provided, the function writes the result into it,
and returns a reference to out. (See Examples)
- input x does not support complex computation (like imaginary number)
>>> np.tanh(np.pi*1j)
TypeError: type <type ‘complex’> not supported
Examples
>>> np.tanh(np.array[0,np.pi]))array([0. , 0.9962721])>>> np.tanh(np.pi)0.99627207622075>>> # Example of providing the optional output parameter illustrating>>> # that what is returned is a reference to said parameter>>> out1=np.array(1)>>> out2=np.tanh(np.array(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)))mxnet.base.MXNetError:[07:17:36] ../src/ndarray/./../operator/tensor/../elemwise_op_common.h:135:Check failed: assign(&dattr, vec.at(i)): Incompatible attr in nodeat 0-th output: expected [3,3], got [2,2]
Compute tensor dot product along specified axes for arrays >= 1-D.
Given two tensors (arrays of dimension greater than or equal to one),
a and b, and an ndarray object containing two ndarray
objects, (a_axes,b_axes), sum the products of a’s and b’s
elements (components) over the axes specified by a_axes and
b_axes. The third argument can be a single non-negative
integer_like scalar, N; if it is such, then the last N
dimensions of a and the first N dimensions of b are summed
over.
If an int N, sum over the last N axes of a and the first N axes
of b in order. The sizes of the corresponding axes must match.
* (2,) array_like
Or, a list of axes to be summed over, first sequence applying to a,
second to b. Both elements array_like must be of the same length.
When axes is integer_like, the sequence for evaluation will be: first
the -Nth axis in a and 0th axis in b, and the -1th axis in a and
Nth axis in b last.
When there is more than one axis to sum over - and they are not the last
(first) axes of a (b) - the argument axes should consist of
two sequences of the same length, with the first axis to sum over given
first in both sequences, the second axis second, and so forth.
Construct an array by repeating A the number of times given by reps.
If reps has length d, the result will have dimension of
max(d,A.ndim).
If A.ndim<d, A is promoted to be d-dimensional by prepending new
axes. So a shape (3,) array is promoted to (1, 3) for 2-D replication,
or shape (1, 1, 3) for 3-D replication. If this is not the desired
behavior, promote A to d-dimensions manually before calling this
function.
If A.ndim>d, reps is promoted to A.ndim by pre-pending 1’s to it.
Thus for an A of shape (2, 3, 4, 5), a reps of (2, 2) is treated as
(1, 1, 2, 2).
Parameters:
A (_Symbol or scalar) – An input array or a scalar to repeat.
reps (a single integer or tuple of integers) – The number of repetitions of x along each axis.
Return the sum along diagonals of the array.
If a is 2-D, the sum along its diagonal with the given offset
is returned, i.e., the sum of elements a[i,i+offset] for all i.
If a has more than two dimensions, then the axes specified by axis1 and
axis2 are used to determine the 2-D sub-arrays whose traces are returned.
The shape of the resulting array is the same as that of a with axis1
and axis2 removed.
Parameters:
a (_Symbol) – Input array, from which the diagonals are taken.
offset (int, optional) – Offset of the diagonal from the main diagonal. Can be both positive
and negative. Defaults to 0.
axis1 (int, optional) – Axes to be used as the first and second axis of the 2-D sub-arrays
from which the diagonals should be taken. Defaults are the first two
axes of a.
axis2 (int, optional) – Axes to be used as the first and second axis of the 2-D sub-arrays
from which the diagonals should be taken. Defaults are the first two
axes of a.
out (_Symbol) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
sum_along_diagonals – If a is 2-D, the sum along the diagonal is returned. If a has
larger dimensions, then an array of sums along diagonals is returned.
M (int, optional) – Number of columns in the array.
By default, M is taken equal to N.
k (int, optional) – The sub-diagonal at and below which the array is filled.
k = 0 is the main diagonal, while k < 0 is below it,
and k > 0 is above. The default is 0.
dtype (dtype, optional) – Data type of the returned array. The default is float.
Returns:
tri – Array with its lower triangle filled with ones and zero elsewhere;
in other words T[i,j]==1 for i<=j+k, 0 otherwise.
Compute two different sets of indices to access 4x4 arrays, one for the
lower triangular part starting at the main diagonal, and one starting two
diagonals further right:
Return the truncated value of the input, element-wise.
The truncated value of the scalar x is the nearest integer i which
is closer to zero than x is. In short, the fractional part of the
signed number x is discarded.
Parameters:
x (_Symbol or scalar) – Input data.
out (_Symbol or None, optional) – Dummy parameter to keep the consistency with the ndarray counterpart.
Returns:
y – The truncated value of each element in x.
This is a scalar if x is a scalar.
Return type:
_Symbol or scalar
Notes
This function differs from the original numpy.trunc in the following aspects:
Do not support where, a parameter in numpy which indicates where to calculate.
Cannot cast type automatically. Dtype of out must be same as the expected one.
Cannot broadcast automatically. Shape of out must be same as the expected one.
If x is plain python numeric, the result won’t be stored in out.
Returns the sorted unique elements of an array. There are three optional
outputs in addition to the unique elements:
the indices of the input array that give the unique values
the indices of the unique array that reconstruct the input array
the number of times each unique value comes up in the input array
Parameters:
ar (_Symbol) – Input array. Unless axis is specified, this will be flattened if it
is not already 1-D.
return_index (bool, optional) – If True, also return the indices of ar (along the specified axis,
if provided, or in the flattened array) that result in the unique array.
return_inverse (bool, optional) – If True, also return the indices of the unique array (for the specified
axis, if provided) that can be used to reconstruct ar.
return_counts (bool, optional) – If True, also return the number of times each unique item appears
in ar.
axis (int or None, optional) – The axis to operate on. If None, ar will be flattened. If an integer,
the subarrays indexed by the given axis will be flattened and treated
as the elements of a 1-D array with the dimension of the given axis,
see the notes for more details. The default is None.
Returns:
unique (_Symbol) – The sorted unique values.
unique_indices (_Symbol, optional) – The indices of the first occurrences of the unique values in the
original array. Only provided if return_index is True.
unique_inverse (_Symbol, optional) – The indices to reconstruct the original array from the
unique array. Only provided if return_inverse is True.
unique_counts (_Symbol, optional) – The number of times each of the unique values comes up in the
original array. Only provided if return_counts is True.
Notes
When an axis is specified the subarrays indexed by the axis are sorted.
This is done by making the specified axis the first dimension of the array
and then flattening the subarrays in C order. The flattened subarrays are
then viewed as a structured type with each element given a label, with the
effect that we end up with a 1-D array of structured types that can be
treated in the same way as any other 1-D array. The result is that the
flattened subarrays are sorted in lexicographic order starting with the
first element.
An integer array whose elements are indices into the flattened version of an array of dimensions shape.
Before version 1.6.0, this function accepted just one index value.
shapetuple of ints
The shape of the array to use for unraveling indices.
Returns the variance of the array elements, a measure of the spread of a
distribution. The variance is computed for the flattened array by
default, otherwise over the specified axis.
Parameters:
a (_Symbol) – _Symbol containing numbers whose variance is desired.
axis (None or int or tuple of ints, optional) – Axis or axes along which the variance is computed.
The default is to compute the variance of the flattened array.
If this is a tuple of ints, computation is performed over multiple axes,
instead of a single axis or all the axes as before.
dtype (data-type, optional) – Type to use in computing the variance.
For arrays of integer type,
When npx.is_np_default_dtype() returns False, default dtype is float32,
When npx.is_np_default_dtype() returns True, default dtype is float64;
For arrays of float types it is the same as the array type.
out (_Symbol, optional) – Dummy parameter to keep the consistency with the ndarray counterpart.
keepdims (bool, optional) – If this is set to True, the axes which are reduced are left in the result
as dimensions with size one. With this option, the result will broadcast correctly
against the input array.
If the default value is passed, then keepdims will not be passed through to the mean
method of sub-classes of _Symbol, however any non-default value will be. If the sub-class
method does not implement keepdims any exceptions will be raised.
Returns:
m – If out=None, returns a new array containing the variance values,
otherwise a reference to the output array is returned.
Return type:
_Symbol, see dtype parameter above
Notes
This function differs from the original numpy.var in
the following way(s):
only _Symbol is accepted as valid input, python iterables or scalar is not supported
default output data type for integer input is float32
Return the dot product of two vectors.
Note that vdot handles multidimensional arrays differently than dot:
it does not perform a matrix product, but flattens input arguments
to 1-D vectors first. Consequently, it should only be used for vectors.
Split an array into multiple sub-arrays vertically (row-wise).
vsplit is equivalent to split with axis=0 (default): the array is always split
along the first axis regardless of the array dimension.
Parameters:
ary (_Symbol) – Array to be divided into sub-arrays.
indices_or_sections (int or 1 - D Python tuple, list or set.) –
If indices_or_sections is an integer, N, the array will be divided into N equal arrays
along axis 0. If such a split is not possible, an error is raised.
If indices_or_sections is a 1-D array of sorted integers, the entries indicate where
along axis 0 the array is split. For example, [2,3] would result in
ary[:2]
ary[2:3]
ary[3:]
If an index exceeds the dimension of the array along axis 0, an error will be thrown.
This is equivalent to concatenation along the first axis after 1-D arrays
of shape (N,) have been reshaped to (1,N). Rebuilds arrays divided by
vsplit.
This function makes most sense for arrays with up to 3 dimensions. For
instance, for pixel-data with a height (first axis), width (second axis),
and r/g/b channels (third axis). The functions concatenate and stack
provide more general stacking and concatenation operations.
Parameters:
tup (sequence of _Symbol) – The arrays must have the same shape along all but the first axis.
1-D arrays must have the same length.
Returns:
stacked – The array formed by stacking the given arrays, will be at least 2-D.
Return a new array of given shape and type, filled with zeros.
This function currently only supports storing multi-dimensional data
in row-major (C-style).
Parameters:
shape (int or tuple of int) – The shape of the empty array.
dtype (str or numpy.dtype, optional) – An optional value type .
When npx.is_np_default_dtype() returns False, default dtype is float32;
When npx.is_np_default_dtype() returns True, default dtype is float64.
Note that this behavior is different from NumPy’s zeros function where float64
is the default value, here we can set ‘float32’ or ‘float64’ as your default dtype,
because float32 is considered as the default data type in deep learning.
order ({'C'}, optional, default: 'C') – How to store multi-dimensional data in memory, currently only row-major
(C-style) is supported.
ctx (Context, optional) – An optional device context (default is the current default context).
Returns:
out – Array of zeros with the given shape, dtype, and ctx.
Return an array of zeros with the same shape and type as a given array.
Parameters:
a (_Symbol) – The shape and data-type of a define these same attributes of
the returned array.
fill_value (scalar) – Fill value.
dtype (data-type, optional) – Overrides the data type of the result.
Temporarily do not support boolean type.
order ({'C'}, optional) – Whether to store multidimensional data in C- or Fortran-contiguous
(row- or column-wise) order in memory. Currently only supports C order.
ctx (to specify the device, e.g. the i-th GPU.)
out (ndarray or None, optional) – A location into which the result is stored.
If provided, it must have the same shape and dtype as input ndarray.
If not provided or None, a freshly-allocated array is returned.
Returns:
out – Array of zeros with the same shape and type as a.