我们从Python开源项目中,提取了以下33个代码示例,用于说明如何使用numpy.True_()。
def masked_matrix(matrix, all_zero=False): """ Returns masked version of HicMatrix. By default, all entries in zero-count rows and columns are masked. :param matrix: A numpy 2D matrix :param all_zero: Mask ALL zero-count entries :returns: MaskedArray with zero entries masked """ if all_zero: return np.ma.MaskedArray(matrix, mask=np.isclose(matrix, 0.)) col_zero = np.isclose(np.sum(matrix, axis=0), 0.) row_zero = np.isclose(np.sum(matrix, axis=1), 0.) mask = np.zeros(matrix.shape, dtype=np.bool_) mask[:, col_zero] = np.True_ mask[row_zero, :] = np.True_ return np.ma.MaskedArray(matrix, mask=mask)
def test_logical(self): f = np.False_ t = np.True_ s = "xyz" self.assertTrue((t and s) is s) self.assertTrue((f and s) is f)
def test_bitwise_or(self): f = np.False_ t = np.True_ self.assertTrue((t | t) is t) self.assertTrue((f | t) is t) self.assertTrue((t | f) is t) self.assertTrue((f | f) is f)
def test_bitwise_and(self): f = np.False_ t = np.True_ self.assertTrue((t & t) is t) self.assertTrue((f & t) is f) self.assertTrue((t & f) is f) self.assertTrue((f & f) is f)
def test_bitwise_xor(self): f = np.False_ t = np.True_ self.assertTrue((t ^ t) is f) self.assertTrue((f ^ t) is t) self.assertTrue((t ^ f) is t) self.assertTrue((f ^ f) is f)
def _recalc_display_image_minmax(self): finite_mask = np.isfinite(self.display_image) if finite_mask.max() is np.True_: self._display_image_min = self.display_image[finite_mask].min() self._display_image_max = self.display_image[finite_mask].max() else: self._display_image_min = 0. self._display_image_max = 0.
def aperture_phot(im, x, y, star_radius, sky_inner_radius, sky_outer_radius, return_distances=False): """ im - 2-d numpy array x,y - coordinates of center of star star_radius - radius of photometry circle sky_inner_radius, sky_outer_radius - defines annulus for determining sky (if sky_inner_radius > sky_outer_radius, aperture_phot flips them) ---- Note that this is a very quick-and-dirty aperture photometry routine. No error checking. No partial pixels. Many ways this could fail and/or give misleading results. Not to be used within 12 hours of eating food. Use only immediately after a large meal. ---- returns dictionary with: flux - sky-subtracted flux inside star_radius sky_per_pixel - sky counts per pixel determined from sky annulus sky_per_pixel_err - estimated 1-sigma uncertainty in sky_per_pixel sky_err - estimated 1-sigma uncertainty in sky subtraction from flux n_star_pix - number of pixels in star_radius n_sky_pix - number of pixels in sky annulus x - input x y - input y star_radius - input star_radius sky_inner_radius - input sky_inner_radius sky_outer_radius - input sky_outer_radius """ if np.isnan(x) or np.isnan(y): return {'error-msg':'One or both of x/y were NaN.', 'x':x, 'y':y, 'star_radius': star_radius, 'sky_inner_radius': sky_inner_radius, 'sky_outer_radius': sky_outer_radius, 'n_star_pix':0, 'n_sky_pix':0, 'sky_per_pixel':np.nan, 'sky_per_pixel_err':np.nan, 'flux':np.nan, 'sky_err':np.nan, 'distances':[]} if sky_inner_radius > sky_outer_radius: sky_inner_radius, sky_outer_radius = sky_outer_radius, sky_inner_radius output = {'x': x, 'y': y, 'star_radius': star_radius, 'sky_inner_radius': sky_inner_radius, 'sky_outer_radius': sky_outer_radius} xdist = np.outer(np.ones(im.shape[0]), np.arange(im.shape[1]) - x) ydist = np.outer(np.arange(im.shape[0]) - y, np.ones(im.shape[1])) dist = np.sqrt(xdist**2 + ydist**2) star_mask = dist <= star_radius star_pixels = im[star_mask] sky_pixels = im[(dist >= sky_inner_radius) & (dist <= sky_outer_radius)] output['n_star_pix'] = star_pixels.size output['n_sky_pix'] = sky_pixels.size finite_mask = np.isfinite(sky_pixels) if finite_mask.max() is np.True_: sky_per_pixel, median, stddev = sigma_clipped_stats(sky_pixels[finite_mask]) else: sky_per_pixel, median, stddev = np.nan, np.nan, np.inf sky_per_pixel_err = stddev/np.sqrt(finite_mask.sum()) output['sky_per_pixel'] = sky_per_pixel # TODO: check that are doing sky_per_pixel_err right. In one quick test seemed high (but maybe wasn't a good test) output['sky_per_pixel_err'] = sky_per_pixel_err output['flux'] = star_pixels.sum() - sky_per_pixel*star_pixels.size output['sky_err'] = sky_per_pixel_err*np.sqrt(star_pixels.size) if return_distances: output['distances'] = dist return output