This is not explained in the documentation of the func argument in fromfunction docstring that func is called only once, with array arguments.
In this example
np.fromfunction(lambda i: i, (4,), dtype=int)
the anonymous function is called once, the argument i is an array [0, 1, 2, 3]. To check this, you can do:
In [10] from __future__ import print_function In [11]: np.fromfunction(lambda i: print("i = %r" % (i,)), (4,), dtype=int) i = array([0, 1, 2, 3])
In this case, when func returns 1,
np.fromfunction(lambda i: 1, (4,), dtype=int)
because the value returned by one call is 1, the array created contains only 1.
It is not clear why you would like to use fromfunction to create an array of 1s instead of, say, np.ones , but in case you have something more complex in mind, here is one way to do this using np.ones_like :
In [14]: np.fromfunction(lambda i: np.ones_like(i), (4,), dtype=int) Out[14]: array([1, 1, 1, 1])