1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| import numpy as np
# Literal syntax: nested lists
A = np.array([[1, 2, 3],
[4, 5, 6]]) # 2×3 matrix
# Column-based construction
A = np.column_stack(([1, 4, 7],
[2, 5, 8],
[3, 6, 9]))
# Reshape: default fills rows first
A = np.arange(1, 10).reshape(3, 3)
# Column-first order, like Julia
A = np.arange(1, 10).reshape(3, 3, order="F")
# Constructors
np.zeros((3, 3))
np.ones((2, 4))
rng.random((3, 3))
rng.standard_normal((3, 3))
np.empty((3, 3), dtype=float) # uninitialized
np.eye(3) # identity
# Indexing
A[0, 1] # first row, second column
A[:, 0] # entire first column
A[0, :] # entire first row
# Transpose
A.T # ordinary transpose
A.conj().T # conjugate transpose
# Concatenation
np.vstack((A, A)) # append rows
np.hstack((A, A)) # append columns
|