1

我有 Python 小波包的输出:

 [[[[[[255 255 255 255]
 [255 255 255 255]
 [255 255 255 255]
 ..., 
 [255 255 255 255]
 [255 255 255 255]
 [255 255 255 255]]

[[255 255 255 255]
 [255 255 255 255]
 [255 255 255 255]
 ..., 
 [255 255 255 255]
 [255 255 255 255]
 [255 255 255 255]]

[[255 255 255 255]
 [255 255 255 255]
 [255 255 255 255]
 ..., 
 [255 255 255 255]
 [255 255 255 255]
 [255 255 255 255]]

..., 
[[255 255 255 255]
 [255 255 255 255]
 [255 255 255 255]
 ..., 
 [255 255 255 255]
 [255 255 255 255]
 [255 255 255 255]]

[[255 255 255 255]
 [255 255 255 255]
 [255 255 255 255]
 ..., 
 [255 255 255 255]
 [255 255 255 255]
 [255 255 255 255]]

[[255 255 255 255]
 [255 255 255 255]
 [255 255 255 255]
 ..., 
 [255 255 255 255]
 [255 255 255 255]
 [255 255 255 255]]]]]]

我需要将它打印到终端并打印到.csv一行中的文件,其中包含制表符分隔且不带括号。

 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 for pywt module
         coefwbior = pywt.wavedec(arraywbior,'db1')#compute wavelet coefficients
         arr = numpy.array([coefwbior])
         np.set_printoptions(precision=3)
         print arr
4

1 回答 1

0

如果您真的只想要一行,请使用迭代器flat

蟒蛇 3

>>> for elem in arr.flat:
        print('{}\t'.format(elem), end='')  
    255.0   255.0   255.0   255.0   255.0 .........

蟒蛇2

>>> for elem in arr.flat:
        print '{}\t'.format(elem),
    255.0   255.0   255.0   255.0   255.0 .........
于 2013-06-06T09:41:48.170 回答