gpt4 book ai didi

python - 计算图像小波时如何限制 numpy 数组的打印输出?

转载 作者:太空宇宙 更新时间:2023-11-03 18:55:54 24 4
gpt4 key购买 nike

此代码将图像小波中的无休止的数字列打印到控制台。我需要将输出限制为前 50 或 100 个项目。我试图实现这一点,但无法得到我需要的东西。

  def waveletdbbiorone(self):     #function for Wavelets computation
for filename in glob.iglob ('*.tif'):
imgwbior = mahotas.imread (filename) #read the image
arraywbior = numpy.array([imgwbior])#make an array
coefwbior = pywt.wavedec(arraywbior,'db1')#compute wavelet coefficients
arr = numpy.array([coefwbior])
np.set_printoptions(threshold=3)
# print arr
for elem in arr.flat:
print('{}\t'.format(elem)) #, end ='') #print out the result

最佳答案

尝试这样的事情:

for i in range(min(50, len(arr.flat))):
elem = arr.flat[i]
print('{}\t'.format(elem))

可以缩写为:

for i in range(min(50, len(arr.flat))):
print('{}\t'.format(arr.flat[i]))


编辑:

或者,按照Jaime的建议,更加Pythonic:

for elem in arr.flat[:50]:
print('{}\t'.format(elem))

关于python - 计算图像小波时如何限制 numpy 数组的打印输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17259705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com