本文整理汇总了Python中numpy.core.numeric.indices方法的典型用法代码示例。如果您正苦于以下问题:Python numeric.indices方法的具体用法?Python numeric.indices怎么用?Python numeric.indices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.core.numeric
的用法示例。
在下文中一共展示了numeric.indices方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: choose
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import indices [as 别名]
def choose (indices, t, out=None, mode='raise'):
"Returns array shaped like indices with elements chosen from t"
def fmask (x):
if x is masked: return 1
return filled(x)
def nmask (x):
if x is masked: return 1
m = getmask(x)
if m is nomask: return 0
return m
c = filled(indices, 0)
masks = [nmask(x) for x in t]
a = [fmask(x) for x in t]
d = numeric.choose(c, a)
m = numeric.choose(c, masks)
m = make_mask(mask_or(m, getmask(indices)), copy=0, flag=1)
return masked_array(d, m)
示例2: __next__
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import indices [as 别名]
def __next__(self):
"""
Standard iterator method, returns the index tuple and array value.
Returns
-------
coords : tuple of ints
The indices of the current iteration.
val : scalar
The array element of the current iteration.
"""
return self.iter.coords, next(self.iter)
示例3: diag_indices_from
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import indices [as 别名]
def diag_indices_from(arr):
"""
Return the indices to access the main diagonal of an n-dimensional array.
See `diag_indices` for full details.
Parameters
----------
arr : array, at least 2-D
See Also
--------
diag_indices
Notes
-----
.. versionadded:: 1.4.0
"""
if not arr.ndim >= 2:
raise ValueError("input array must be at least 2-d")
# For more than d=2, the strided formula is only valid for arrays with
# all dimensions equal, so we check first.
if not alltrue(diff(arr.shape) == 0):
raise ValueError("All dimensions of input must be of equal length")
return diag_indices(arr.shape[0], arr.ndim)
示例4: __next__
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import indices [as 别名]
def __next__(self):
"""
Standard iterator method, updates the index and returns the index
tuple.
Returns
-------
val : tuple of ints
Returns a tuple containing the indices of the current
iteration.
"""
next(self._it)
return self._it.multi_index
示例5: nonzero
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import indices [as 别名]
def nonzero(a):
"""returns the indices of the elements of a which are not zero
and not masked
"""
return numeric.asarray(filled(a, 0).nonzero())
示例6: new_take
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import indices [as 别名]
def new_take (a, indices, axis=None, out=None, mode='raise'):
"returns selection of items from a."
m = getmask(a)
# d = masked_array(a).raw_data()
d = masked_array(a).data
if m is nomask:
return masked_array(numeric.take(d, indices, axis))
else:
return masked_array(numeric.take(d, indices, axis),
mask = numeric.take(m, indices, axis))
示例7: put
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import indices [as 别名]
def put(a, indices, values, mode='raise'):
"""sets storage-indexed locations to corresponding values.
Values and indices are filled if necessary.
"""
d = a.raw_data()
ind = filled(indices)
v = filled(values)
numeric.put (d, ind, v)
m = getmask(a)
if m is not nomask:
a.unshare_mask()
numeric.put(a.raw_mask(), ind, 0)
示例8: argsort
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import indices [as 别名]
def argsort (x, axis = -1, out=None, fill_value=None):
"""Treating masked values as if they have the value fill_value,
return sort indices for sorting along given axis.
if fill_value is None, use get_fill_value(x)
Returns a numpy array.
"""
d = filled(x, fill_value)
return fromnumeric.argsort(d, axis)
示例9: argmin
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import indices [as 别名]
def argmin (x, axis = -1, out=None, fill_value=None):
"""Treating masked values as if they have the value fill_value,
return indices for minimum values along given axis.
if fill_value is None, use get_fill_value(x).
Returns a numpy array if x has more than one dimension.
Otherwise, returns a scalar index.
"""
d = filled(x, fill_value)
return fromnumeric.argmin(d, axis)
示例10: take
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import indices [as 别名]
def take(a, indices, axis=0):
return new_take(a, indices, axis)