2-dimensional numpy Flashcards
Cast a list to an array
A = np.array(a) A array([[11, 12, 13], [21, 22, 23], [31, 32, 33]])
ndim
obtain the number of axes or dimensions referred to as the rank.
a.ndim
2
shape
returns a tuple corresponding to the size or number of each dimension.
A.shape
(3, 3)
go down vertical first and horizontal second
Or total number of nested list first, the number of elements in each nested list second
size
The total number of elements in the array
A.size
9
Obtain elements
A[0:2, 2]
array([13, 23])
you first go down the vertical axis along 0:2 before you go across along 2
Matrix multiplcation using *
Multiplication of two arrays corresponds to an element-wise product or Hadamard product. Consider matrix X and Y. The Hadamard product corresponds to multiplying each of the elements in the same position, i.e. multiplying elements contained in the same color boxes together. The result is a new matrix that is the same size as matrix Y or X, as shown in the following figure.
get transorse
C.T
array([[1, 2, 3],
[1, 2, 3]])