The Numpy method fromfunctioncreates two arrays: one where the value in each cell is the index of cell x and where each cell is the index of cell y. Then it applies the function in which you passed.
When the function is first called, it does something like this:
x=[[0 0 0]
[1 1 1]
[2 2 2]]
y=[[0 1 2]
[0 1 2]
[0 1 2]]
result = fn(x,y)
fn - -. numpy , , . , max , max max python numpy. , python max :
def max(x,y):
if x>y:
return x
return y
x>y numpy, x y numpy, if <numpy array> , :
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
, , numpy.fromfunction, , , , . Numpy numpy.maximum, max numpy.maximum, , .
: lambda x,y: max(x,y) max, , max. , , :
B=numpy.fromfunction(numpy.maximum,(3,3),dtype=int)