本文整理汇总了Python中numpy.bool方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.bool方法的具体用法?Python numpy.bool怎么用?Python numpy.bool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.bool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fetch
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def fetch(clobber=False):
"""
Downloads the 3D dust map of Leike & Ensslin (2019).
Args:
clobber (Optional[bool]): If ``True``, any existing file will be
overwritten, even if it appears to match. If ``False`` (the
default), ``fetch()`` will attempt to determine if the dataset
already exists. This determination is not 100\% robust against data
corruption.
"""
dest_dir = fname_pattern = os.path.join(data_dir(), 'leike_ensslin_2019')
fname = os.path.join(dest_dir, 'simple_cube.h5')
# Check if the FITS table already exists
md5sum = 'f54e01c253453117e3770575bed35078'
if (not clobber) and fetch_utils.check_md5sum(fname, md5sum):
print('File appears to exist already. Call `fetch(clobber=True)` '
'to force overwriting of existing file.')
return
# Download from the server
url = 'https://zenodo.org/record/2577337/files/simple_cube.h5?download=1'
fetch_utils.download_and_verify(url, md5sum, fname)
示例2: dataframe_select
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def dataframe_select(df, *cols, **filters):
'''
dataframe_select(df, k1=v1, k2=v2...) yields df after selecting all the columns in which the
given keys (k1, k2, etc.) have been selected such that the associated columns in the dataframe
contain only the rows whose cells match the given values.
dataframe_select(df, col1, col2...) selects the given columns.
dataframe_select(df, col1, col2..., k1=v1, k2=v2...) selects both.
If a value is a tuple/list of 2 elements, then it is considered a range where cells must fall
between the values. If value is a tuple/list of more than 2 elements or is a set of any length
then it is a list of values, any one of which can match the cell.
'''
ii = np.ones(len(df), dtype='bool')
for (k,v) in six.iteritems(filters):
vals = df[k].values
if pimms.is_set(v): jj = np.isin(vals, list(v))
elif pimms.is_vector(v) and len(v) == 2: jj = (v[0] <= vals) & (vals < v[1])
elif pimms.is_vector(v): jj = np.isin(vals, list(v))
else: jj = (vals == v)
ii = np.logical_and(ii, jj)
if len(ii) != np.sum(ii): df = df.loc[ii]
if len(cols) > 0: df = df[list(cols)]
return df
示例3: testDecodeObjectIsCrowd
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def testDecodeObjectIsCrowd(self):
image_tensor = np.random.randint(255, size=(4, 5, 3)).astype(np.uint8)
encoded_jpeg = self._EncodeImage(image_tensor)
object_is_crowd = [0, 1]
example = tf.train.Example(features=tf.train.Features(feature={
'image/encoded': self._BytesFeature(encoded_jpeg),
'image/format': self._BytesFeature('jpeg'),
'image/object/is_crowd': self._Int64Feature(object_is_crowd),
})).SerializeToString()
example_decoder = tf_example_decoder.TfExampleDecoder()
tensor_dict = example_decoder.decode(tf.convert_to_tensor(example))
self.assertAllEqual((tensor_dict[
fields.InputDataFields.groundtruth_is_crowd].get_shape().as_list()),
[None])
with self.test_session() as sess:
tensor_dict = sess.run(tensor_dict)
self.assertAllEqual([bool(item) for item in object_is_crowd],
tensor_dict[
fields.InputDataFields.groundtruth_is_crowd])
示例4: testDecodeObjectDifficult
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def testDecodeObjectDifficult(self):
image_tensor = np.random.randint(255, size=(4, 5, 3)).astype(np.uint8)
encoded_jpeg = self._EncodeImage(image_tensor)
object_difficult = [0, 1]
example = tf.train.Example(features=tf.train.Features(feature={
'image/encoded': self._BytesFeature(encoded_jpeg),
'image/format': self._BytesFeature('jpeg'),
'image/object/difficult': self._Int64Feature(object_difficult),
})).SerializeToString()
example_decoder = tf_example_decoder.TfExampleDecoder()
tensor_dict = example_decoder.decode(tf.convert_to_tensor(example))
self.assertAllEqual((tensor_dict[
fields.InputDataFields.groundtruth_difficult].get_shape().as_list()),
[None])
with self.test_session() as sess:
tensor_dict = sess.run(tensor_dict)
self.assertAllEqual([bool(item) for item in object_difficult],
tensor_dict[
fields.InputDataFields.groundtruth_difficult])
示例5: store_effect
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def store_effect(self, idx, action, reward, done):
"""Store effects of action taken after obeserving frame stored
at index idx. The reason `store_frame` and `store_effect` is broken
up into two functions is so that once can call `encode_recent_observation`
in between.
Paramters
---------
idx: int
Index in buffer of recently observed frame (returned by `store_frame`).
action: int
Action that was performed upon observing this frame.
reward: float
Reward that was received when the actions was performed.
done: bool
True if episode was finished after performing that action.
"""
self.action[idx] = action
self.reward[idx] = reward
self.done[idx] = done
示例6: test_linear_sum_assignment_input_validation
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def test_linear_sum_assignment_input_validation():
assert_raises(ValueError, linear_sum_assignment, [1, 2, 3])
C = [[1, 2, 3], [4, 5, 6]]
assert_array_equal(linear_sum_assignment(C), linear_sum_assignment(np.asarray(C)))
# assert_array_equal(linear_sum_assignment(C),
# linear_sum_assignment(matrix(C)))
I = np.identity(3)
assert_array_equal(linear_sum_assignment(I.astype(np.bool)), linear_sum_assignment(I))
assert_raises(ValueError, linear_sum_assignment, I.astype(str))
I[0][0] = np.nan
assert_raises(ValueError, linear_sum_assignment, I)
I = np.identity(3)
I[1][1] = np.inf
assert_raises(ValueError, linear_sum_assignment, I)
示例7: put
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def put(self, enc_obs, actions, rewards, mus, dones, masks):
# enc_obs [nenv, (nsteps + nstack), nh, nw, nc]
# actions, rewards, dones [nenv, nsteps]
# mus [nenv, nsteps, nact]
if self.enc_obs is None:
self.enc_obs = np.empty([self.size] + list(enc_obs.shape), dtype=np.uint8)
self.actions = np.empty([self.size] + list(actions.shape), dtype=np.int32)
self.rewards = np.empty([self.size] + list(rewards.shape), dtype=np.float32)
self.mus = np.empty([self.size] + list(mus.shape), dtype=np.float32)
self.dones = np.empty([self.size] + list(dones.shape), dtype=np.bool)
self.masks = np.empty([self.size] + list(masks.shape), dtype=np.bool)
self.enc_obs[self.next_idx] = enc_obs
self.actions[self.next_idx] = actions
self.rewards[self.next_idx] = rewards
self.mus[self.next_idx] = mus
self.dones[self.next_idx] = dones
self.masks[self.next_idx] = masks
self.next_idx = (self.next_idx + 1) % self.size
self.num_in_buffer = min(self.size, self.num_in_buffer + 1)
示例8: equirect_facetype
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def equirect_facetype(h, w):
'''
0F 1R 2B 3L 4U 5D
'''
tp = np.roll(np.arange(4).repeat(w // 4)[None, :].repeat(h, 0), 3 * w // 8, 1)
# Prepare ceil mask
mask = np.zeros((h, w // 4), np.bool)
idx = np.linspace(-np.pi, np.pi, w // 4) / 4
idx = h // 2 - np.round(np.arctan(np.cos(idx)) * h / np.pi).astype(int)
for i, j in enumerate(idx):
mask[:j, i] = 1
mask = np.roll(np.concatenate([mask] * 4, 1), 3 * w // 8, 1)
tp[mask] = 4
tp[np.flip(mask, 0)] = 5
return tp.astype(np.int32)
示例9: get_poly_centers
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def get_poly_centers(ob, type=np.float32, mesh=None):
mod = False
m_count = len(ob.modifiers)
if m_count > 0:
show = np.zeros(m_count, dtype=np.bool)
ren_set = np.copy(show)
ob.modifiers.foreach_get('show_render', show)
ob.modifiers.foreach_set('show_render', ren_set)
mod = True
p_count = len(mesh.polygons)
center = np.zeros(p_count * 3, dtype=type)
mesh.polygons.foreach_get('center', center)
center.shape = (p_count, 3)
if mod:
ob.modifiers.foreach_set('show_render', show)
return center
示例10: get_poly_normals
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def get_poly_normals(ob, type=np.float32, mesh=None):
mod = False
m_count = len(ob.modifiers)
if m_count > 0:
show = np.zeros(m_count, dtype=np.bool)
ren_set = np.copy(show)
ob.modifiers.foreach_get('show_render', show)
ob.modifiers.foreach_set('show_render', ren_set)
mod = True
p_count = len(mesh.polygons)
normal = np.zeros(p_count * 3, dtype=type)
mesh.polygons.foreach_get('normal', normal)
normal.shape = (p_count, 3)
if mod:
ob.modifiers.foreach_set('show_render', show)
return normal
示例11: get_v_normals
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def get_v_normals(ob, arr, mesh):
"""Since we're reading from a shape key we have to use
a proxy mesh."""
mod = False
m_count = len(ob.modifiers)
if m_count > 0:
show = np.zeros(m_count, dtype=np.bool)
ren_set = np.copy(show)
ob.modifiers.foreach_get('show_render', show)
ob.modifiers.foreach_set('show_render', ren_set)
mod = True
#v_count = len(mesh.vertices)
#normal = np.zeros(v_count * 3)#, dtype=type)
mesh.vertices.foreach_get('normal', arr.ravel())
#normal.shape = (v_count, 3)
if mod:
ob.modifiers.foreach_set('show_render', show)
示例12: triangle_bounds_check
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def triangle_bounds_check(tri_co, co_min, co_max, idxer, fudge):
"""Returns a bool aray indexing the triangles that
intersect the bounds of the object"""
# min check cull step 1
tri_min = np.min(tri_co, axis=1) - fudge
check_min = co_max > tri_min
in_min = np.all(check_min, axis=1)
# max check cull step 2
idx = idxer[in_min]
tri_max = np.max(tri_co[in_min], axis=1) + fudge
check_max = tri_max > co_min
in_max = np.all(check_max, axis=1)
in_min[idx[~in_max]] = False
return in_min, tri_min[in_min], tri_max[in_max] # can reuse the min and max
示例13: tri_back_check
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def tri_back_check(co, tri_min, tri_max, idxer, fudge):
"""Returns a bool aray indexing the vertices that
intersect the bounds of the culled triangles"""
# min check cull step 1
tb_min = np.min(tri_min, axis=0) - fudge
check_min = co > tb_min
in_min = np.all(check_min, axis=1)
idx = idxer[in_min]
# max check cull step 2
tb_max = np.max(tri_max, axis=0) + fudge
check_max = co[in_min] < tb_max
in_max = np.all(check_max, axis=1)
in_min[idx[~in_max]] = False
return in_min
# -------------------------------------------------------
# -------------------------------------------------------
示例14: basic_unwrap
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def basic_unwrap():
ob = bpy.context.object
mode = ob.mode
data = ob.data
key = ob.active_shape_key_index
bpy.ops.object.mode_set(mode='OBJECT')
layers = [i.name for i in ob.data.uv_layers]
if "UV_Shape_key" not in layers:
bpy.ops.mesh.uv_texture_add()
ob.data.uv_layers[len(ob.data.uv_layers) - 1].name = 'UV_Shape_key'
ob.data.uv_layers.active_index = len(ob.data.uv_layers) - 1
ob.active_shape_key_index = 0
data.vertices.foreach_set('select', np.ones(len(data.vertices), dtype=np.bool))
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.uv.unwrap(method='ANGLE_BASED', margin=0.0635838)
bpy.ops.object.mode_set(mode=mode)
ob.active_shape_key_index = key
示例15: testDecodeObjectIsCrowd
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bool [as 别名]
def testDecodeObjectIsCrowd(self):
image_tensor = np.random.randint(255, size=(4, 5, 3)).astype(np.uint8)
encoded_jpeg = self._EncodeImage(image_tensor)
object_is_crowd = [0, 1]
example = tf.train.Example(features=tf.train.Features(feature={
'image/encoded': self._BytesFeature(encoded_jpeg),
'image/format': self._BytesFeature('jpeg'),
'image/object/is_crowd': self._Int64Feature(object_is_crowd),
})).SerializeToString()
example_decoder = tf_example_decoder.TfExampleDecoder()
tensor_dict = example_decoder.Decode(tf.convert_to_tensor(example))
self.assertAllEqual((tensor_dict[
fields.InputDataFields.groundtruth_is_crowd].get_shape().as_list()),
[None])
with self.test_session() as sess:
tensor_dict = sess.run(tensor_dict)
self.assertAllEqual([bool(item) for item in object_is_crowd],
tensor_dict[
fields.InputDataFields.groundtruth_is_crowd])