[Numpy-discussion] result shape from dot for 0d, 1d, 2d scalar

Skipper Seabold jsseabold@gmail....
Mon Nov 26 12:54:01 CST 2012


I discovered this because scipy.optimize.fmin_powell appears to squeeze 1d
argmin to 0d unlike the other optimizers, but that's a different story.

I would expect the 0d array to behave like the 1d array not the 2d as it
does below. Thoughts? Maybe too big of a pain to change this behavior if
indeed it's not desired, but I found it to be unexpected.

[255]: np.version.full_version # same on 1.5.1
[255]: '1.8.0.dev-8e0a542'

[262]: arr = np.random.random((25,1))

[~/]
[263]: np.dot(arr, np.array([1.])).shape
[263]: (25,)

[~/]
[264]: np.dot(arr, np.array([[1.]])).shape
[264]: (25, 1)

[~/]
[265]: np.dot(arr, np.array(1.)).shape
[265]: (25, 1)

[~/]
[271]: np.dot(arr.squeeze(), np.array(1.)).shape
[271]: (25,)

Huh? 0d arrays broadcast with dot?

[~]
[279]: arr = np.random.random((25,2))

[~/]
[280]: np.dot(arr.squeeze(), np.array(2.)).shape
[280]: (25, 2)

Skipper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20121126/7d9fba40/attachment.html 


More information about the NumPy-Discussion mailing list