當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python numpy sctype2char用法及代碼示例

本文簡要介紹 python 語言中 numpy.sctype2char 的用法。

用法:

numpy.sctype2char(sctype)

返回標量 dtype 的字符串表示形式。

參數

sctype 標量 dtype 或對象

如果是標量數據類型,則返回相應的字符串字符。如果是對象,sctype2char 嘗試推斷其標量類型,然後返回相應的字符串字符。

返回

typechar str

標量類型對應的字符串字符。

拋出

ValueError

如果 sctype 是無法推斷其類型的對象。

例子

>>> for sctype in [np.int32, np.double, np.complex_, np.string_, np.ndarray]:
...     print(np.sctype2char(sctype))
l # may vary
d
D
S
O
>>> x = np.array([1., 2-1.j])
>>> np.sctype2char(x)
'D'
>>> np.sctype2char(list)
'O'

相關用法


注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.sctype2char。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。