May-23-2019, 04:15 PM
Quote:I want to sum to each element the value 10
I don't understand this part. Would you like to add 10 to every value over 5? In such case you could do something like this:
>>> import numpy as np >>> arr10=np.random.randint(0,10,(4,4)) >>> arr10 array([[7, 2, 6, 2], [5, 7, 0, 8], [4, 2, 0, 5], [1, 5, 6, 6]]) >>> np.where(arr10 > 5, arr10+10, arr10) array([[17, 2, 16, 2], [ 5, 17, 0, 18], [ 4, 2, 0, 5], [ 1, 5, 16, 16]]) >>>