I have an array of numpy objects containing several index lists:
>>> idxLsts = np.array([[1], [0, 2]], dtype=object)
I define a vector function to add a value to each list:
>>> idx = 99 >>> f = np.vectorize(lambda idxLst: idxLst.append(idx))
I am calling a function. I'm not interested in the return value, just a side effect.
>>> f(idxLsts) array([None, None], dtype=object)
Index 99 was added twice to the first list. What for? I'm at a dead end.
>>> idxLsts array([[1, 99, 99], [0, 2, 99]], dtype=object)
With other idxLsts values ββthis does not happen:
>>> idxLsts = np.array([[1, 2], [0, 2, 4]], dtype=object) >>> f(idxLsts) array([None, None], dtype=object) >>> idxLsts array([[1, 2, 99], [0, 2, 4, 99]], dtype=object)
My suspicion is related to the documentation, which reads: "Define a vectorized function that takes a sequence of numpy objects or numpy arrays as inputs and returns a numpy array as output. Pyfunc on consecutive tuples of input arrays such as the python mapping function, except that uses numpy broadcast rules. "