我發現與NumPy的一個ndarray以下令人費解的行爲和一個自定義的D型細胞,當數組賦值問題:NumPy的:使用自定義的D型
import numpy as np
# Make a custom dtype with a single triplet of floats (my actual dtype has other
# components, but this suffices to demonstrate the problem.
dt = np.dtype([('a', np.float64, 3)])
# Make a zero array with this dtype:
points = np.zeros((4, 4), dtype=dt)
# Try to edit an entry:
points[0][0]['a'] = np.array([1, 1, 1])
print points[0][0]['a']
現在,這回來爲含有不[1。如我所料,但是[1]。 0. 0],只在第一個座標上執行賦值。我可以通過座標明智地執行分配來解決這個問題,但這看起來沒有必要,因爲在這種情況下完全分配肯定應該是默認行爲。
想到這裏發生了什麼?
正是我在找的,謝謝。 –