numpy数组生成矩阵

2024-04-23 18:20:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我想创建一个2x2矩阵

T = [[A, B],
     [C, D]]

其中每个元素A,B,C,D是一个数组。你知道吗

这可能吗?你知道吗

我想能够乘以这些矩阵,例如乘以两个矩阵T1和T2应该给我

T1*T2 = [[A1*A2, B1*B2],
         [C1*C2, D1*D2]]

仍然是相同大小的数组矩阵。有这样的乘法函数吗?你知道吗

而且,如果我用正规的标量矩阵T乘以T=[[a,b],[c,d]],其中a,b,c,d是标量数,那么乘法应该给我

t*T = [[a*A, b*B],
       [c*C, d*D]]

我该怎么做?你知道吗


Tags: a2元素a1矩阵数组b2b1d2
1条回答
网友
1楼 · 发布于 2024-04-23 18:20:41

想到在numpy中使用ndarray/数组。 http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html

比如:

import numpy as np
A = np.ndarray(shape=(2,2), dtype=float, order='F')
B = np.ndarray(shape=(2,2), dtype=float, order='F')
C = np.ndarray(shape=(2,2), dtype=float, order='F')
D = np.ndarray(shape=(2,2), dtype=float, order='F')

T = np.array([[A,B],[C,D]])

对于您的操作,您可能需要编写自己的函数。你知道吗

相关问题 更多 >