Table Of Contents
Table Of Contents

CSRNDArray.__getitem__

CSRNDArray.__getitem__(key)[source]

x.__getitem__(i) <=> x[i]

Returns a newly created NDArray based on the indexing key.

Parameters:key (int or slice) – Indexing key.

Examples

>>> indptr = np.array([0, 2, 3, 6])
>>> indices = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6])
>>> a = mx.nd.sparse.csr_matrix((data, indices, indptr), shape=(3, 3))
>>> a.asnumpy()
array([[ 1.,  0.,  2.],
       [ 0.,  0.,  3.],
       [ 4.,  5.,  6.]], dtype=float32)
>>> a[1:2].asnumpy()
array([[ 0.,  0.,  3.]], dtype=float32)
>>> a[1].asnumpy()
array([[ 0.,  0.,  3.]], dtype=float32)
>>> a[-1].asnumpy()
array([[ 4.,  5.,  6.]], dtype=float32)