[Numpy-discussion] re turning a tuple of arrays with apply_along_axis

Pedro G uniccornio at hotmail.com
Sat May 7 11:40:55 EDT 2011


Hello,

I'm trying to use apply_along_axis with a function that returns 2 arrays,
but I always get different error messages.
For example, here is a test:

>>> from numpy import *
>>> def f(x):
...     a = array([1, 2, 3], dtype=float)
...     b = array([4, 5, 6], dtype=float)
...     return (a, b)
... 
>>> x = arange(60).reshape(5, 4, 3)
>>> x
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8],
        [ 9, 10, 11]],

       [[12, 13, 14],
        [15, 16, 17],
        [18, 19, 20],
        [21, 22, 23]],

       [[24, 25, 26],
        [27, 28, 29],
        [30, 31, 32],
        [33, 34, 35]],

       [[36, 37, 38],
        [39, 40, 41],
        [42, 43, 44],
        [45, 46, 47]],

       [[48, 49, 50],
        [51, 52, 53],
        [54, 55, 56],
        [57, 58, 59]]])
>>> f(1)
(array([ 1.,  2.,  3.]), array([ 4.,  5.,  6.]))
>>> f(array([1, 5, 9]))
(array([ 1.,  2.,  3.]), array([ 4.,  5.,  6.]))
>>> a, b = apply_along_axis(f, 0, x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/dist-packages/numpy/lib/shape_base.py",
line 106, in apply_along_axis
    outarr[tuple(i.tolist())] = res
ValueError: operands could not be broadcast together with shapes (2) (2,3)

I'm using python 3.2 and numpy 1.6.0 RC2.
Does anyone know an efficient way to do this?
Thanks

Pedro

-- 
View this message in context: http://old.nabble.com/returning-a-tuple-of-arrays-with-apply_along_axis-tp31566316p31566316.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.




More information about the NumPy-Discussion mailing list