[Numpy-discussion] newb question

paul taney paultaney at yahoo.com
Fri Sep 19 20:47:12 EDT 2008


Hi,

What am I doing wrong here?  The reshape doesn"t take.

% cat test1.py
import numpy as np

a = np.uint8([39, 39, 231,  239, 39, 231,  39, 39, 231, 
              39, 39, 231,  239, 39, 231,  39, 39, 231,
              39, 39, 231,  239, 39, 231,  39, 39, 231,
              39, 39, 231,  239, 39, 231,  39, 39, 231,])
a.reshape(3, 4, 3)
print "a = %r" % (a)
% 
% python test1.py
a = array([ 39, 39, 231, 239, 39, 231, 39, 39, 231,  
            39, 39, 231, 239, 39, 231, 39, 39, 231,  
            39, 39, 231, 239, 39, 231, 39, 39, 231,  
            39, 39, 231, 239, 39, 231, 39, 39, 231], dtype=uint8)

----

I am expecting:

a = array([[[39, 39, 231],  [239, 39, 231],  [39, 39, 231]], 
           [[39, 39, 231],  [239, 39, 231],  [39, 39, 231]],
           [[39, 39, 231],  [239, 39, 231],  [39, 39, 231]],
           [[39, 39, 231],  [239, 39, 231],  [39, 39, 231]]], \
dtype=np.uint8)


paul

----

def vanderWalt(a, f):
    """thanks Stefan"""
    RED, GRN, BLU = 0, 1, 2
    bluemask = (a[...,BLU] > f*a[...,GRN]) & \
               (a[...,BLU] > f*a[...,RED])
    return np.array(bluemask.nonzero()).swapaxes(0,1)





More information about the NumPy-Discussion mailing list