Manipulating Data with ndarray

In section Operations, it seems that the function f should be R^2 \to R rather than R \to R.

And in “In [11]”, the operations should be between x+y, x-y, etc. (it says x+x, x-x,…).

I get the following error when running x = nd.array(12). I installed mxnet as per the introduction and activated the conda environment. Please advise:

AttributeError: module ‘mxnet.ndarray’ has no attribute ‘arrange’

Disregard, I was using nd.arrange() and the command is nd.arange() with one ‘r’.

Thanks. Would you like to contribute to the book by fixing such issues?

I have followed all installation steps. I tried running the code in the Notebook by going to the folder “d2l-en”, then type “cmd” onto the address bar. When the command prompt window pops up I typed in “jupyter notebook”. The note books then appear and I open the notebook for this section. When I tried to run the code, the following error appears. Can someone help? Thanks

ModuleNotFoundError Traceback (most recent call last)
in ()
----> 1 import mxnet as mx
2 from mxnet import nd

ModuleNotFoundError: No module named ‘mxnet’

Have you install mxnet? Use “pip install mxnet”
Or “pip install mxnet-cuxx” replace xx with your cuda version and multiply by 10, ex- “pip install mxnet-cu100” for cuda version 10.0

It worked! Thanks for the fix

Hi there, I am stuck (yet again) on the Data Manipulation part (section 2.1).

I opened up a bank Jupyter Notebook to practice the code in the book. When I tried to import mxnet as mx and from mxnet import nd, I get the following message. Does any know what that means and how to fix it? Thanks

C:\ProgramData\Anaconda3\lib\site-packages\h5py_hl\base.py:19: DeprecationWarning: Using or importing the ABCs from ‘collections’ instead of from ‘collections.abc’ is deprecated, and in 3.8 it will stop working from collections import (Mapping, MutableMapping, KeysView, C:\ProgramData\Anaconda3\lib\site-packages\sklearn\externals\joblib\func_inspect.py:53: DeprecationWarning: invalid escape sequence &lt; ‘&lt;doctest (..rst)[(.)]&gt;’, source_file).groups() C:\ProgramData\Anaconda3\lib\site-packages\sklearn\externals\joblib_memory_helpers.py:10: DeprecationWarning: invalid escape sequence \s cookie_re = re.compile(“coding[:=]\s*([-\w.]+)”) C:\ProgramData\Anaconda3\lib\site-packages\socks.py:58: DeprecationWarning: Using or importing the ABCs from ‘collections’ instead of from ‘collections.abc’ is deprecated, and in 3.8 it will stop working from collections import Callable

Sorry I don’t know how to fix this. But I think mxnet installation is perfectly fine. It’s the anaconda that causing the error. Try removing anaconda if possible. And then uninstall and reinstall mxnet.

Is there any rule for broadcast mechanism, because I am unable to broadcast with tensors for Exercise - 2

This is what I have tried for tensors:

a = nd.random.normal(0, 1, shape=(1, 6, 2))
b = nd.random.normal(0, 1, shape=(6, 3, 1))
1 Like

To broadcast you need to have dimensions of size 1, or matching dimensions across your tensors

For example:

a = nd.random.normal(0, 1, shape=(1, 6, 2))
b = nd.random.normal(0, 1, shape=(6, 6, 1))


would work.

1 Like

I get it now thanks

Hi!
I solved exercise 4.1.7.3. as follows:

c += nd.dot(a, b.T)

Is this the most memory efficient way? Or can I improve nd.dot in some sense too?

if I do a x.norm(), it pops up the following error: “mxnet.numpy.ndarray object has no attribute norm”

I think you are calling .norm() after converting your x to numpy array using .asnumpy().
Below is the explanation.

import mxnet as mx
from mxnet import nd

print(mx.__version__) # will print 1.4.1

a = nd.array([0,1,2,3])
print(a.norm())
# will print
# [3.7416573]
# <NDArray 1 @cpu(0)>
a = a.asnumpy()
print(a)
print(a.norm()) # will give error as it's a numpy array, not MXNet NDArray


Or you should upgrade your mxnet to 1.4.1 using pip install --upgrade mxnet

you are still copy buffer to c and your operation mul(nd.dot).
my solution: only use one buffer is cloned from c.
mulOut =c.zeros_like()
nd.dot(a, b.T, out =mulOut)