Python numpy.True_() 使用实例

The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can also save this page to your account.

Example 1

```def masked_matrix(matrix, all_zero=False):
"""
Returns masked version of HicMatrix. By default, all entries in zero-count

:param matrix: A numpy 2D matrix
:param all_zero: Mask ALL zero-count entries
"""
if all_zero:
col_zero = np.isclose(np.sum(matrix, axis=0), 0.)
row_zero = np.isclose(np.sum(matrix, axis=1), 0.)

Example 2

```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) ```

Example 3

```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) ```

Example 4

```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) ```

Example 5

```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) ```

Example 6

```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) ```

Example 7

```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) ```

Example 8

```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) ```

Example 9

```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) ```

Example 10

```def _recalc_display_image_minmax(self):
else:
self._display_image_min = 0.
self._display_image_max = 0. ```

Example 11

```def _recalc_display_image_minmax(self):
else:
self._display_image_min = 0.
self._display_image_max = 0. ```

Example 12

```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) ```

Example 13

```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) ```

Example 14

```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) ```

Example 15

```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) ```

Example 16

```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) ```

Example 17

```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) ```

Example 18

```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) ```

Example 19

```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) ```

Example 20

```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) ```

Example 21

```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) ```

Example 22

```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) ```

Example 23

```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) ```

Example 24

```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) ```

Example 25

```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) ```

Example 26

```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) ```

Example 27

```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) ```

Example 28

```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) ```

Example 29

```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) ```

Example 30

```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) ```

Example 31

```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) ```

Example 32

```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
----
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
"""
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,
'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':[]}
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)

output['n_star_pix'] = star_pixels.size
output['n_sky_pix'] = sky_pixels.size
else:
sky_per_pixel, median, stddev = np.nan, np.nan, np.inf
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 ```

Example 33

```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
----
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
"""
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,
'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':[]}
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)

output['n_star_pix'] = star_pixels.size
output['n_sky_pix'] = sky_pixels.size