我想以格式化的方式打印numpy.timedelta64()值。直接法效果很好:打印numpy timedelta64與格式()
>>> import numpy as np
>>> print np.timedelta64(10,'m')
10 minutes
我的猜測來自於__str__
()方法
>>> np.timedelta64(10,'m').__str__()
'10 minutes'
但是,當我嘗試與格式()函數,我得到以下錯誤打印:
>>> print "my delta is : {delta}".format(delta=np.timedelta64(10,'m'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: don't know how to convert scalar number to long
我想了解「string」.format()函數的基本機制,以及爲什麼它在這種情況下不起作用。
你認爲我應該在某處提交錯誤報告嗎? – 2014-09-25 17:33:34
[我剛剛爲你做了。](https://github.com/numpy/numpy/issues/5121) – Veedrac 2014-09-25 17:33:45