因此基本上我有一个数组subslope,由以下内容组成:
import numpy as np
import matplotlib.pyplot as plt
slp = 1501.66*(np.ones((1000,1000), dtype=np.float32))
vsub = 2000*(np.ones((1000,1000), dtype=np.float32))
slope = np.triu(slp)
slope2 = np.tril(vsub, k=-1)
subslope = slope + slope2
这是视觉表现:
您可以看到分隔数组两部分的对角线,上面部分的值为1501.66,对角线下面的值为2000。但是,当我更改维度时,列数明显大于行数,如下所示:
slp = 1501.66*(np.ones((1000,2000), dtype=np.float32))
vsub = 2000*(np.ones((1000,2000), dtype=np.float32))
我们得到以下结果:
我想要的是对角线从数组的上角到下角,如下所示:
我怎样才能做到这一点
要生成数组,请填充nR行和nC列:
您可以使用以下功能:
要测试它,请在较小的数字上运行:
结果是:
如果您希望这张桌子没有单独填充对角线, 首先决定是否填充对角线元素 使用“上限”或“下限”值,然后将所选值作为valDiag传递
可以使用^{} 创建布尔掩码:
相关问题 更多 >
编程相关推荐