Python numpy.ma.zeros() Examples
The following are 30
code examples of numpy.ma.zeros().
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.ma
, or try the search function
.
Example #1
Source File: intra_comp_ts.py From CogAlg with MIT License | 6 votes |
def comp_g(dert__, odd): g__ = dert__[0] a__ = dert__[1:] # loop through each pair of comparands in a kernel dgy__ = ma.zeros(np.subtract(g.shape, rng)) dgx__ = ma.zeros(np.subtract(g.shape, rng)) for x_coeff, y_coeff, (ts, _ts) in zip(X_COEFFS[rng], Y_COEFFS[rng], TRANSLATING_SLICES_PAIRS_[rng]): # find angle differences da__ = angle_diff(a__[ts], a__[_ts]) # compute dg: dg = g - _g * cos(da) at each position dg__ = g__[ts] - g__[_ts] * da__[1] # accumulate dgy, dgx dgx__ += dg__ * x_coeff dgy__ += dg__ * y_coeff gg__ = ma.hypot(dgy__, dgx__) return ma.stack((g__, gg__, dgy__, dgx__))
Example #2
Source File: png.py From mapchete with MIT License | 6 votes |
def empty(self, process_tile): """ Return empty data. Parameters ---------- process_tile : ``BufferedTile`` must be member of process ``TilePyramid`` Returns ------- empty data : array empty array with data type given in output parameters """ bands = ( self.output_params["bands"] if "bands" in self.output_params else PNG_DEFAULT_PROFILE["count"] ) return ma.masked_array( data=ma.zeros((bands, ) + process_tile.shape), mask=ma.zeros((bands, ) + process_tile.shape), dtype=PNG_DEFAULT_PROFILE["dtype"] )
Example #3
Source File: lines.py From ImageFusion with MIT License | 5 votes |
def _draw_steps_post(self, renderer, gc, path, trans): vertices = self._xy steps = ma.zeros((2 * len(vertices) - 1, 2), np.float_) steps[::2, 0], steps[1:-1:2, 0] = vertices[:, 0], vertices[1:, 0] steps[0::2, 1], steps[1::2, 1] = vertices[:, 1], vertices[:-1, 1] path = Path(steps) path = path.transformed(self.get_transform()) self._lineFunc(renderer, gc, path, IdentityTransform())
Example #4
Source File: test_recfunctions.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def test_duplicate_keys(self): a = np.zeros(3, dtype=[('a', 'i4'), ('b', 'f4'), ('c', 'u1')]) b = np.ones(3, dtype=[('c', 'u1'), ('b', 'f4'), ('a', 'i4')]) assert_raises(ValueError, join_by, ['a', 'b', 'b'], a, b)
Example #5
Source File: tree.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _resize(masked, new_size): """ Masked arrays can not be resized inplace, and `np.resize` and `ma.resize` are both incompatible with structured arrays. Therefore, we do all this. """ new_array = ma.zeros((new_size,), dtype=masked.dtype) length = min(len(masked), new_size) new_array[:length] = masked[:length] return new_array
Example #6
Source File: test_recfunctions.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_simple_flexible(self): # Test recursive_fill_fields on flexible-array a = np.array([(1, 10.), (2, 20.)], dtype=[('A', int), ('B', float)]) b = np.zeros((3,), dtype=a.dtype) test = recursive_fill_fields(a, b) control = np.array([(1, 10.), (2, 20.), (0, 0.)], dtype=[('A', int), ('B', float)]) assert_equal(test, control)
Example #7
Source File: test_recfunctions.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_repack_fields(self): dt = np.dtype('u1,f4,i8', align=True) a = np.zeros(2, dtype=dt) assert_equal(repack_fields(dt), np.dtype('u1,f4,i8')) assert_equal(repack_fields(a).itemsize, 13) assert_equal(repack_fields(repack_fields(dt), align=True), dt) # make sure type is preserved dt = np.dtype((np.record, dt)) assert_(repack_fields(dt).type is np.record)
Example #8
Source File: test_recfunctions.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def test_masked_flexible(self): # Test recursive_fill_fields on masked flexible-array a = ma.array([(1, 10.), (2, 20.)], mask=[(0, 1), (1, 0)], dtype=[('A', int), ('B', float)]) b = ma.zeros((3,), dtype=a.dtype) test = recursive_fill_fields(a, b) control = ma.array([(1, 10.), (2, 20.), (0, 0.)], mask=[(0, 1), (1, 0), (0, 0)], dtype=[('A', int), ('B', float)]) assert_equal(test, control)
Example #9
Source File: test_recfunctions.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def test_simple_flexible(self): # Test recursive_fill_fields on flexible-array a = np.array([(1, 10.), (2, 20.)], dtype=[('A', int), ('B', float)]) b = np.zeros((3,), dtype=a.dtype) test = recursive_fill_fields(a, b) control = np.array([(1, 10.), (2, 20.), (0, 0.)], dtype=[('A', int), ('B', float)]) assert_equal(test, control)
Example #10
Source File: test_recfunctions.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def test_repack_fields(self): dt = np.dtype('u1,f4,i8', align=True) a = np.zeros(2, dtype=dt) assert_equal(repack_fields(dt), np.dtype('u1,f4,i8')) assert_equal(repack_fields(a).itemsize, 13) assert_equal(repack_fields(repack_fields(dt), align=True), dt) # make sure type is preserved dt = np.dtype((np.record, dt)) assert_(repack_fields(dt).type is np.record)
Example #11
Source File: tree.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def create_arrays(self, nrows=0, config=None): """ Create a new array to hold the data based on the current set of fields, and store them in the *array* and member variable. Any data in the existing array will be lost. *nrows*, if provided, is the number of rows to allocate. """ if nrows is None: nrows = 0 fields = self.fields if len(fields) == 0: array = np.recarray((nrows,), dtype='O') mask = np.zeros((nrows,), dtype='b') else: # for field in fields: field._setup(config) Field.uniqify_names(fields) dtype = [] for x in fields: if x._unique_name == x.ID: id = x.ID else: id = (x._unique_name, x.ID) dtype.append((id, x.converter.format)) array = np.recarray((nrows,), dtype=np.dtype(dtype)) descr_mask = [] for d in array.dtype.descr: new_type = (d[1][1] == 'O' and 'O') or 'bool' if len(d) == 2: descr_mask.append((d[0], new_type)) elif len(d) == 3: descr_mask.append((d[0], new_type, d[2])) mask = np.zeros((nrows,), dtype=descr_mask) self.array = ma.array(array, mask=mask)
Example #12
Source File: test_recfunctions.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def test_different_field_order(self): # gh-8940 a = np.zeros(3, dtype=[('a', 'i4'), ('b', 'f4'), ('c', 'u1')]) b = np.ones(3, dtype=[('c', 'u1'), ('b', 'f4'), ('a', 'i4')]) # this should not give a FutureWarning: j = join_by(['c', 'b'], a, b, jointype='inner', usemask=False) assert_equal(j.dtype.names, ['b', 'c', 'a1', 'a2'])
Example #13
Source File: test_recfunctions.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_different_field_order(self): # gh-8940 a = np.zeros(3, dtype=[('a', 'i4'), ('b', 'f4'), ('c', 'u1')]) b = np.ones(3, dtype=[('c', 'u1'), ('b', 'f4'), ('a', 'i4')]) # this should not give a FutureWarning: j = join_by(['c', 'b'], a, b, jointype='inner', usemask=False) assert_equal(j.dtype.names, ['b', 'c', 'a1', 'a2'])
Example #14
Source File: test_recfunctions.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_masked_flexible(self): # Test recursive_fill_fields on masked flexible-array a = ma.array([(1, 10.), (2, 20.)], mask=[(0, 1), (1, 0)], dtype=[('A', int), ('B', float)]) b = ma.zeros((3,), dtype=a.dtype) test = recursive_fill_fields(a, b) control = ma.array([(1, 10.), (2, 20.), (0, 0.)], mask=[(0, 1), (1, 0), (0, 0)], dtype=[('A', int), ('B', float)]) assert_equal(test, control)
Example #15
Source File: test_recfunctions.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_simple_flexible(self): # Test recursive_fill_fields on flexible-array a = np.array([(1, 10.), (2, 20.)], dtype=[('A', int), ('B', float)]) b = np.zeros((3,), dtype=a.dtype) test = recursive_fill_fields(a, b) control = np.array([(1, 10.), (2, 20.), (0, 0.)], dtype=[('A', int), ('B', float)]) assert_equal(test, control)
Example #16
Source File: lines.py From ImageFusion with MIT License | 5 votes |
def _draw_steps_mid(self, renderer, gc, path, trans): vertices = self._xy steps = ma.zeros((2 * len(vertices), 2), np.float_) steps[1:-1:2, 0] = 0.5 * (vertices[:-1, 0] + vertices[1:, 0]) steps[2::2, 0] = 0.5 * (vertices[:-1, 0] + vertices[1:, 0]) steps[0, 0] = vertices[0, 0] steps[-1, 0] = vertices[-1, 0] steps[0::2, 1], steps[1::2, 1] = vertices[:, 1], vertices[:, 1] path = Path(steps) path = path.transformed(self.get_transform()) self._lineFunc(renderer, gc, path, IdentityTransform())
Example #17
Source File: test_recfunctions.py From recruit with Apache License 2.0 | 5 votes |
def test_repack_fields(self): dt = np.dtype('u1,f4,i8', align=True) a = np.zeros(2, dtype=dt) assert_equal(repack_fields(dt), np.dtype('u1,f4,i8')) assert_equal(repack_fields(a).itemsize, 13) assert_equal(repack_fields(repack_fields(dt), align=True), dt) # make sure type is preserved dt = np.dtype((np.record, dt)) assert_(repack_fields(dt).type is np.record)
Example #18
Source File: lines.py From ImageFusion with MIT License | 5 votes |
def _draw_steps_pre(self, renderer, gc, path, trans): vertices = self._xy steps = ma.zeros((2 * len(vertices) - 1, 2), np.float_) steps[0::2, 0], steps[1::2, 0] = vertices[:, 0], vertices[:-1, 0] steps[0::2, 1], steps[1:-1:2, 1] = vertices[:, 1], vertices[1:, 1] path = Path(steps) path = path.transformed(self.get_transform()) self._lineFunc(renderer, gc, path, IdentityTransform())
Example #19
Source File: test_recfunctions.py From ImageFusion with MIT License | 5 votes |
def test_masked_flexible(self): # Test recursive_fill_fields on masked flexible-array a = ma.array([(1, 10.), (2, 20.)], mask=[(0, 1), (1, 0)], dtype=[('A', int), ('B', float)]) b = ma.zeros((3,), dtype=a.dtype) test = recursive_fill_fields(a, b) control = ma.array([(1, 10.), (2, 20.), (0, 0.)], mask=[(0, 1), (1, 0), (0, 0)], dtype=[('A', int), ('B', float)]) assert_equal(test, control)
Example #20
Source File: test_recfunctions.py From ImageFusion with MIT License | 5 votes |
def test_simple_flexible(self): # Test recursive_fill_fields on flexible-array a = np.array([(1, 10.), (2, 20.)], dtype=[('A', int), ('B', float)]) b = np.zeros((3,), dtype=a.dtype) test = recursive_fill_fields(a, b) control = np.array([(1, 10.), (2, 20.), (0, 0.)], dtype=[('A', int), ('B', float)]) assert_equal(test, control)
Example #21
Source File: test_recfunctions.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_duplicate_keys(self): a = np.zeros(3, dtype=[('a', 'i4'), ('b', 'f4'), ('c', 'u1')]) b = np.ones(3, dtype=[('c', 'u1'), ('b', 'f4'), ('a', 'i4')]) assert_raises(ValueError, join_by, ['a', 'b', 'b'], a, b)
Example #22
Source File: test_recfunctions.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_different_field_order(self): # gh-8940 a = np.zeros(3, dtype=[('a', 'i4'), ('b', 'f4'), ('c', 'u1')]) b = np.ones(3, dtype=[('c', 'u1'), ('b', 'f4'), ('a', 'i4')]) # this should not give a FutureWarning: j = join_by(['c', 'b'], a, b, jointype='inner', usemask=False) assert_equal(j.dtype.names, ['b', 'c', 'a1', 'a2'])
Example #23
Source File: test_recfunctions.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_masked_flexible(self): # Test recursive_fill_fields on masked flexible-array a = ma.array([(1, 10.), (2, 20.)], mask=[(0, 1), (1, 0)], dtype=[('A', int), ('B', float)]) b = ma.zeros((3,), dtype=a.dtype) test = recursive_fill_fields(a, b) control = ma.array([(1, 10.), (2, 20.), (0, 0.)], mask=[(0, 1), (1, 0), (0, 0)], dtype=[('A', int), ('B', float)]) assert_equal(test, control)
Example #24
Source File: test_recfunctions.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_simple_flexible(self): # Test recursive_fill_fields on flexible-array a = np.array([(1, 10.), (2, 20.)], dtype=[('A', int), ('B', float)]) b = np.zeros((3,), dtype=a.dtype) test = recursive_fill_fields(a, b) control = np.array([(1, 10.), (2, 20.), (0, 0.)], dtype=[('A', int), ('B', float)]) assert_equal(test, control)
Example #25
Source File: ImPACT.py From ctapipe with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_hillas_mean(self): """This is a simple function to find the peak position of each image in an event which will be used later in the Xmax calculation. Peak is found by taking the average position of the n hottest pixels in the image. Parameters ---------- Returns ------- None """ peak_x = np.zeros([len(self.pixel_x)]) # Create blank arrays for peaks # rather than a dict (faster) peak_y = np.zeros(peak_x.shape) peak_amp = np.zeros(peak_x.shape) # Loop over all tels to take weighted average of pixel # positions This loop could maybe be replaced by an array # operation by a numpy wizard # Maybe a vectorize? tel_num = 0 for hillas in self.hillas_parameters: peak_x[tel_num] = hillas.x.to(u.rad).value # Fill up array peak_y[tel_num] = hillas.y.to(u.rad).value peak_amp[tel_num] = hillas.intensity tel_num += 1 self.peak_x = peak_x # * unit # Add to class member self.peak_y = peak_y # * unit self.peak_amp = peak_amp # This function would be useful elsewhere so probably be implemented in a # more general form
Example #26
Source File: test_recfunctions.py From pySINDy with MIT License | 5 votes |
def test_duplicate_keys(self): a = np.zeros(3, dtype=[('a', 'i4'), ('b', 'f4'), ('c', 'u1')]) b = np.ones(3, dtype=[('c', 'u1'), ('b', 'f4'), ('a', 'i4')]) assert_raises(ValueError, join_by, ['a', 'b', 'b'], a, b)
Example #27
Source File: test_recfunctions.py From pySINDy with MIT License | 5 votes |
def test_different_field_order(self): # gh-8940 a = np.zeros(3, dtype=[('a', 'i4'), ('b', 'f4'), ('c', 'u1')]) b = np.ones(3, dtype=[('c', 'u1'), ('b', 'f4'), ('a', 'i4')]) # this should not give a FutureWarning: j = join_by(['c', 'b'], a, b, jointype='inner', usemask=False) assert_equal(j.dtype.names, ['b', 'c', 'a1', 'a2'])
Example #28
Source File: test_recfunctions.py From pySINDy with MIT License | 5 votes |
def test_masked_flexible(self): # Test recursive_fill_fields on masked flexible-array a = ma.array([(1, 10.), (2, 20.)], mask=[(0, 1), (1, 0)], dtype=[('A', int), ('B', float)]) b = ma.zeros((3,), dtype=a.dtype) test = recursive_fill_fields(a, b) control = ma.array([(1, 10.), (2, 20.), (0, 0.)], mask=[(0, 1), (1, 0), (0, 0)], dtype=[('A', int), ('B', float)]) assert_equal(test, control)
Example #29
Source File: test_recfunctions.py From pySINDy with MIT License | 5 votes |
def test_simple_flexible(self): # Test recursive_fill_fields on flexible-array a = np.array([(1, 10.), (2, 20.)], dtype=[('A', int), ('B', float)]) b = np.zeros((3,), dtype=a.dtype) test = recursive_fill_fields(a, b) control = np.array([(1, 10.), (2, 20.), (0, 0.)], dtype=[('A', int), ('B', float)]) assert_equal(test, control)
Example #30
Source File: test_recfunctions.py From pySINDy with MIT License | 5 votes |
def test_repack_fields(self): dt = np.dtype('u1,f4,i8', align=True) a = np.zeros(2, dtype=dt) assert_equal(repack_fields(dt), np.dtype('u1,f4,i8')) assert_equal(repack_fields(a).itemsize, 13) assert_equal(repack_fields(repack_fields(dt), align=True), dt) # make sure type is preserved dt = np.dtype((np.record, dt)) assert_(repack_fields(dt).type is np.record)