Chapter2-Numpy Flashcards
Dot product
v transpose dot w
np.dot(v.T, w)
v.T.shape
get the shape (number of lines, number of columns) of v transpose
how to create a 2x2 Matrix A as 2D Numpy Array having the elements 1234?
A = np.array([[1,2],[3,4]])
create a vector vdont with shape(3,). Is it a mathematical vector?
vdont = np.array([1,1,1])
if x is a numpy array([[9]]) what is the output of print(x.item())
when that array contains exactly one item results on this element: 9
how to get the norm of a vector v?
np.linalg.norm(v)
matrix A with shape (3,2) and vector u with shape (2,1). Is it possible in Python to calculate A dot u? If yes, what is the shape of the result?
Yes because the number of columns of the matrix is equal the number of elements of the vector. The resulting vector will have shape (3,1)
What is the definition of the identity matrix? How to create one identity matrix I3 of grad 3?
definition: Matrix with all elements in the main diagonal set to 1. I3= np.identity(3)
what is the result np.dot(I3, w3) for all vectors w3 of shape (3,*)?
the vector w3 again
How is the inverse of a Matrix defined and when does the inverse of a matrix exist?
Mathematically, the inverse of a matrix A is denoted as A⁻¹, and it satisfies the equation:
A * A⁻¹ = A⁻¹ * A = I
follow criteria must be met:
- Square Matrix: The matrix must be a square matrix, which means it has the same number of rows and columns
- Full Rank: The matrix must be of full rank. A matrix is said to be of full rank if its rows and columns are linearly independent.
- Non-Singular (or Non-Degenerate): A matrix is invertible if and only if it is non-singular (or non-degenerate). A non-singular matrix is one that does not have a determinant of zero.
Given a system of equations in the form Ax = b, how to solve this system for x mathematicaly and in python?
math: x = A⁻¹ * b
python: x = np.dot(np.linalg.inv(A), b)
what is the diference between np.dot(A, B) and A * B?
A * B ist the element-wise multiplication
How to obtain the type of data stored in one array A?
A.dtype
how to create one column vector np array containing 10 equally spaced real number from 1 to 5?
np.linspace(1,5,10).reshape(10,1)
what do the function calls np.hstack([v,w]) and np.vstack([v,w]) do?
np.hstack([v,w]): attach the vector w as a column to the vector v creting a matrix
np.vstack([v,w]): attach the vector w as a ‘line’ to the vector v creting a matrix
what to get
array([[1, 2, 1, 2, 1, 2],
[3, 4, 3, 4, 3, 4]])
from
A = array([[1, 2],
[3, 4]])
np.tile(A, 3)
how to create one vector containing the natural numbers from 0 to 29?
np.arange(30)
how to get the first column of a matrix?
A[:, 0]
which elements o the lines and columns of A define the new matrix extracted by view1 = A[0:3, 0:3]
line: elements 0, 1 and 2
column: elements 0, 1 and 2
considering isBo to be array([ True, False, False, True, False, True, True]) what does data[isBo, :] will retrieve?
True for every one that I want and false for every row I don’t want to extract