在 python 范围内创建 n 个矩阵
Create n matrice in a range with python
你好,我是 python 的新手,我需要创建 n 个矩阵,每个矩阵的内容都不同,我希望能够存储每个矩阵都有不同的名称 T1、T2、...。 .. Tn to return 他们,我期待的例子 1 谢谢你的帮助!
这是一种使用一些随机选择的变量(矩阵形状、矩阵数量)的方法:
import numpy as np
matrix_shape = (10, 10)
n = 10
matrix_dict = {f'T_{i}': np.ones(matrix_shape) * i for i in range(1, n)}
检查这段代码
def matrix(n):
mat={}
for i in range(1,n+1):
mat.update({f"T{i}":[i for j in range(n)]}) #== You can also insert a number in the ```range()``` for specific number of the digits
return mat
print(matrix(5))
你好,我是 python 的新手,我需要创建 n 个矩阵,每个矩阵的内容都不同,我希望能够存储每个矩阵都有不同的名称 T1、T2、...。 .. Tn to return 他们,我期待的例子 1 谢谢你的帮助!
这是一种使用一些随机选择的变量(矩阵形状、矩阵数量)的方法:
import numpy as np
matrix_shape = (10, 10)
n = 10
matrix_dict = {f'T_{i}': np.ones(matrix_shape) * i for i in range(1, n)}
检查这段代码
def matrix(n):
mat={}
for i in range(1,n+1):
mat.update({f"T{i}":[i for j in range(n)]}) #== You can also insert a number in the ```range()``` for specific number of the digits
return mat
print(matrix(5))