In [1]:
import mxnet as mx
In [2]:
# Scalars are initialized as NDArrays with a single value
x = mx.nd.array([3.0])
y = mx.nd.array([2.0])
In [3]:
# Addition
x + y
Out[3]:
In [4]:
# Multiplication
x * y
Out[4]:
In [5]:
# Division
x / y
Out[5]:
In [6]:
# Power
mx.nd.power(x, y)
Out[6]:
In [7]:
# MXNet scalar as Numpy floating point value
x.asscalar()
Out[7]:
In [8]:
type(x.asscalar())
Out[8]:
In [9]:
u = mx.nd.arange(4)
u
Out[9]:
In [10]:
u[3]
Out[10]:
In [11]:
len(u)
Out[11]:
In [12]:
u.shape
Out[12]:
In [13]:
A = mx.nd.zeros(shape = [5, 4])
A
Out[13]:
In [14]:
x = mx.nd.arange(start=0, stop=20)
x
Out[14]:
In [15]:
A = x.reshape(shape=[5, 4])
A
Out[15]:
In [16]:
# Specific value
A[2, 3]
Out[16]:
In [17]:
# Specific row
A[0, :]
Out[17]:
In [18]:
# Specific column
A[:, 1]
Out[18]:
In [19]:
# Transport
A.T
Out[19]:
In [20]:
X = mx.nd.arange(start=0, stop=24).reshape(shape=[2, 3, 4])
X
Out[20]:
In [21]:
u = mx.nd.array([1, 2, 3, 7])
In [22]:
v = mx.nd.ones_like(u) * 2
v
Out[22]:
In [23]:
u + v
Out[23]:
In [24]:
u - v
Out[24]:
In [25]:
u * v
Out[25]:
In [26]:
u / v
Out[26]:
In [27]:
A
Out[27]:
In [28]:
B = mx.nd.ones_like(A) * 3
B
Out[28]:
In [29]:
A * B
Out[29]:
In [30]:
A + B
Out[30]:
In [31]:
A
Out[31]:
In [32]:
mx.nd.sum(A)
Out[32]:
In [33]:
mx.nd.mean(A)
Out[33]:
In [34]:
u
Out[34]:
In [35]:
v
Out[35]:
In [36]:
mx.nd.dot(u, v)
Out[36]:
In [37]:
A
Out[37]:
In [38]:
u
Out[38]:
In [39]:
mx.nd.dot(A, u)
Out[39]:
In [40]:
A = mx.nd.ones(shape=(3, 4))
B = mx.nd.ones(shape=(4, 5))
C = mx.nd.dot(A, B)
C
Out[40]:
In [41]:
C.shape
Out[41]:
In [42]:
u
Out[42]:
In [43]:
mx.nd.norm(u)
Out[43]:
In [44]:
# L1 norm can be calculated as follows l1 = sum(abs(u))
mx.nd.sum(mx.nd.abs(u))
Out[44]: