Why do you want to do that?
First thank you for your help, the callable object works.
Basically I have a lot of functions inside a numpy array,
of which most return "" and actually are derived as follows:
from numpy import *
grid_size = 1000000
class F(object):
def __cmp__(self, other): return 0
def __call__(self, dummy): return ""
f = F()
myarray = array([f] * grid_size, dtype="O")
# I re-define an element in the array
myarray[34424] = lambda x: "23"
# Now, I would like to loop over all re-defined elements:
for i in itertools.izip(*nonzero(myarray)):
print myarray
()
If I fill the array with 0 instead of the functions that
return "" this works really fast.
However, I would like to be able call the content of each
cell in the array as a function.
As I said, the callable object approach works but is
about as slow as iterating through the whole array.
Perhaps I should add a __call__ function to the built-in
0? But I doubt that this helps.
Martin