Hello, the docstring for compress in numpy give this help(numpy.compress) compress(condition, m, axis=None, out=None) compress(condition, x, axis=None) = those elements of x corresponding to those elements of condition that are "true". condition must be the same size as the given dimension of x. So (but perhaps I can misundertand the help due to my english) I don't undersand the following error, for me a and c array does have the same dimension and size. So someone can explain me the result please? Thanks, N. In [86]: a = numpy.arange(9) In [87]: a = numpy.arange(9).reshape(3,3) In [88]: c = numpy.ones(9).reshape(3,3) In [89]: numpy.compress(c,a) --------------------------------------------------------------------------- exceptions.ValueError Traceback (most recent call last) /home/gruel/tmp/Astro/FATBOY/<ipython console> /home/gruel/usr/lib/python2.4/site-packages/numpy/core/fromnumeric.py in compress(condition, m, axis, out) 353 except AttributeError: 354 return _wrapit(m, 'compress', condition, axis, out) --> 355 return compress(condition, axis, out) 356 357 def clip(m, m_min, m_max): ValueError: condition must be 1-d array ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
humufr@yahoo.fr wrote:
Hello,
the docstring for compress in numpy give this
help(numpy.compress)
compress(condition, m, axis=None, out=None) compress(condition, x, axis=None) = those elements of x corresponding to those elements of condition that are "true". condition must be the same size as the given dimension of x.
So (but perhaps I can misundertand the help due to my english) I don't undersand the following error, for me a and c array does have the same dimension and size. So someone can explain me the result please?
The docstring is a bit underspecified. The condition array *must* be a 1D array with the same size *as the given axis* of the other array (using the convention that axis=None implies operating over the flattened array). There's simply no valid interpretation of this, for example: compress(array([[1, 0, 0], [1, 1, 0]]), arange(6).reshape(2,3)) since numpy arrays cannot be "ragged". -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
participants (2)
-
humufr@yahoo.fr
-
Robert Kern