I am new to python programming. when using reduce() function on a numpy array (like this code):
import numpy as np
from functools import reduce
x = np.arange(1, 5)
y = list(reduce(lambda s, t: s + t, x))
I receive this error:
TypeError: 'numpy.int32' object is not iterable
I tested the same codes for map() function and had no error:
import numpy as np
x = np.arange(1, 5)
z = list(map(lambda s: s if s%2 == 0 else None, x))
How can I use reduce function for a numpy array? Thanks in advance.