本文整理汇总了Python中numpy.bool_函数的典型用法代码示例。如果您正苦于以下问题:Python bool_函数的具体用法?Python bool_怎么用?Python bool_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bool_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_numpy_scalar_bool
def test_numpy_scalar_bool(self):
x = np.bool_(True)
x_rec = self.encode_decode(x)
assert x == x_rec and type(x) == type(x_rec)
x = np.bool_(False)
x_rec = self.encode_decode(x)
assert x == x_rec and type(x) == type(x_rec)
示例2: __init__
def __init__(self, x, y):
assert np.ndim(x)==2 and np.ndim(y)==2 and np.shape(x)==np.shape(y), \
'x and y must be 2D arrays of the same size.'
if np.any(np.isnan(x)) or np.any(np.isnan(y)):
x = np.ma.masked_where( (isnan(x)) | (isnan(y)) , x)
y = np.ma.masked_where( (isnan(x)) | (isnan(y)) , y)
self.x_vert = x
self.y_vert = y
mask_shape = tuple([n-1 for n in self.x_vert.shape])
self.mask_rho = np.ones(mask_shape, dtype='d')
# If maskedarray is given for verticies, modify the mask such that
# non-existant grid points are masked. A cell requires all four
# verticies to be defined as a water point.
if isinstance(self.x_vert, np.ma.MaskedArray):
mask = (self.x_vert.mask[:-1,:-1] | self.x_vert.mask[1:,:-1] | \
self.x_vert.mask[:-1,1:] | self.x_vert.mask[1:,1:])
self.mask_rho = np.asarray(~(~np.bool_(self.mask_rho) | mask), dtype='d')
if isinstance(self.y_vert, np.ma.MaskedArray):
mask = (self.y_vert.mask[:-1,:-1] | self.y_vert.mask[1:,:-1] | \
self.y_vert.mask[:-1,1:] | self.y_vert.mask[1:,1:])
self.mask_rho = np.asarray(~(~np.bool_(self.mask_rho) | mask), dtype='d')
self._calculate_subgrids()
self._calculate_metrics()
示例3: test_numpy
def test_numpy(self):
assert chash(np.bool_(True)) == chash(np.bool_(True))
assert chash(np.int8(1)) == chash(np.int8(1))
assert chash(np.int16(1))
assert chash(np.int32(1))
assert chash(np.int64(1))
assert chash(np.uint8(1))
assert chash(np.uint16(1))
assert chash(np.uint32(1))
assert chash(np.uint64(1))
assert chash(np.float32(1)) == chash(np.float32(1))
assert chash(np.float64(1)) == chash(np.float64(1))
assert chash(np.float128(1)) == chash(np.float128(1))
assert chash(np.complex64(1+1j)) == chash(np.complex64(1+1j))
assert chash(np.complex128(1+1j)) == chash(np.complex128(1+1j))
assert chash(np.complex256(1+1j)) == chash(np.complex256(1+1j))
assert chash(np.datetime64('2000-01-01')) == chash(np.datetime64('2000-01-01'))
assert chash(np.timedelta64(1,'W')) == chash(np.timedelta64(1,'W'))
self.assertRaises(ValueError, chash, np.object())
assert chash(np.array([[1, 2], [3, 4]])) == \
chash(np.array([[1, 2], [3, 4]]))
assert chash(np.array([[1, 2], [3, 4]])) != \
chash(np.array([[1, 2], [3, 4]]).T)
assert chash(np.array([1, 2, 3])) == chash(np.array([1, 2, 3]))
assert chash(np.array([1, 2, 3], dtype=np.int32)) != \
chash(np.array([1, 2, 3], dtype=np.int64))
示例4: mask_rho
def mask_rho(self):
"""
Returns the mask for the cells
"""
if self._mask_rho is None:
mask_shape = tuple([n - 1 for n in self.x_vert.shape])
self._mask_rho = numpy.ones(mask_shape, dtype='d')
# If maskedarray is given for vertices, modify the mask such that
# non-existant grid points are masked. A cell requires all four
# verticies to be defined as a water point.
if isinstance(self.x_vert, numpy.ma.MaskedArray):
mask = (self.x_vert.mask[:-1, :-1] | self.x_vert.mask[1:, :-1] |
self.x_vert.mask[:-1, 1:] | self.x_vert.mask[1:, 1:])
self._mask_rho = numpy.asarray(
~(~numpy.bool_(self.mask_rho) | mask),
dtype='d'
)
if isinstance(self.y_vert, numpy.ma.MaskedArray):
mask = (self.y_vert.mask[:-1, :-1] | self.y_vert.mask[1:, :-1] |
self.y_vert.mask[:-1, 1:] | self.y_vert.mask[1:, 1:])
self._mask_rho = numpy.asarray(
~(~numpy.bool_(self.mask_rho) | mask),
dtype='d'
)
return self._mask_rho
示例5: test00b_setBoolAttributes
def test00b_setBoolAttributes(self):
"""Checking setting Bool attributes (scalar, NumPy case)"""
self.array.attrs.pq = numpy.bool_(True)
self.array.attrs.qr = numpy.bool_(False)
self.array.attrs.rs = numpy.bool_(True)
# Check the results
if common.verbose:
print "pq -->", self.array.attrs.pq
print "qr -->", self.array.attrs.qr
print "rs -->", self.array.attrs.rs
if self.close:
if common.verbose:
print "(closing file version)"
self.fileh.close()
self.fileh = openFile(self.file, mode = "r+")
self.root = self.fileh.root
self.array = self.fileh.root.anarray
assert isinstance(self.root.anarray.attrs.pq, numpy.bool_)
assert isinstance(self.root.anarray.attrs.qr, numpy.bool_)
assert isinstance(self.root.anarray.attrs.rs, numpy.bool_)
assert self.root.anarray.attrs.pq == True
assert self.root.anarray.attrs.qr == False
assert self.root.anarray.attrs.rs == True
示例6: test_numpy_scalar_conversion_values
def test_numpy_scalar_conversion_values(self):
self.assertEqual(nd.as_py(nd.array(np.bool_(True))), True)
self.assertEqual(nd.as_py(nd.array(np.bool_(False))), False)
self.assertEqual(nd.as_py(nd.array(np.int8(100))), 100)
self.assertEqual(nd.as_py(nd.array(np.int8(-100))), -100)
self.assertEqual(nd.as_py(nd.array(np.int16(20000))), 20000)
self.assertEqual(nd.as_py(nd.array(np.int16(-20000))), -20000)
self.assertEqual(nd.as_py(nd.array(np.int32(1000000000))), 1000000000)
self.assertEqual(nd.as_py(nd.array(np.int64(-1000000000000))),
-1000000000000)
self.assertEqual(nd.as_py(nd.array(np.int64(1000000000000))),
1000000000000)
self.assertEqual(nd.as_py(nd.array(np.int32(-1000000000))),
-1000000000)
self.assertEqual(nd.as_py(nd.array(np.uint8(200))), 200)
self.assertEqual(nd.as_py(nd.array(np.uint16(50000))), 50000)
self.assertEqual(nd.as_py(nd.array(np.uint32(3000000000))), 3000000000)
self.assertEqual(nd.as_py(nd.array(np.uint64(10000000000000000000))),
10000000000000000000)
self.assertEqual(nd.as_py(nd.array(np.float32(2.5))), 2.5)
self.assertEqual(nd.as_py(nd.array(np.float64(2.5))), 2.5)
self.assertEqual(nd.as_py(nd.array(np.complex64(2.5-1j))), 2.5-1j)
self.assertEqual(nd.as_py(nd.array(np.complex128(2.5-1j))), 2.5-1j)
if np.__version__ >= '1.7':
self.assertEqual(nd.as_py(nd.array(np.datetime64('2000-12-13'))),
date(2000, 12, 13))
示例7: test_scalar_bool
def test_scalar_bool(self):
x = np.bool_(1)
x_rec = self.encode_decode(x)
tm.assert_almost_equal(x, x_rec)
x = np.bool_(0)
x_rec = self.encode_decode(x)
tm.assert_almost_equal(x, x_rec)
示例8: test_normalize_json
def test_normalize_json():
doc = {"foo": {numpy.bool_(True): "value"},
"what": numpy.bool_(False),
"this": numpy.PINF}
normalized_doc = normalize_json(doc)
assert isinstance(normalized_doc['what'], bool)
assert isinstance(list(normalized_doc['foo'].keys())[0], bool)
assert normalized_doc['this'] == "Infinity"
示例9: eval
def eval(self, row, dataset):
result = np.bool_(self.value[0].eval(row, dataset))
for oper, val in self.operator_operands(self.value[1:]):
val = np.bool_(val.eval(row, dataset))
result = self.operation(oper, result, val)
return result
示例10: test_numpy_scalar_bool
def test_numpy_scalar_bool(self):
x = np.bool_(True)
x_rec = self.encode_decode(x)
assert_equal(x, x_rec)
assert_equal(type(x), type(x_rec))
x = np.bool_(False)
x_rec = self.encode_decode(x)
assert_equal(x, x_rec)
assert_equal(type(x), type(x_rec))
示例11: get_results
def get_results(self, conditions):
self.conditions = dict(zip(conditions, range(len(conditions))))
# Loads data for each subject
# results is in the form (condition x subjects x runs x matrix)
results = load_matrices(self.path, conditions)
# Check if there are NaNs in the data
nan_mask = np.isnan(results)
for _ in range(len(results.shape) - 2):
# For each condition/subject/run check if we have nan
nan_mask = nan_mask.sum(axis=0)
#pl.imshow(np.bool_(nan_mask), interpolation='nearest')
#print np.nonzero(np.bool_(nan_mask)[0,:])
# Clean NaNs
results = results[:,:,:,~np.bool_(nan_mask)]
# Reshaping because numpy masking flattens matrices
rows = np.sqrt(results.shape[-1])
shape = list(results.shape[:-1])
shape.append(int(rows))
shape.append(-1)
results = results.reshape(shape)
# We apply z fisher to results
zresults = z_fisher(results)
zresults[np.isinf(zresults)] = 1
self.results = zresults
# Select mask to delete labels
roi_mask = ~np.bool_(np.diagonal(nan_mask))
# Get some information to store stuff
self.store_details(roi_mask)
# Mean across runs
zmean = zresults.mean(axis=2)
new_shape = list(zmean.shape[-2:])
new_shape.insert(0, -1)
zreshaped = zmean.reshape(new_shape)
upper_mask = np.ones_like(zreshaped[0])
upper_mask[np.tril_indices(zreshaped[0].shape[0])] = 0
upper_mask = np.bool_(upper_mask)
# Returns the mask of the not available ROIs.
self.nan_mask = nan_mask
return self.nan_mask
示例12: test_index_bool
def test_index_bool( self ):
a = np.arange(5)
x = np.bool_(False)
y = np.bool_(True)
z = a[x:y]
assert_equal( z, [0] )
示例13: test_dmat_add
def test_dmat_add(self):
assert_equals(self.pos_vec + self.neg_vec, self.unknown_vec)
result = Sign(np.bool_(True), self.arr)
assert_equals(self.pos_vec + Sign.NEGATIVE, result)
assert_equals(self.neg_vec + self.zero_vec, self.neg_vec)
result = Sign(np.bool_(True), ~self.true_mat)
assert_equals(self.neg_mat + Sign.NEGATIVE, result)
assert_equals(self.pos_vec + self.pos_vec, self.pos_vec)
assert_equals(self.unknown_mat + self.zero_mat, self.unknown_mat)
assert_equals(Sign.UNKNOWN + self.pos_mat, Sign.UNKNOWN)
示例14: test_mask_ratio
def test_mask_ratio(self):
self.assertEqual(mask_ratio(True), 1)
self.assertEqual(mask_ratio(np.bool_(True)), 1)
self.assertEqual(mask_ratio(False), 0)
self.assertEqual(mask_ratio(np.bool_(False)), 0)
array = np.ma.array(range(10))
self.assertEqual(mask_ratio(np.ma.getmaskarray(array)), 0)
array[0] = np.ma.masked
self.assertEqual(mask_ratio(np.ma.getmaskarray(array)), 0.1)
invalid_array = np.ma.array(range(100), mask=[True]*100)
self.assertEqual(mask_ratio(np.ma.getmaskarray(invalid_array)), 1)
示例15: test_astype
def test_astype(self):
import numpy as np
a = np.bool_(True).astype(np.float32)
assert type(a) is np.float32
assert a == 1.0
a = np.bool_(True).astype('int32')
assert type(a) is np.int32
assert a == 1
a = np.str_('123').astype('int32')
assert type(a) is np.int32
assert a == 123