mindspore.numpy

Numpy-like interfaces in mindspore.

Examples

>>> import mindspore.numpy as np

Note

  • array_ops.py defines all the array operation interfaces.

  • array_creations.py defines all the array generation interfaces.

  • math_ops.py defines all the math operations on tensors.

  • logic_ops.py defines all the logical operations on tensors.

  • dtypes.py defines all the mindspore.numpy dtypes (mainly redirected from mindspore)

Array Generation

API Name

Description

Supported Platforms

mindspore.numpy.arange

Returns evenly spaced values within a given interval.

Ascend GPU CPU

mindspore.numpy.array

Creates a tensor.

Ascend GPU CPU

mindspore.numpy.asarray

Converts the input to tensor.

Ascend GPU CPU

mindspore.numpy.asfarray

Similar to asarray, converts the input to a float tensor.

Ascend GPU CPU

mindspore.numpy.bartlett

mindspore.numpy.blackman

mindspore.numpy.copy

Returns a tensor copy of the given object.

Ascend GPU CPU

mindspore.numpy.diag

Extracts a diagonal or construct a diagonal array.

Ascend GPU CPU

mindspore.numpy.diag_indices

Returns the indices to access the main diagonal of an array.

Ascend GPU CPU

mindspore.numpy.diagflat

Creates a two-dimensional array with the flattened input as a diagonal.

Ascend GPU CPU

mindspore.numpy.diagonal

Returns specified diagonals.

Ascend GPU CPU

mindspore.numpy.empty

Returns a new array of given shape and type, without initializing entries.

Ascend GPU CPU

mindspore.numpy.empty_like

Returns a new array with the same shape and type as a given array.

Ascend GPU CPU

mindspore.numpy.eye

Returns a 2-D tensor with ones on the diagnoal and zeros elsewhere.

Ascend GPU CPU

mindspore.numpy.full

Returns a new tensor of given shape and type, filled with fill_value.

Ascend GPU CPU

mindspore.numpy.full_like

Returns a full array with the same shape and type as a given array.

Ascend GPU CPU

mindspore.numpy.geomspace

Returns numbers spaced evenly on a log scale (a geometric progression).

Ascend GPU CPU

mindspore.numpy.hamming

mindspore.numpy.hanning

mindspore.numpy.histogram_bin_edges

mindspore.numpy.identity

Returns the identity tensor.

Ascend GPU CPU

mindspore.numpy.indices

Returns an array representing the indices of a grid.

Ascend GPU CPU

mindspore.numpy.ix_

Constructs an open mesh from multiple sequences.

Ascend GPU CPU

mindspore.numpy.linspace

Returns evenly spaced values within a given interval.

Ascend GPU CPU

mindspore.numpy.logspace

Returns numbers spaced evenly on a log scale.

Ascend GPU CPU

mindspore.numpy.meshgrid

Returns coordinate matrices from coordinate vectors.

Ascend GPU CPU

mindspore.numpy.mgrid

mgrid is an nd_grid instance with sparse=False.

Ascend GPU CPU

mindspore.numpy.ogrid

ogrid is an nd_grid instance with sparse=True.

Ascend GPU CPU

mindspore.numpy.ones

Returns a new tensor of given shape and type, filled with ones.

Ascend GPU CPU

mindspore.numpy.ones_like

Returns an array of ones with the same shape and type as a given array.

Ascend GPU CPU

mindspore.numpy.pad

mindspore.numpy.trace

Returns the sum along diagonals of the array.

Ascend GPU CPU

mindspore.numpy.tri

Returns a tensor with ones at and below the given diagonal and zeros elsewhere.

Ascend GPU CPU

mindspore.numpy.tril

Returns a lower triangle of a tensor.

Ascend GPU CPU

mindspore.numpy.tril_indices

mindspore.numpy.tril_indices_from

mindspore.numpy.triu

Returns an upper triangle of a tensor.

Ascend GPU CPU

mindspore.numpy.triu_indices

mindspore.numpy.triu_indices_from

mindspore.numpy.vander

Generates a Vandermonde matrix.

Ascend GPU CPU

mindspore.numpy.zeros

Returns a new tensor of given shape and type, filled with zeros.

Ascend GPU CPU

mindspore.numpy.zeros_like

Returns an array of zeros with the same shape and type as a given array.

Ascend GPU CPU

Array Operation

API Name

Description

Supported Platforms

mindspore.numpy.append

Appends values to the end of a tensor.

Ascend GPU CPU

mindspore.numpy.apply_along_axis

mindspore.numpy.apply_over_axes

mindspore.numpy.array_split

Splits a tensor into multiple sub-tensors.

Ascend GPU CPU

mindspore.numpy.array_str

mindspore.numpy.atleast_1d

Converts inputs to arrays with at least one dimension.

Ascend GPU CPU

mindspore.numpy.atleast_2d

Reshapes inputs as arrays with at least two dimensions.

Ascend GPU CPU

mindspore.numpy.atleast_3d

Reshapes inputs as arrays with at least three dimensions.

Ascend GPU CPU

mindspore.numpy.broadcast_arrays

Broadcasts any number of arrays against each other.

Ascend GPU CPU

mindspore.numpy.broadcast_to

Broadcasts an array to a new shape.

Ascend GPU CPU

mindspore.numpy.choose

mindspore.numpy.column_stack

Stacks 1-D tensors as columns into a 2-D tensor.

Ascend GPU CPU

mindspore.numpy.concatenate

Joins a sequence of tensors along an existing axis.

Ascend GPU CPU

mindspore.numpy.dsplit

Splits a tensor into multiple sub-tensors along the 3rd axis (depth).

Ascend GPU CPU

mindspore.numpy.dstack

Stacks tensors in sequence depth wise (along the third axis).

Ascend GPU CPU

mindspore.numpy.expand_dims

Expands the shape of a tensor.

Ascend GPU CPU

mindspore.numpy.flip

Reverses the order of elements in an array along the given axis.

GPU

mindspore.numpy.fliplr

Flips the entries in each row in the left/right direction.

GPU

mindspore.numpy.flipud

Flips the entries in each column in the up/down direction.

GPU

mindspore.numpy.hsplit

Splits a tensor into multiple sub-tensors horizontally (column-wise).

Ascend GPU CPU

mindspore.numpy.hstack

Stacks tensors in sequence horizontally.

Ascend GPU CPU

mindspore.numpy.moveaxis

Moves axes of an array to new positions.

Ascend GPU CPU

mindspore.numpy.piecewise

mindspore.numpy.ravel

Returns a contiguous flattened tensor.

Ascend GPU CPU

mindspore.numpy.repeat

Repeats elements of an array.

Ascend GPU CPU

mindspore.numpy.reshape

Reshapes a tensor without changing its data.

Ascend GPU CPU

mindspore.numpy.roll

Rolls a tensor along given axes.

Ascend GPU CPU

mindspore.numpy.rollaxis

Rolls the specified axis backwards, until it lies in the given position.

Ascend GPU CPU

mindspore.numpy.rot90

Rotates a tensor by 90 degrees in the plane specified by axes.

GPU

mindspore.numpy.select

Returns an array drawn from elements in choicelist, depending on conditions.

Ascend GPU CPU

mindspore.numpy.size

mindspore.numpy.split

Splits a tensor into multiple sub-tensors along the given axis.

Ascend GPU CPU

mindspore.numpy.squeeze

Removes single-dimensional entries from the shape of an tensor.

Ascend GPU CPU

mindspore.numpy.stack

Joins a sequence of arrays along a new axis.

Ascend GPU CPU

mindspore.numpy.swapaxes

Interchanges two axes of a tensor.

Ascend GPU CPU

mindspore.numpy.take

Takes elements from an array along an axis.

Ascend GPU CPU

mindspore.numpy.take_along_axis

Takes values from the input array by matching 1d index and data slices.

Ascend GPU CPU

mindspore.numpy.tile

Constructs an array by repeating a the number of times given by reps.

Ascend GPU CPU

mindspore.numpy.transpose

Reverses or permutes the axes of a tensor; returns the modified tensor.

Ascend GPU CPU

mindspore.numpy.unique

Finds the unique elements of a tensor.

Ascend GPU CPU

mindspore.numpy.unravel_index

mindspore.numpy.vsplit

Splits a tensor into multiple sub-tensors vertically (row-wise).

Ascend GPU CPU

mindspore.numpy.vstack

Stacks tensors in sequence vertically.

Ascend GPU CPU

mindspore.numpy.where

Returns elements chosen from x or y depending on condition.

Ascend GPU CPU

Logic

API Name

Description

Supported Platforms

mindspore.numpy.array_equal

mindspore.numpy.array_equiv

mindspore.numpy.equal

Returns the truth value of (x1 == x2) element-wise.

Ascend GPU CPU

mindspore.numpy.greater

Returns the truth value of (x1 > x2) element-wise.

Ascend GPU CPU

mindspore.numpy.greater_equal

Returns the truth value of (x1 >= x2) element-wise.

Ascend GPU CPU

mindspore.numpy.in1d

Tests whether each element of a 1-D array is also present in a second array.

Ascend GPU CPU

mindspore.numpy.isclose

Returns a boolean tensor where two tensors are element-wise equal within a tolerance.

GPU CPU

mindspore.numpy.isfinite

Tests element-wise for finiteness (not infinity or not Not a Number).

Ascend GPU CPU

mindspore.numpy.isin

Calculates element in test_elements, broadcasting over element only.

Ascend GPU CPU

mindspore.numpy.isinf

Tests element-wise for positive or negative infinity.

GPU CPU

mindspore.numpy.isnan

Tests element-wise for NaN and return result as a boolean array.

GPU CPU

mindspore.numpy.isneginf

Tests element-wise for negative infinity, returns result as bool array.

GPU CPU

mindspore.numpy.isposinf

Tests element-wise for positive infinity, returns result as bool array.

GPU CPU

mindspore.numpy.isscalar

Returns True if the type of element is a scalar type.

Ascend GPU CPU

mindspore.numpy.less

Returns the truth value of (x1 < x2) element-wise.

Ascend GPU CPU

mindspore.numpy.less_equal

Returns the truth value of (x1 <= x2) element-wise.

Ascend GPU CPU

mindspore.numpy.logical_and

Computes the truth value of x1 AND x2 element-wise.

Ascend GPU CPU

mindspore.numpy.logical_not

Computes the truth value of NOT a element-wise.

Ascend GPU CPU

mindspore.numpy.logical_or

Computes the truth value of x1 OR x2 element-wise.

Ascend GPU CPU

mindspore.numpy.logical_xor

Computes the truth value of x1 XOR x2, element-wise.

Ascend GPU CPU

mindspore.numpy.not_equal

Returns (x1 != x2) element-wise.

Ascend GPU CPU

mindspore.numpy.signbit

mindspore.numpy.sometrue

Math

API Name

Description

Supported Platforms

mindspore.numpy.absolute

Calculates the absolute value element-wise.

Ascend GPU CPU

mindspore.numpy.add

Adds arguments element-wise.

Ascend GPU CPU

mindspore.numpy.amax

Returns the maximum of an array or maximum along an axis.

Ascend GPU CPU

mindspore.numpy.amin

Returns the minimum of an array or minimum along an axis.

Ascend GPU CPU

mindspore.numpy.arccos

Trigonometric inverse cosine, element-wise.

Ascend GPU CPU

mindspore.numpy.arccosh

Inverse hyperbolic cosine, element-wise.

Ascend GPU CPU

mindspore.numpy.arcsin

Inverse sine, element-wise.

Ascend GPU CPU

mindspore.numpy.arcsinh

Inverse hyperbolic sine element-wise.

Ascend GPU CPU

mindspore.numpy.arctan

Trigonometric inverse tangent, element-wise.

Ascend GPU CPU

mindspore.numpy.arctan2

Element-wise arc tangent of \(x1/x2\) choosing the quadrant correctly.

Ascend CPU

mindspore.numpy.arctanh

Inverse hyperbolic tangent element-wise.

Ascend CPU

mindspore.numpy.argmax

mindspore.numpy.argmin

mindspore.numpy.around

mindspore.numpy.average

Computes the weighted average along the specified axis.

Ascend GPU CPU

mindspore.numpy.bincount

mindspore.numpy.bitwise_and

mindspore.numpy.bitwise_or

mindspore.numpy.bitwise_xor

mindspore.numpy.cbrt

Returns the cube-root of a tensor, element-wise.

Ascend GPU CPU

mindspore.numpy.ceil

Returns the ceiling of the input, element-wise.

Ascend GPU CPU

mindspore.numpy.clip

Clips (limits) the values in an array.

Ascend GPU CPU

mindspore.numpy.convolve

Returns the discrete, linear convolution of two one-dimensional sequences.

GPU

mindspore.numpy.copysign

mindspore.numpy.corrcoef

mindspore.numpy.correlate

mindspore.numpy.cos

Cosine element-wise.

Ascend GPU CPU

mindspore.numpy.cosh

Hyperbolic cosine, element-wise.

Ascend CPU

mindspore.numpy.count_nonzero

Counts the number of non-zero values in the tensor x.

Ascend GPU CPU

mindspore.numpy.cov

Estimates a covariance matrix, given data and weights.

Ascend GPU CPU

mindspore.numpy.cross

Returns the cross product of two (arrays of) vectors.

Ascend GPU CPU

mindspore.numpy.cumprod

mindspore.numpy.cumsum

Returns the cumulative sum of the elements along a given axis.

Ascend GPU CPU

mindspore.numpy.deg2rad

Converts angles from degrees to radians.

Ascend GPU CPU

mindspore.numpy.diff

Calculates the n-th discrete difference along the given axis.

Ascend GPU CPU

mindspore.numpy.digitize

mindspore.numpy.divide

Returns a true division of the inputs, element-wise.

Ascend GPU CPU

mindspore.numpy.divmod

Returns element-wise quotient and remainder simultaneously.

Ascend GPU CPU

mindspore.numpy.dot

Returns the dot product of two arrays.

Ascend GPU CPU

mindspore.numpy.ediff1d

The differences between consecutive elements of a tensor.

Ascend GPU CPU

mindspore.numpy.exp

Calculates the exponential of all elements in the input array.

Ascend GPU CPU

mindspore.numpy.exp2

Calculates 2**p for all p in the input array.

Ascend GPU CPU

mindspore.numpy.expm1

Calculates exp(x) - 1 for all elements in the array.

Ascend GPU CPU

mindspore.numpy.fix

Rounds to nearest integer towards zero.

Ascend GPU CPU

mindspore.numpy.float_power

First array elements raised to powers from second array, element-wise.

Ascend GPU CPU

mindspore.numpy.floor

Returns the floor of the input, element-wise.

Ascend GPU CPU

mindspore.numpy.floor_divide

Returns the largest integer smaller or equal to the division of the inputs.

Ascend GPU CPU

mindspore.numpy.fmod

Returns the element-wise remainder of division.

Ascend GPU CPU

mindspore.numpy.gcd

Returns the greatest common divisor of |x1| and |x2|.

Ascend GPU CPU

mindspore.numpy.gradient

mindspore.numpy.heaviside

Computes the Heaviside step function.

Ascend GPU CPU

mindspore.numpy.histogram

mindspore.numpy.histogram2d

mindspore.numpy.histogramdd

mindspore.numpy.hypot

Given the “legs” of a right triangle, returns its hypotenuse.

Ascend GPU CPU

mindspore.numpy.inner

Returns the inner product of two tensors.

Ascend GPU CPU

mindspore.numpy.interp

mindspore.numpy.invert

mindspore.numpy.kron

Kronecker product of two arrays.

Ascend GPU CPU

mindspore.numpy.lcm

Returns the lowest common multiple of |x1| and |x2|.

Ascend GPU CPU

mindspore.numpy.log

Returns the natural logarithm, element-wise.

Ascend GPU CPU

mindspore.numpy.log10

Base-10 logarithm of x.

Ascend GPU CPU

mindspore.numpy.log1p

Returns the natural logarithm of one plus the input array, element-wise.

Ascend GPU CPU

mindspore.numpy.log2

Base-2 logarithm of x.

Ascend GPU CPU

mindspore.numpy.logaddexp

Logarithm of the sum of exponentiations of the inputs.

Ascend GPU CPU

mindspore.numpy.logaddexp2

Logarithm of the sum of exponentiations of the inputs in base of 2.

Ascend GPU CPU

mindspore.numpy.matmul

Returns the matrix product of two arrays.

Ascend GPU CPU

mindspore.numpy.matrix_power

mindspore.numpy.maximum

Returns the element-wise maximum of array elements.

Ascend GPU CPU

mindspore.numpy.mean

Computes the arithmetic mean along the specified axis.

Ascend GPU CPU

mindspore.numpy.minimum

Element-wise minimum of tensor elements.

Ascend GPU CPU

mindspore.numpy.multi_dot

mindspore.numpy.multiply

Multiplies arguments element-wise.

Ascend GPU CPU

mindspore.numpy.nancumsum

Return the cumulative sum of array elements over a given axis treating Not a Numbers (NaNs) as zero.

GPU CPU

mindspore.numpy.nanmax

mindspore.numpy.nanmean

Computes the arithmetic mean along the specified axis, ignoring NaNs.

GPU CPU

mindspore.numpy.nanmin

mindspore.numpy.nanstd

Computes the standard deviation along the specified axis, while ignoring NaNs.

GPU CPU

mindspore.numpy.nansum

Returns the sum of array elements over a given axis treating Not a Numbers (NaNs) as zero.

GPU CPU

mindspore.numpy.nanvar

Computes the variance along the specified axis, while ignoring NaNs.

GPU CPU

mindspore.numpy.negative

Numerical negative, element-wise.

Ascend GPU CPU

mindspore.numpy.norm

mindspore.numpy.outer

Computes the outer product of two vectors.

Ascend GPU CPU

mindspore.numpy.polyadd

mindspore.numpy.polyder

mindspore.numpy.polyint

mindspore.numpy.polymul

mindspore.numpy.polysub

mindspore.numpy.polyval

mindspore.numpy.positive

Numerical positive, element-wise.

Ascend GPU CPU

mindspore.numpy.power

First array elements raised to powers from second array, element-wise.

Ascend GPU CPU

mindspore.numpy.promote_types

Returns the data type with the smallest size and smallest scalar kind.

Ascend GPU CPU

mindspore.numpy.ptp

Range of values (maximum - minimum) along an axis.

Ascend GPU CPU

mindspore.numpy.rad2deg

Converts angles from radians to degrees.

Ascend GPU CPU

mindspore.numpy.radians

mindspore.numpy.ravel_multi_index

mindspore.numpy.reciprocal

Returns the reciprocal of the argument, element-wise.

Ascend GPU CPU

mindspore.numpy.remainder

Returns element-wise remainder of division.

Ascend GPU CPU

mindspore.numpy.result_type

mindspore.numpy.rint

mindspore.numpy.searchsorted

mindspore.numpy.sign

mindspore.numpy.sin

Trigonometric sine, element-wise.

Ascend GPU CPU

mindspore.numpy.sinh

Hyperbolic sine, element-wise.

Ascend CPU

mindspore.numpy.sqrt

Returns the non-negative square-root of an array, element-wise.

Ascend GPU CPU

mindspore.numpy.square

Returns the element-wise square of the input.

Ascend GPU CPU

mindspore.numpy.std

Computes the standard deviation along the specified axis.

Ascend GPU CPU

mindspore.numpy.subtract

Subtracts arguments, element-wise.

Ascend GPU CPU

mindspore.numpy.sum

mindspore.numpy.tan

Computes tangent element-wise.

Ascend CPU

mindspore.numpy.tanh

Computes hyperbolic tangent element-wise.

Ascend GPU CPU

mindspore.numpy.tensordot

Computes tensor dot product along specified axes.

Ascend GPU CPU

mindspore.numpy.trapz

Integrates along the given axis using the composite trapezoidal rule.

Ascend GPU CPU

mindspore.numpy.true_divide

Returns a true division of the inputs, element-wise.

Ascend GPU CPU

mindspore.numpy.trunc

Returns the truncated value of the input, element-wise.

Ascend GPU CPU

mindspore.numpy.unwrap

mindspore.numpy.var

Computes the variance along the specified axis.

Ascend GPU CPU