Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Modify and Add documentation for mx.nd.zeros #7197

Merged
merged 4 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions python/mxnet/ndarray/ndarray_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,34 @@


def zeros(shape, ctx=None, dtype=None, stype=None, aux_types=None, **kwargs):
"""Return a new array of given shape and type, filled with zeros.

Parameters
----------
shape : int or tuple of int
The shape of the empty array
ctx : Context, optional
An optional device context (default is the current default context)
dtype : str or numpy.dtype, optional
An optional value type (default is `float32`)
stype: string, optional
The storage type of the empty array, such as 'row_sparse', 'csr', etc
aux_types: list of numpy.dtype, optional
An optional type for the aux data for SparseNDArray (default values depends
on the storage type)

Returns
-------
SparseNDArray
A created array
Examples
--------
>>> mx.nd.zeros((1,2), mx.cpu(), stype='csr')
<CSRNDArray 1x2 @cpu(0)>
>>> mx.nd.zeros((1,2), mx.cpu(), 'float16', stype='row_sparse').asnumpy()
array([[ 0., 0.]], dtype=float16)
"""

if stype is None:
return _zeros_ndarray(shape, ctx, dtype, **kwargs)
else:
Expand Down
10 changes: 5 additions & 5 deletions python/mxnet/ndarray/sparse_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,10 @@ def _zeros_sparse_ndarray(stype, shape, ctx=None, dtype=None, aux_types=None, **

Parameters
----------
shape : int or tuple of int
The shape of the empty array
stype: string
The storage type of the empty array, such as 'row_sparse', 'csr', etc
shape : int or tuple of int
The shape of the empty array
ctx : Context, optional
An optional device context (default is the current default context)
dtype : str or numpy.dtype, optional
Expand All @@ -613,9 +613,9 @@ def _zeros_sparse_ndarray(stype, shape, ctx=None, dtype=None, aux_types=None, **
A created array
Examples
--------
>>> mx.nd.zeros('csr', (1,2), mx.gpu(0))
<SparseNDArray 1x2 @gpu(0)>
>>> mx.nd.zeros('row_sparse', (1,2), mx.gpu(0), 'float16').asnumpy()
>>> mx.nd.zeros((1,2), mx.cpu(), stype='csr')
<CSRNDArray 1x2 @cpu(0)>
>>> mx.nd.zeros((1,2), mx.cpu(), 'float16', stype='row_sparse').asnumpy()
array([[ 0., 0.]], dtype=float16)
"""
if stype == 'default':
Expand Down