NumPy arrays, unlike Python lists, can contain only a single type, which (as far as I know) is set at creation time. Everything you put into the array gets converted to that type.
By default, the data type is assumed to be float
. To set another type, you can pass dtype
to the empty
function like this:
>>> arr = np.empty(9, dtype=int)
>>> arr[3] = 7
>>> arr[3]
7
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…