From: Keith G. <kwg...@gm...> - 2006-06-28 17:26:04
|
>> x = asmatrix(rand(3,2)) >> y = asmatrix(rand(3,1)) >> y matrix([[ 0.77952062], [ 0.97110465], [ 0.77450218]]) >> idx = where(y > 0.5)[0] >> idx matrix([[0, 1, 2]]) >> x[idx,:] matrix([[ 0.24837887, 0.52988253], [ 0.28661085, 0.43053076], [ 0.05360893, 0.22668509]]) So far everything works as it should. Now the problem: >> y[idx,:] --------------------------------------------------------------------------- exceptions.ValueError Traceback (most recent call last) /usr/local/lib/python2.4/site-packages/numpy/core/defmatrix.py in __getitem__(self, index) 120 121 def __getitem__(self, index): --> 122 out = N.ndarray.__getitem__(self, index) 123 # Need to swap if slice is on first index 124 retscal = False /usr/local/lib/python2.4/site-packages/numpy/core/defmatrix.py in __array_finalize__(self, obj) 116 self.shape = (1,1) 117 elif ndim == 1: --> 118 self.shape = (1,self.shape[0]) 119 return 120 ValueError: total size of new array must be unchanged And, on a related note, shouldn't this be a column vector? >> x[idx,0] matrix([[ 0.24837887, 0.28661085, 0.05360893]]) |