Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 [numpy]add a value to an array elmismo999 Unladen Swallow Posts: 2 Threads: 2 Joined: May 2019 Reputation: 0 Likes received: 0 #1 May-23-2019, 03:54 PM (This post was last modified: May-23-2019, 06:28 PM by Yoriz. Edited 2 times in total. Edit Reason: Added code tags, prefix and moved to data science ) I have an array created with numpy `arr10=np.random.randint(0,10,(4,4))`If for example I want to sum to each element the value 10 where the value is > 5 how I do that please ? Thank You - Yoriz wrote May-23-2019, 06:28 PM:Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time. michalmonday Wafer-Thin Wafer Posts: 93 Threads: 1 Joined: May 2019 Reputation: 13 Likes received: 19 #2 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]]) >>>``` « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post numpy.where array search for string in just one coordinate adetheheat 1 165 Jan-09-2020, 07:09 PM Last Post: paul18fr memory issue loading movie to numpy array djf123 1 129 Nov-07-2019, 06:19 AM Last Post: ThomasL Numpy structured array Nitram 3 322 Sep-17-2019, 10:09 PM Last Post: jefsummers numpy.copy / numpy.delete paul18fr 3 368 Jul-26-2019, 01:51 PM Last Post: paul18fr AttributeError: module 'numpy' has no attribute 'array aapurdel 7 7,069 May-29-2019, 02:48 AM Last Post: heiner55 Array in numpy Truman 5 4,378 May-26-2019, 10:14 AM Last Post: snippsat [split] Array in numpy aapurdel 1 351 May-25-2019, 08:05 PM Last Post: buran "erlarge" a numpy-matrix to numpy-array PhysChem 2 498 Apr-09-2019, 04:54 PM Last Post: PhysChem while creating a array using numpy.arrange, how to negate only the last 50 numbers? vicky53 1 508 Apr-06-2019, 11:52 AM Last Post: scidam How to get the size of a numpy array? mcgrim 2 545 Mar-23-2019, 02:25 PM Last Post: perfringo

Forum Jump:

Users browsing this thread: 1 Guest(s)