Testing on Numpy
np.sum.__doc__
sum
Sum of array elements over a given axis.
Parameters
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| a | array_like | Elements to sum. |
| axis | None or int or tuple of ints, 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 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. 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-class' method does not implement keepdims any exceptions will be raised. |
| initial | scalar, optional | Starting value for the sum. See ~numpy.ufunc.reduce for details. |
| where | array_like of bool, optional | Elements to include in the sum. See ~numpy.ufunc.reduce for details. |
Returns
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| sum_along_axis | ndarray | An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, a scalar is returned. If an output array is specified, a reference to out is returned. |
See Also
ndarray.sum : Equivalent method.
add.reduce : Equivalent functionality of add.
cumsum : Cumulative sum of array elements.
trapz : Integration of array values using the composite trapezoidal rule.
mean, average
Examples
If the accumulator is too small, overflow occurs:
You can also start the sum with a value other than zero:
np.median.__doc__
median
Compute the median along the specified axis.
Returns the median of the array elements.
Parameters
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| a | array_like | 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 | 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 | If True, then allow use of memory of input array a for calculations. The input array will be modified by the call to median. This will save memory when you do not need to preserve the contents of the input array. Treat the input as undefined, but it will probably be fully or partially sorted. Default is False. If overwrite_input is True and a is not already an ndarray, an error will be raised. |
| 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
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| median | ndarray | A new array holding the result. If the input contains integers or floats smaller than float64, then the output data-type is np.float64. Otherwise, the data-type of the output is the same as that of the input. If out is specified, that array is returned instead. |
See Also
mean, percentile
Examples
np.argmax.__doc__
argmax
Returns the indices of the maximum values along an axis.
Parameters
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| a | array_like | Input array. |
| axis | int, optional | By default, the index is into the flattened array, otherwise along the specified axis. |
| out | array, optional | If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
Returns
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| index_array | ndarray of ints | Array of indices into the array. It has the same shape as a.shape with the dimension along axis removed. |
See Also
ndarray.argmax, argmin
amax : The maximum value along a given axis.
unravel_index : Convert a flat index into an index tuple.
take_along_axis : Apply np.expand_dims(index_array, axis)
from argmax to an array as if by calling max.
Examples
Indexes of the maximal elements of a N-dimensional array:
np.array.__doc__
array
array(object, dtype=None, *, copy=True, order='K', subok=False, ndmin=0)
Create an array.
Parameters
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| object | array_like | An array, any object exposing the array interface, an object whose array method returns an array, or any (nested) sequence. |
| dtype | data-type, optional | The desired data-type for the array. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence. |
| copy | bool, optional | If true (default), then the object is copied. Otherwise, a copy will only be made if array returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy any of the other requirements (dtype, order, etc.). |
| order | {'K', 'A', 'C', 'F'}, optional | Specify the memory layout of the array. If object is not an array, the newly created array will be in C order (row major) unless 'F' is specified, in which case it will be in Fortran order (column major). If object is an array the following holds. copy=False and a copy is made for other reasons, the result is the same as if copy=True, with some exceptions for A, see the Notes section. The default order is 'K'. |
| subok | bool, optional | If True, then sub-classes will be passed-through, otherwise the returned array will be forced to be a base-class array (default). |
| ndmin | int, optional | Specifies the minimum number of dimensions that the resulting array should have. Ones will be pre-pended to the shape as needed to meet this requirement. |
Returns
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| out | ndarray | An array object satisfying the specified requirements. |
See Also
empty_like : Return an empty array with shape and type of input. ones_like : Return an array of ones with shape and type of input. zeros_like : Return an array of zeros with shape and type of input. full_like : Return a new array with shape of input filled with value. empty : Return a new uninitialized array. ones : Return a new array setting values to one. zeros : Return a new array setting values to zero. full : Return a new array of given shape filled with value.
Examples
Upcasting:
More than one dimension:
Minimum dimensions 2:
Type provided:
Data-type consisting of more than one element:
Creating an array from sub-classes: