本文整理匯總了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))