2013-07-01 4 views
0

내 코드는 .tiff 이미지에서 후자를 계산합니다.NumPy 배열 요소를 인쇄 할 때 지수 (과학 표기)를 제거하는 방법은 무엇입니까?

2.84737313535e-05
1.25610416364e-09
1.25419253619e-09
1.57419718046e-18
6.69242940524e-12
: 나는처럼 보이는, 출력에 지수 (과학) 표기법을 제거해야 4.17512050223e-22

def humoments(self):    #function for HuMoments computation 
    for filename in glob.iglob ('*.tif'): 
     img = cv.LoadImageM(filename, cv.CV_LOAD_IMAGE_GRAYSCALE) 
     cancer = cv.GetHuMoments(cv.Moments(img)) 
     #arr = cancer 
     arr = numpy.array([cancer]) 
    with open('hu.csv', 'wb') as csvfile: 
     for elem in arr.flat[:50]: 
    #print('{}\t'.format(elem)) #this code puts the result to console 
     writer = csv.writer(csvfile, delimiter=' ', quotechar='|',  quoting=csv.QUOTE_MINIMAL) 
     writer.writerow([('{}\t'.format(elem))]) 

나에게

답변

1

변경을 도와 주셔서 감사합니다

writer.writerow([('{}\t'.format(elem))]) 

writer.writerow([('{0:.10f}\t'.format(elem))]) 

Here

에 파이썬에서 서식 문자열의 설명을 찾을 수 있습니다. 대신 파일을 만들 CSV를 사용

1

, 당신은 np.savetxt를 호출 할 수 있습니다

>>> import numpy as np 
>>> arr = np.array([2.84e-05, 6.69e-12]) 
>>> np.savetxt('/tmp/out', arr, fmt='%.14f') 

가 편곡 사용의 처음 50 개 요소를 작성하는 귀하의 경우 그래서

0.00002840000000 
0.00000000000669 

를 생성합니다

np.savetxt('hu.csv', arr.flat[:50], fmt='%.14f') 

대신

with open('hu.csv', 'wb') as csvfile: 
    for elem in arr.flat[:50]: 
#print('{}\t'.format(elem)) #this code puts the result to console 
    writer = csv.writer(csvfile, delimiter=' ', quotechar='|',  quoting=csv.QUOTE_MINIMAL) 
    writer.writerow([('{}\t'.format(elem))]) 

참고 : 원래 코드와 달리 np.savetxt은 각 줄의 끝에 탭을 넣지 않습니다. 그런데 왜 그걸 원하니?

관련 문제