I am trying to convert each element of a numpy array into the array itself (say, to interpret the grayscale image as a color image). In other words:
>>> my_ar = numpy.array((0,5,10))
[0, 5, 10]
>>> transformed = my_fun(my_ar)
array([
[ 0, 0, 0],
[ 5, 10, 15],
[10, 20, 30]])
>>> transformed.shape
(3, 3)
I tried:
def my_fun_e(val):
return numpy.array((val, val*2, val*3))
my_fun = numpy.frompyfunc(my_fun_e, 1, 3)
but we get:
my_fun(my_ar)
(array([[0 0 0], [ 5 10 15], [10 20 30]], dtype=object), array([None, None, None], dtype=object), array([None, None, None], dtype=object))
and I tried:
my_fun = numpy.frompyfunc(my_fun_e, 1, 1)
but we get:
>>> my_fun(my_ar)
array([[0 0 0], [ 5 10 15], [10 20 30]], dtype=object)
This is close, but not entirely correct - I get an array of objects, not an array of ints.
Update 3! OK. I realized that my example was too simple in advance - I do not just want to replicate my data in the third dimension, I would like to convert it at the same time. Maybe this is clearer?