0
我希望收入和支出的輸出爲全部美元。我已將打印選項設置爲int,但我仍然收到小數點,並且無法在文檔中看到如何將整個金額顯示爲美元。整數美元的numpy set_printoptions格式
revenue = [14574.49, 7606.46, 8611.41, 9175.41, 8058.65, 8105.44, 11496.28, 9766.09, 10305.32, 14379.96, 10713.97, 15433.50]
expenses = [12051.82, 5695.07, 12319.20, 12089.72, 8658.57, 840.20, 3285.73, 5821.12, 6976.93, 16618.61, 10054.37, 3803.96]
這是我的代碼,但我無法格式化爲全部美元。
import numpy as np
np.set_printoptions(precision=0, formatter={'int_kind':':d'})
revenue_arr = np.array(revenue)
expense_arr = np.array(expense)
profits = revenue_arr - expense_arr
print(profits)
結果
[ 10771. 3802. 4807. 5371. 4255. 4301. 7692. 5962. 6501.
10576. 6910. 11630.]
所需的結果
[ $10771 $3802 $4807 $5371 $4255 $4301 $7692 $5962 $6501
$10576 $6910 $11630]