本文簡要介紹 python 語言中  numpy.promote_types  的用法。
用法:
numpy.promote_types(type1, type2)返回
type1和type2可以安全地轉換為的具有最小大小和最小標量類型的數據類型。返回的數據類型始終按本機字節順序排列。這個函數是對稱的,但很少有關聯。
- type1: dtype 或 dtype 說明符
 第一種數據類型。
- type2: dtype 或 dtype 說明符
 第二種數據類型。
- out: 類型
 提升的數據類型。
參數:
返回:
注意:
從 NumPy 1.9 開始,promote_types 函數現在在將整數或浮點數據類型作為一個參數、將字符串數據類型作為另一個參數時返回有效的字符串長度。以前,它總是返回輸入字符串 dtype,即使它不夠長,無法存儲轉換為字符串的最大整數/浮點值。
例子:
>>> np.promote_types('f4', 'f8') dtype('float64')>>> np.promote_types('i8', 'f4') dtype('float64')>>> np.promote_types('>i8', '<c8') dtype('complex128')>>> np.promote_types('i4', 'S8') dtype('S11')非關聯案例的示例:
>>> p = np.promote_types >>> p('S', p('i1', 'u1')) dtype('S6') >>> p(p('S', 'i1'), 'u1') dtype('S4')
相關用法
- Python numpy prod用法及代碼示例
 - Python numpy printoptions用法及代碼示例
 - Python numpy polyder用法及代碼示例
 - Python numpy polynomial.polyfit用法及代碼示例
 - Python numpy put_along_axis用法及代碼示例
 - Python numpy polyfit用法及代碼示例
 - Python numpy piecewise用法及代碼示例
 - Python numpy polynomial.polyline用法及代碼示例
 - Python numpy polynomial.polyadd用法及代碼示例
 - Python numpy polynomial.polyder用法及代碼示例
 - Python numpy pmt用法及代碼示例
 - Python numpy polyutils.as_series用法及代碼示例
 - Python numpy percentile用法及代碼示例
 - Python numpy polynomial.polydomain用法及代碼示例
 - Python numpy poly用法及代碼示例
 - Python numpy polynomial.polyint用法及代碼示例
 - Python numpy polysub用法及代碼示例
 - Python numpy polyutils.getdomain用法及代碼示例
 - Python numpy power用法及代碼示例
 - Python numpy polyutils.mapdomain用法及代碼示例
 - Python numpy putmask用法及代碼示例
 - Python numpy polyutils.mapparms用法及代碼示例
 - Python numpy polynomial.polydiv用法及代碼示例
 - Python numpy polynomial.polyvalfromroots用法及代碼示例
 - Python numpy polydiv用法及代碼示例
 
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.promote_types。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
