import numpy as np
# a = np.array([1,2,3], dtype =np.int )
# a = np.array([[1,2,3],[3,4,5]] , dtype =float ) #設置精度中 設置64只能用np.float64
# a = np.zeros((3,5),dtype = np.int64)
# a = np.ones((3,4), dtype = np.int64)
# a = np.empty((3,4), dtype = np.int16)
# a = np.empty((3,4))
# a = np.full((3,4),2) #指定矩陣的全部值
# a = np.arange(10,20)
# a = np.arange(20)
# a = np.arange(20).reshape((5,4))
a = np.linspace(1, 5, 20).reshape((5, 4)) # 線段, 從1到10分段
print(a)
print(a.dtype)
a.fill(2) # 也可以直接用numpy 中的fill填充2
print(a)
# print(help(np.empty))
import numpy as np
a = np.array([[1, 2, 3], [5, 9, 8]])
print(a)
print("number of dim:", a.ndim) # 維度
print("shape:", a.shape)
print("size:", a.size)
import numpy as np
#
# #a = np.array([1,11,1])
# a = np.array([[1,11,1],[2,3,4]])
#
#
# b = np.arange(6).reshape(3,2)
#
#
# print(a<5) #判斷邏輯符直接輸出bool型
# print(a ==5)
#
# print(a)
# print(b)
#
# #c = a*b //數和數相乘 前提:同型矩陣
# #c = b**2
# #c =a - b
# #c = a -b
# #c = np.dot(a,b) //矩陣相乘 或者
# #c = a.dot(b)
# #c = np.cos(a) * 100
#
#
# print(c)
a = np.random.random((2, 4))
# print(np.max(a))
# print(np.sum(a))
# print(np.min(a))
print(np.max(a, axis=0)) # axis軸 為1 為行 0為列
print(np.sum(a, axis=1))
print(np.min(a, axis=1))
print(a)
import numpy as np
a = np.arange(15, 3, -1).reshape((3, 4))
print(np.argmax(a)) # 最大值索引 argument of a function
print(np.argmin(a)) # 最小值索引
# 平均值(也可以設置按行列求)
print(np.mean(a))
print(a.mean())
# 老版本
print(np.average(a))
# 不支持
# print(a.average)
# 中位數
print(np.median(a))
# 累加前面的值
print(np.cumsum(a)) # Cumulative sum 積累 和
# 輸出非0的行和列
print(np.nonzero(a))
# 兩數之差
print(np.diff(a))
# 每一行(列)排序
print(np.sort(a, axis=0))
# 轉置
print(np.transpose(a))
print(a.T.dot(a))
# 只留下范圍內的值
print(np.clip(a, 5, 9))
print(a)
更新中—