Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.chararray.itemset

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

If one argument: a scalar, only used in casea is of size 1.If two arguments: the last argument is the value to be setand must be a scalar, the first argument specifies a single arrayelement location. It is either an int or a tuple.

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]])
  • © Copyright 2008-2009, The Scipy community.
  • Last updated on Jun 10, 2017.
  • Created usingSphinx 1.5.3.

[8]ページ先頭

©2009-2025 Movatter.jp