idf / FaceReader

Face Recognition, CZ4041 Machine Learning, Spring 2015
http://git.io/vJnox
MIT License
5 stars 3 forks source link

Weird numpy behavior of += #14

Closed idf closed 9 years ago

idf commented 9 years ago
            Sw += np.dot((Xi - mean_class), (Xi - mean_class).T)
            Sb += Xi.shape[1] * np.dot((mean_class - mean_total), (mean_class - mean_total).T)
idf commented 9 years ago

One other issue with += to watch out for here is that because it is in-place it doesn't promote the dtype the way normal assignment does. So something like a=np.arange(10); a *= np.pi won't do what you probably want.

http://stackoverflow.com/questions/19417649/numpy-weird-behavior-with-plus-equal-with-slicing

idf commented 9 years ago

Before is float32, after is float64. The data type changed.