# [SciPy-user] problem ValueError: array is not broadcastable to correct shape - convert shape (x, ) to (x, 1)

Tan Tran fragon25@yahoo....
Sun Jan 11 21:58:53 CST 2009

```Hello,

I'm trying to convert a command like this in matlab to python numpy
mysel((col3 ==11 & (col4 ==16)) = y((col3 ==11 & (col4 ==16)), col0);

from numpy import *

y = array([ [ 0, 1,11,15, 4], \
[10,11,12,16,14], \
[20,21,11,17,24], \
[30,31,12,15,34], \
[40,41,11,16,44], \
[50,51,12,17,54], \
[60,61,11,15,64], \
[70,71,11,16,74], \
[80,81,11,17,84], \
[90,91,12,15,94]])

col3 = 2
col4 = 3
col0 = 0
mysel = zeros((10, 1),int)

mypick = y[:,col0][(y[:,col3] == 11) & (y[:,col4] == 16)]
print mypick
print mypick.shape

aa = mysel[(y[:,col3] == 11) & (y[:,col4] == 16)]
print aa
print aa.shape

mysel[(y[:,col3] == 11) & (y[:,col4] == 16)]  = mypick  <-- error here ValueError: array is not broadcastable to correct shape

I check the shape of two sides and see they are not adequate. The shape of mypick is (2,) and the shape of mysel[(y[:,col3] == 11) & (y[:,col4] == 16)] is (2,1).
I have a problem selecting elements in numpy. It's always return something with shape (x,). How can I reformat it to the shape that I want like (x,1)?
Is there other way to do the task?

Thanks,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20090111/9abf5b48/attachment.html
```