import numpy as np
test = np.load("I:/软件/mask.npy")
print(test)

如下图所示:

python 读取npy文件-LMLPHP

循环读取npy的行列

import numpy as np
masks = np.load("I:/软件/mask.npy")
height=masks.shape[0]
width=masks.shape[1]
cellcount = masks.shape[2]
for i in range(cellcount):
    mask = masks[:,:,i]
    for j in range(height*width):
        if mask.flat[j]>0:
           print(str(i) + " " + str(int(j/width))+ " " + str(int(j%width)))

python 读取npy文件-LMLPHP

 

07-10 21:07