python 질문

조회수 551회
import tensorflow.keras
from PIL import Image
import numpy as np

np.set_printoptions(suppress=True)

model = tensorflow.keras.models.load_model('keras_model.h5')

data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
image = Image.open('skoda.jpg')

image = image.resize((224, 224))
image_array = np.asarray(image)

normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1

data[0] = normalized_image_array

prediction = model.predict(data)
print("Ford",prediction[0,0])
print("Fox",prediction[0,1])
print("Hundae",prediction[0,2])
print("Lexus",prediction[0,3])
print("Ferrari",prediction[0,4])
print("Chevrolet",prediction[0,5])
print("Nissan",prediction[0,6])
print("Skoda",prediction[0,7])
print(prediction)

실행시

 Ford 8.9526235e-05
Fox 0.00031412177
Hundae 2.5784022e-05
Lexus 1.4473101e-05
Ferrari 0.008922634
Chevrolet 3.905558e-05
Nissan 5.2737455e-06
Skoda 0.99058914
[[0.00008953 0.00031412 0.00002578 0.00001447 0.00892263 0.00003906
  0.00000527 0.99058914]]

로 출력이 되는데 소수점 부분부터 출력이 안되고 저렇게 출력이 되는데 어떻게 해야 수정이 가능할까요??

1 답변

  • 아래 예제로 답변 대신 합니다.

    In [1]: import numpy as np
    
    In [2]: nums = np.array([0.00008953, 0.00031412, 0.00002578, 0.00001447, 0.00892263, 0.00003906, 0.00000527, 0.99058914])
    
    In [3]: for i in nums: print(f"{i}")
    8.953e-05
    0.00031412
    2.578e-05
    1.447e-05
    0.00892263
    3.906e-05
    5.27e-06
    0.99058914
    
    In [4]: for i in nums: print(f"{i:.8f}")
    0.00008953
    0.00031412
    0.00002578
    0.00001447
    0.00892263
    0.00003906
    0.00000527
    0.99058914
    

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)