numpy 数组序列- python

tnkciper  于 12个月前  发布在  Python
关注(0)|答案(1)|浏览(80)

我希望能够创建一个2x2数组的序列,当我尝试打印一个特定的索引时,它会打印一个2x2数组。

H = np.array(Ez_centre[0]*I_z)
for i in range(1,img.shape[0]):
    H = np.append(H,np.array(Ez_centre[i]*I_z),axis=1)

这只会创建一个大数组

igetnqfo

igetnqfo1#

正如Mark Reed提到的,提供一点上下文会很有帮助,但如果你只是想知道如何创建数组序列,一个答案可能是:

Create an array of N elements and then reshape it into the form you wanted.

np.arange(0,16)
#output =  array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15])

# reshape it 
output.reshape(4,2,2) # (number of batches, number of row , number of columns)

# array([[[ 0,  1],
        [ 2,  3]],

       [[ 4,  5],
        [ 6,  7]],

       [[ 8,  9],
        [10, 11]],

       [[12, 13],
        [14, 15]]])

相关问题