numpy檔案描述了創建自定義復合型別的選項。
應該如何使用它們?
我可以想象一個實際的例子是一個復合時間格式,它可以用來統一 python、hdf5 和 numpy,例如:
custom_time = np.dtype( [ ('h', np.int8) , ('m', np.int8), ('s', np.float)] )
t = custom_time(23,59,59.99999)
(上面的行不起作用 - 我明白了TypeError: 'numpy.dtype[void]' object is not callable)
也許您使用過復合型別并且有一個想法?
uj5u.com熱心網友回復:
自定義型別旨在用于 Numpy 陣列,而不是作為獨立型別。這是一個例子:
# Declare the type
custom_time = np.dtype( [ ('h', np.int8) , ('m', np.int8), ('s', np.float64)] )
# Create an array with 2 items of custom_time
arr = np.array([(4, 8, 15.16), (23, 42, 0.815)], dtype=custom_time)
# Access the fields
print(arr['h']) # [4 23]
print(arr['s']) # [15.16 0.815]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/464611.html
上一篇:插入串列理解
