我有300个大小为50x50的矩阵,每个矩阵都是我功能的答案。为了做到这一点,我做了一个大小为50x50的零矩阵,称为J,然后把它放在一个循环中,每次我的函数的答案都保存到J.对于循环的每一轮,这些J矩阵必须放在我的一个元素中3d数组,我尝试这样做,但我不确定它是否正确。另外我不知道有没有更好的解决方案。感谢。
我的代码是:
import numpy as np
l=300
ts=50
#JointEntropy(X,Y,K) is my function
Jt=np.zeros(shape=(l,ts,ts))
J=np.zeros(shape=(ts,ts))
for i in range(1,l):
#this loop is used put each parts of my original data in Ti and Dc is my data
Ti=Dc[i-1][0:lw-1][0:ts-1]
for j in range(1,ts):
#this loop is used to each column of Ti as an array in X1 to be used in JointEntropy function
X1=Ti[j-1][0:lw-1]
for z in range(1,ts):
##this loop is used to each column of Ti as an array in X2 to be used in JointEntropy function
X2=Ti[z-1][0:lw-1]
J[j-1][z-1]=JointEntropy(X1,X2,k)
Jt[i-1][0:ts-1][0:ts-1]=J