In [1]:
import numpy as np
In [2]:
a = [1, 2, 3]
In [3]:
a
Out[3]:
In [4]:
a_array = np.array(a)
In [5]:
a_array.shape
Out[5]:
In [6]:
# sum, min, max
a_array.sum(), a_array.min(), a_array.max()
Out[6]:
In [7]:
np.atleast_2d(a_array), np.atleast_2d(a_array).shape
Out[7]:
In [8]:
np.atleast_1d(a_array), np.atleast_1d(a_array).shape
Out[8]:
In [9]:
np.atleast_3d(a_array), np.atleast_3d(a_array).shape
Out[9]:
In [10]:
# flatten the array
np.atleast_2d(a_array).reshape(-1)
Out[10]:
In [11]:
np.atleast_2d(a_array).flatten()
Out[11]:
In [12]:
# identity matrix
id_3 = np.identity(3)
id_3
Out[12]:
In [13]:
# trace operator
id_3.trace() == 3
Out[13]:
In [14]:
# matrix * scalar
id_3 * 3
Out[14]:
In [15]:
# matrix + scalar
id_3 + 1
Out[15]:
In [16]:
# matrix / scalar
id_3 / 2
Out[16]:
In [17]:
# dot product id_3^T a_vector
np.dot(id_3, a_array)
Out[17]:
In [18]:
# random variables
np.random.randn(4)
Out[18]:
In [19]:
np.random.random((2, 3))
Out[19]:
In [20]:
# uniform distribution between [a, b]
np.random.randint(10)
Out[20]:
In [21]:
np.ones((3,3))
Out[21]:
In [22]:
np.ones(3)
Out[22]:
In [23]:
np.ones((3,3)).reshape(-1)
Out[23]:
In [24]:
# stacking
np.hstack((np.ones(3), np.ones(3)))
Out[24]:
In [25]:
np.vstack((np.ones(3), np.ones(3)))
Out[25]:
In [26]:
# similar to hstack
np.concatenate((np.ones(3), np.ones(3)))
Out[26]:
In [ ]: