python - Numpy vectorize and atomic vectors -
i implement function works numpy.sum function on arrays on expects, e.g. np.sum([2,3],1) = [3,4] , np.sum([1,2],[3,4]) = [4,6].
yet trivial test implementation behaves somehow awkward:
import numpy np def triv(a, b): return a, b triv_vec = np.vectorize(fun, otypes = [np.int]) triv_vec([1,2],[3,4])
with result:
array([0, 0])
rather desired result:
array([[1,3], [2,4]])
any ideas, going on here? thx
you need otypes=[np.int,np.int]
:
triv_vec = np.vectorize(triv, otypes=[np.int,np.int]) print triv_vec([1,2],[3,4]) (array([1, 2]), array([3, 4]))
otypes : str or list of dtypes, optional
the output data type. must specified either string of typecode characters or list of data type specifiers. there should 1 data type specifier each output.
Comments
Post a Comment