mirror of
https://github.com/Visualize-ML/Book4_Power-of-Matrix.git
synced 2026-02-03 02:24:03 +08:00
42 lines
715 B
Python
42 lines
715 B
Python
|
|
###############
|
|
# Authored by Weisheng Jiang
|
|
# Book 4 | From Basic Arithmetic to Machine Learning
|
|
# Published and copyrighted by Tsinghua University Press
|
|
# Beijing, China, 2022
|
|
###############
|
|
|
|
# Bk4_Ch4_01.py
|
|
|
|
import numpy as np
|
|
|
|
# 2d matrix
|
|
A_matrix = np.matrix([[2,4],
|
|
[6,8]])
|
|
print(A_matrix.shape)
|
|
print(type(A_matrix))
|
|
|
|
# 1d array
|
|
A_1d = np.array([2,4])
|
|
print(A_1d.shape)
|
|
print(type(A_1d))
|
|
|
|
# 2d array
|
|
A_2d = np.array([[2,4],
|
|
[6,8]])
|
|
print(A_2d.shape)
|
|
print(type(A_2d))
|
|
|
|
# 3d array
|
|
A1 = [[2,4],
|
|
[6,8]]
|
|
|
|
A2 = [[1,3],
|
|
[5,7]]
|
|
|
|
A3 = [[1,0],
|
|
[0,1]]
|
|
A_3d = np.array([A1,A2,A3])
|
|
print(A_3d.shape)
|
|
print(type(A_3d))
|