Python numpy.core.numeric.ones() Examples
The following are 2
code examples of numpy.core.numeric.ones().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy.core.numeric
, or try the search function
.
Example #1
Source File: ma.py From Computable with MIT License | 5 votes |
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
Example #2
Source File: ma.py From Computable with MIT License | 5 votes |
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))