chararray.itemset(*args)¶Insert scalar into an array (scalar is cast to array’s dtype, if possible)
There must be at least 1 argument, and define the last argumentasitem. Then,a.itemset(*args) is equivalent to but fasterthana[args]=item. The item should be a scalar value andargsmust select a single item in the arraya.
| Parameters: | *args : Arguments
|
|---|
Notes
Compared to indexing syntax,itemset provides some speed increasefor placing a scalar into a particular location in anndarray,if you must do this. However, generally this is discouraged:among other problems, it complicates the appearance of the code.Also, when usingitemset (anditem) inside a loop, be sureto assign the methods to a local variable to avoid the attributelook-up at each loop iteration.
Examples
>>>x=np.random.randint(9,size=(3,3))>>>xarray([[3, 1, 7], [2, 8, 3], [8, 5, 3]])>>>x.itemset(4,0)>>>x.itemset((2,2),9)>>>xarray([[3, 1, 7], [2, 0, 3], [8, 5, 9]])