<jupyter_start><jupyter_text>Mathematical objects==* *Scalars*: A scalar is just a single number* *Vectors*: A vector is an array of numbers* *Matrices*: A matrix is a 2-D array of numbers* *Tensors*: An array of numbers arranged on a regular grid with a variable number of axes<jupyter_code>import numpy as np
a = np.array([[1, 2], [2, 3], [3, 4]], dtype=np.float)
print('a:', a)
print('aT:', np.transpose(a))
# We can add matrices to each other, as long as they have the same shape
b = np.array([[-2, -1], [4, 5], [-4, -3]], dtype=np.float)
print('b:', b)
print('2 * a + b + 1:', 2 * a + b + 2)
# element-wise product or Hadamard product
print('a * b:', a * b)
# The matrix product of matrices A and B is a third matrix C.
# In order for this product to be defined, A must have the same number of columns as B has rows.
# If A is of shape m × n and B is of shape n × p, then C is of shape m × p.
c = np.array([[1, 2, 3, 4], [4, 5, 6, 8]], dtype=np.float)
print('c:', c)
print('a dot c:', np.dot(a, c))
# Matrix multiplication is not commutative (the condition AB = BA does not always hold),
# However, the dot product between two vectors is commutative: xTy = yTx.
d = np.array([[1, 2, 3, 4]], dtype=np.float)
e = np.array([[5, 6, 7, 8]], dtype=np.float)
print(np.dot(np.transpose(d), e))
print(np.dot(np.transpose(e), d))
# An identity matrix is a matrix that does not change any vector when we multiply that vector by that matrix.
print(np.identity(3, dtype=np.float))
# The matrix inverse of A is denoted as A−1, and it is defined as the matrix such that A−1A = In.
aI = np.matrix.getI(a)
print('aI:', aI)
print('aIa = In', np.matrix.dot(aI, a))
# usually measure the size of vectors using a function called a *norm*.
print('norm:', np.linalg.norm(a, ord=2))<jupyter_output>norm: 6.54675563644
{'fraction_non_alphanumeric': 0.15294771968854282, 'fraction_numerical': 0.027252502780867632, 'mean_word_length': 4.199421965317919, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '307910', 'license': 'MIT', 'n_tokens_mistral': 674, 'n_tokens_neox': 638, 'n_words': 280, 'path': 'Mathematics/Linear Algebra Basics.ipynb', 'repo_name': 'wuyuntao/deep-reinforcement-learning', 'size': '1798'}