摘要: 程序文件ex2_35.py import numpy as np a = np.array([[3, 1], [1, 2], [1, 1]]) b = np.array([9, 8, 6]) x = np.linalg.pinv(a) @ b print(np.round(x, 4)) 阅读全文
posted @ 2024-10-27 23:34 世梦 阅读(27) 评论(0) 推荐(0)
摘要: 程序文件ex2_34.py import numpy as np a = np.array([[3, 1], [1, 2]]) b = np.array([9, 8]) x1 = np.linalg.inv(a) @ b #第一种解法 上面语句中@表示矩阵乘法 x2 = np.linalg.solv 阅读全文
posted @ 2024-10-27 23:33 世梦 阅读(21) 评论(0) 推荐(0)
摘要: 程序文件ex2_33.py import numpy as np a = np.array([[0, 3, 4], [1, 6, 4]]) b = np.linalg.norm(a, axis=1) #求行向量2范数 c = np.linalg.norm(a, axis=0) #求列向量2范数 d 阅读全文
posted @ 2024-10-27 23:32 世梦 阅读(22) 评论(0) 推荐(0)
摘要: 程序文件ex2_31.py import numpy as np a = np.array([[0, 3, 4], [1, 6, 4]]) b = np.array([[1, 2, 3], [2, 1, 4]]) c = a / b #两个矩阵对应元素相除 d = np.array([2, 3, 2 阅读全文
posted @ 2024-10-27 23:30 世梦 阅读(15) 评论(0) 推荐(0)
摘要: import numpy as np a = np.array([[0, 3, 4], [1, 6, 4]]) b = a.sum() c1 = sum(a) c2 = np.sum(a, axis = 0) c3 = np.sum(a, axis = 1, keepdims = True) pri 阅读全文
posted @ 2024-10-27 23:30 世梦 阅读(18) 评论(0) 推荐(0)
摘要: import numpy as np a = np.arange(16).reshape(4, 4) b = np.vsplit(a, 2) print('行分割: \n', b[0], '\n', b[1]) c = np.hsplit(a, 4) print('列分割:: \n', c[0], 阅读全文
posted @ 2024-10-27 23:29 世梦 阅读(16) 评论(0) 推荐(0)
摘要: import numpy as np a = np.arange(16).reshape(4,4) b = np.floor(5 * np.random.random((2, 4))) c = np.ceil(6 * np.random.random((4, 2))) d = np.vstack([ 阅读全文
posted @ 2024-10-27 23:28 世梦 阅读(17) 评论(0) 推荐(0)
摘要: import numpy as np a = np.arange(16).reshape(4,4) b = a[1][2] c= a[1, 2] d = a[1:2, 2:3] x = np.array([0, 1, 2, 1]) print(a[x == 1]) 阅读全文
posted @ 2024-10-27 23:27 世梦 阅读(15) 评论(0) 推荐(0)
摘要: import numpy as np a = np.ones(4, dtype= int) b = np.ones((4,), dtype= int) c = np.ones((4,1)) d = np.zeros(4) e = np.empty(3) f = np.eye(3) g = np.ey 阅读全文
posted @ 2024-10-27 23:26 世梦 阅读(18) 评论(0) 推荐(0)
摘要: import numpy as np a1 = np.array([1,2,3,4]) a2 = a1.astype(float) a3 = np.array([1,2,3,4], dtype = float) print(a1.dtype); print(a2.dtype); print(a3.d 阅读全文
posted @ 2024-10-27 23:26 世梦 阅读(22) 评论(0) 推荐(0)