import numpy as np
t1 = np.full(shape=(2, 3), fill_value=5)
print(t1)
t2 = np.empty(shape=(3, 4), dtype=np.int32)
print(t2)
t3 = np.random.random((2, 4))
print(t3)
b = np.eye(N=4, M=5, dtype=np.int32)
print(b)
print("*")
a = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]])
print(a.shape)
print(a.ndim)
print(a.itemsize)
print(type(a))
print("**")
print(a)
print("-")
print(a[:, 0])
print(a[:, 1])
print(a[:, 2])
print("--")
print(a[0, :])
print("---")
print(a[0:])
print("----")
print(a[1:])
print("-----")
print(a[2:])
输出:
[[5 5 5]
[5 5 5]]
[[ -20000000 -1 28 5177601]
[ 5570627 4259916 6226002 4259919]
[ 4522055 5505102 -1782054861 511]]
[[0.10498802 0.00428784 0.37916615 0.0039013 ]
[0.90971026 0.6740593 0.22788562 0.76183898]]
[[1 0 0 0 0]
[0 1 0 0 0]
[0 0 1 0 0]
[0 0 0 1 0]]
*
(3, 3)
2
4
**
[[0 1 2]
[3 4 5]
[6 7 8]]
-
[0 3 6]
[1 4 7]
[2 5 8]
--
[0 1 2]
---
[[0 1 2]
[3 4 5]
[6 7 8]]
----
[[3 4 5]
[6 7 8]]
-----
[[6 7 8]]