本文整理汇总了Python中numpy.core.numeric.ones方法的典型用法代码示例。如果您正苦于以下问题:Python numeric.ones方法的具体用法?Python numeric.ones怎么用?Python numeric.ones使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.core.numeric
的用法示例。
在下文中一共展示了numeric.ones方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: count
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import ones [as 别名]
def count (self, axis = None):
"Count of the non-masked elements in a, or along a certain axis."
m = self._mask
s = self._data.shape
ls = len(s)
if m is nomask:
if ls == 0:
return 1
if ls == 1:
return s[0]
if axis is None:
return reduce(lambda x, y:x*y, s)
else:
n = s[axis]
t = list(s)
del t[axis]
return ones(t) * n
if axis is None:
w = fromnumeric.ravel(m).astype(int)
n1 = size(w)
if n1 == 1:
n2 = w[0]
else:
n2 = umath.add.reduce(w)
return n1 - n2
else:
n1 = size(m, axis)
n2 = sum(m.astype(int), axis)
return n1 - n2
示例2: ones
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import ones [as 别名]
def ones (shape, dtype=float):
"""ones(n, dtype=float) =
an array of all ones of the given length or shape."""
return array(numeric.ones(shape, dtype))