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 3 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
stype: string, optional
The storage type of the empty array, such as 'row_sparse', 'csr', etc
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`)
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
8 changes: 4 additions & 4 deletions python/mxnet/ndarray/sparse_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def _zeros_sparse_ndarray(stype, shape, ctx=None, dtype=None, aux_types=None, **
----------
shape : int or tuple of int
The shape of the empty array
stype: string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for _zeros_sparse_ndarray stype is not optional.. Also could you reorder the arguments in doc so that stype comes before shape?

stype: string, optional
The storage type of the empty array, such as 'row_sparse', 'csr', etc
ctx : Context, optional
An optional device context (default is the current default context)
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