sandeep-krishnamurthy commented on issue #11915: The behavior of 
np.zeros_like(x) if x is a NDArray is unexpected.
URL: 
https://github.com/apache/incubator-mxnet/issues/11915#issuecomment-408475474
 
 
   Hello @kohillyang 
   You are mixing Numpy.NDArray and MXNet.NDArray hence, seeing a different 
behavior.
   ### Numpy only
   ```
   import numpy as np
   >>> y = np.zeros(shape=(17,5))
   >>> print(y.shape)
   (17, 5)
   >>> print(np.zeros_like(y).shape)
   (17, 5)
   ```
   
   ### MXNet NDArray only
   
   ```
   >>> import mxnet.ndarray as nd
   >>> x = nd.zeros(shape=(17,5))
   >>> print(x.shape)
   (17, 5)
   >>> print(nd.zeros_like(x).shape)
   (17, 5)
   ```
   
   You passed np.zeros_like(MXNet NDarray) which treat it as an array object. 
(x in your example is mxnet ndarray that cannot be directly understood by Numpy.
   
   If you want to use MXNet NDArray inside numpy, here is the modified code for 
your example:
   
   ```
   import numpy as np
   import mxnet.ndarray as nd
   import mxnet as mx
   print(mx.__version__)
   x = nd.zeros(shape=(17,5))
   print(x.shape)
   print(np.zeros_like(x.asnumpy()).shape) # Converting X to numpy
   print(type(x))
   print(nd.zeros_like(x).shape)
   ```
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to