Table Of Contents
Table Of Contents

CSRNDArray

class mxnet.ndarray.sparse.CSRNDArray(handle, writable=True)[source]

A sparse representation of 2D NDArray in the Compressed Sparse Row format.

A CSRNDArray represents an NDArray as three separate arrays: data, indptr and indices. It uses the CSR representation where the column indices for row i are stored in indices[indptr[i]:indptr[i+1]] and their corresponding values are stored in data[indptr[i]:indptr[i+1]].

The column indices for a given row are expected to be sorted in ascending order. Duplicate column entries for the same row are not allowed.

Example

>>> a = mx.nd.array([[0, 1, 0], [2, 0, 0], [0, 0, 0], [0, 0, 3]])
>>> a = a.tostype('csr')
>>> a.data.asnumpy()
array([ 1.,  2.,  3.], dtype=float32)
>>> a.indices.asnumpy()
array([1, 0, 2])
>>> a.indptr.asnumpy()
array([0, 1, 2, 2, 3])

See also

csr_matrix
Several ways to construct a CSRNDArray

Array attributes

CSRNDArray.context Device context of the array.
CSRNDArray.data A deep copy NDArray of the data array of the CSRNDArray.
CSRNDArray.dtype Data-type of the array’s elements.
CSRNDArray.indices A deep copy NDArray of the indices array of the CSRNDArray.
CSRNDArray.indptr A deep copy NDArray of the indptr array of the CSRNDArray.
CSRNDArray.shape Tuple of array dimensions.
CSRNDArray.stype Storage-type of the array.

Array creation

CSRNDArray.zeros_like Convenience fluent method for zeros_like().

Manipulation

Array conversion

CSRNDArray.as_in_context Returns an array on the target device with the same value as this array.
CSRNDArray.asnumpy Return a dense numpy.ndarray object with value copied from this array
CSRNDArray.asscalar Returns a scalar whose value is copied from this array.
CSRNDArray.asscipy Returns a scipy.sparse.csr.csr_matrix object with value copied from this array
CSRNDArray.astype Returns a copy of the array after casting to a specified type.
CSRNDArray.copy Makes a copy of this NDArray, keeping the same context.
CSRNDArray.copyto Copies the value of this array to another array.
CSRNDArray.tostype Return a copy of the array with chosen storage type.

Array inspection

CSRNDArray.check_format Check whether the NDArray format is valid.

Array reduction

CSRNDArray.mean Convenience fluent method for mean().
CSRNDArray.norm Convenience fluent method for norm().
CSRNDArray.sum Convenience fluent method for sum().

Indexing

CSRNDArray.__getitem__ x.__getitem__(i) <=> x[i]
CSRNDArray.__setitem__ x.__setitem__(i, y) <=> x[i]=y
CSRNDArray.slice Convenience fluent method for slice().

Joining arrays

concat Joins input arrays along a given axis.

Lazy evaluation

CSRNDArray.wait_to_read Waits until all previous write operations on the current array are finished.

Math

Array rounding

CSRNDArray.ceil Convenience fluent method for ceil().
CSRNDArray.fix Convenience fluent method for fix().
CSRNDArray.floor Convenience fluent method for floor().
CSRNDArray.round Convenience fluent method for round().
CSRNDArray.rint Convenience fluent method for rint().
CSRNDArray.trunc Convenience fluent method for trunc().

Trigonometric functions

CSRNDArray.arcsin Convenience fluent method for arcsin().
CSRNDArray.arctan Convenience fluent method for arctan().
CSRNDArray.degrees Convenience fluent method for degrees().
CSRNDArray.radians Convenience fluent method for radians().
CSRNDArray.sin Convenience fluent method for sin().
CSRNDArray.tan Convenience fluent method for tan().

Hyperbolic functions

CSRNDArray.arcsinh Convenience fluent method for arcsinh().
CSRNDArray.arctanh Convenience fluent method for arctanh().
CSRNDArray.sinh Convenience fluent method for sinh().
CSRNDArray.tanh Convenience fluent method for tanh().

Exponents and logarithms

CSRNDArray.expm1 Convenience fluent method for expm1().
CSRNDArray.log1p Convenience fluent method for log1p().

Powers

CSRNDArray.sqrt Convenience fluent method for sqrt().
CSRNDArray.square Convenience fluent method for square().

Miscellaneous

CSRNDArray.abs Convenience fluent method for abs().
CSRNDArray.clip Convenience fluent method for clip().
CSRNDArray.sign Convenience fluent method for sign().