本文整理汇总了Python中numpy.__dict__方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.__dict__方法的具体用法?Python numpy.__dict__怎么用?Python numpy.__dict__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.__dict__方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_fake_data
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __dict__ [as 别名]
def get_fake_data():
# try to evaluate the source script
try:
# first get all the extra numpy globals
g = _n.__dict__
# update these globals with extra stuff needed for evaluation
g.update(dict(t=d1[0]+s["settings/simulated_input/noise"]*_n.random.rand()))
y = eval(s["settings/simulated_input/source"], g)+_n.random.random(len(d1['t']))
# default to zeros
except:
print("ERROR: Invalid source script.")
y = d1[0]*0.0
# pretend this acquisition actually took time (avoids black holes)
_t.sleep(s["settings/simulated_input/duration"])
return y
# define a function to be called whenever the acquire button is pressed
示例2: _globals
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __dict__ [as 别名]
def _globals(self):
"""
Returns the globals needed for eval() statements.
"""
# start with numpy
globbies = dict(_n.__dict__)
globbies.update(_special.__dict__)
# update with required stuff
globbies.update({'h':self.h, 'c':self.c, 'd':self, 'self':self})
# update with user stuff
globbies.update(self.extra_globals)
return globbies
示例3: _rescale
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __dict__ [as 别名]
def _rescale(arr, ndv, dst_dtype, out_alpha=True):
"""Convert an array from output dtype, scaling up linearly
"""
if dst_dtype == np.__dict__['uint16']:
scale = 1
else:
# convert to 8bit value range in place
scale = float(np.iinfo(np.uint16).max) / float(np.iinfo(np.uint8).max)
res = (arr / scale).astype(dst_dtype)
if out_alpha:
mask = _simple_mask(
arr.astype(dst_dtype),
(ndv, ndv, ndv)).reshape(
1, arr.shape[1], arr.shape[2])
return np.concatenate([res, mask])
else:
return res
示例4: test_pansharp_data
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __dict__ [as 别名]
def test_pansharp_data():
b8_path = 'tests/fixtures/tiny_20_tiffs/LC81070352015122LGN00/'\
'LC81070352015122LGN00_B8.tif'
b4_path = 'tests/fixtures/tiny_20_tiffs/LC81070352015122LGN00/'\
'LC81070352015122LGN00_B4.tif'
b3_path = 'tests/fixtures/tiny_20_tiffs/LC81070352015122LGN00/'\
'LC81070352015122LGN00_B3.tif'
b2_path = 'tests/fixtures/tiny_20_tiffs/LC81070352015122LGN00/'\
'LC81070352015122LGN00_B2.tif'
band_paths = [b8_path, b4_path, b3_path, b2_path]
pan_window = ((1536, 1792), (1280, 1536))
g_args = {'half_window': False,
'dst_aff': Affine(75.00483870967741, 0.0, 300892.5,
0.0, -75.00475285171103, 4107007.5),
'verb': False, 'weight': 0.2,
'dst_crs': {'init': u'epsg:32654'},
'r_crs': {'init': u'epsg:32654'},
'dst_dtype': np.__dict__['uint16'],
'r_aff': Affine(150.0193548387097, 0.0, 300885.0,
0.0, -150.0190114068441, 4107015.0),
'src_nodata': 0}
return [rasterio.open(f) for f in band_paths],\
pan_window, (6, 5), g_args
示例5: nbytes
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __dict__ [as 别名]
def nbytes(self):
""" number of bytes of the object """
n = sum(k.nbytes if hasattr(k, 'nbytes') else sys.getsizeof(k)
for k in self.__dict__.values())
return n
示例6: evalexpr
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __dict__ [as 别名]
def evalexpr(self, expr, exprvars=None, dtype=float):
""" evaluate expression based on the data and external variables
all np function can be used (log, exp, pi...)
Parameters
----------
expr: str
expression to evaluate on the table
includes mathematical operations and attribute names
exprvars: dictionary, optional
A dictionary that replaces the local operands in current frame.
dtype: dtype definition
dtype of the output array
Returns
-------
out : NumPy array
array of the result
"""
_globals = {}
for k in ( list(self.colnames) + list(self._aliases.keys()) ):
if k in expr:
_globals[k] = self[k]
if exprvars is not None:
if (not (hasattr(exprvars, 'keys') & hasattr(exprvars, '__getitem__' ))):
raise AttributeError("Expecting a dictionary-like as condvars")
for k, v in ( exprvars.items() ):
_globals[k] = v
# evaluate expression, to obtain the final filter
r = np.empty( self.nrows, dtype=dtype)
r[:] = eval(expr, _globals, np.__dict__)
return r
示例7: test_initialization
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __dict__ [as 别名]
def test_initialization():
""" Test structure initialization. """
a = Structure()
assert all(abs(a.cell - identity(3)) < 1e-8)
assert abs(a.scale - 1e0 * angstrom) < 1e0
assert len(a.__dict__) == 3
a = Structure(identity(3) * 2.5, scale=5.45)
assert all(abs(a.cell - identity(3) * 2.5) < 1e-8)
assert abs(a.scale - 5.45 * angstrom) < 1e0
assert len(a.__dict__) == 3
a = Structure(identity(3) * 2.5, scale=0.545 * nanometer)
assert all(abs(a.cell - identity(3) * 2.5) < 1e-8)
assert abs(a.scale - 5.45 * angstrom) < 1e0
assert len(a.__dict__) == 3
a = Structure(2.5, 0, 0, 0, 2.5, 0, 0, 0, 2.5, scale=5.45)
assert all(abs(a.cell - identity(3) * 2.5) < 1e-8)
assert abs(a.scale - 5.45 * angstrom) < 1e0
assert len(a.__dict__) == 3
a = Structure([2.5, 0, 0], [0, 2.5, 0], [0, 0, 2.5], scale=5.45)
assert all(abs(a.cell - identity(3) * 2.5) < 1e-8)
assert abs(a.scale - 5.45 * angstrom) < 1e0
assert len(a.__dict__) == 3
a = Structure(cell=[[2.5, 0, 0], [0, 2.5, 0], [0, 0, 2.5]], scale=5.45)
assert all(abs(a.cell - identity(3) * 2.5) < 1e-8)
assert abs(a.scale - 5.45 * angstrom) < 1e0
assert len(a.__dict__) == 3
a = Structure(identity(3) * 2.5, scale=5.45, m=True)
assert all(abs(a.cell - identity(3) * 2.5) < 1e-8)
assert abs(a.scale - 5.45 * angstrom) < 1e0
assert len(a.__dict__) == 4 and getattr(a, 'm', False)
示例8: test_representability
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __dict__ [as 别名]
def test_representability():
import quantities
import numpy
dictionary = {Structure.__name__: Structure}
dictionary.update(numpy.__dict__)
dictionary.update(quantities.__dict__)
expected = Structure()
actual = eval(repr(expected), dictionary)
assert all(abs(expected.cell - actual.cell) < 1e-8)
assert abs(expected.scale - actual.scale) < 1e-8
assert len(expected) == len(actual)
expected = Structure([1, 2, 0], [3, 4, 5], [6, 7, 8], m=True)
actual = eval(repr(expected), dictionary)
assert all(abs(expected.cell - actual.cell) < 1e-8)
assert abs(expected.scale - actual.scale) < 1e-8
assert len(expected) == len(actual)
assert getattr(expected, 'm', False) == actual.m
expected = Structure([1, 2, 0], [3, 4, 5], [6, 7, 8], m=True) \
.add_atom(0, 1, 2, "Au", m=5) \
.add_atom(0, -1, -2, "Pd")
actual = eval(repr(expected), dictionary)
assert all(abs(expected.cell - actual.cell) < 1e-8)
assert abs(expected.scale - actual.scale) < 1e-8
assert len(expected) == len(actual)
assert all(abs(expected[0].pos - actual[0].pos) < 1e-8)
assert getattr(expected[0], 'm', 0) == actual[0].m
assert expected[0].type == actual[0].type
assert all(abs(expected[1].pos - actual[1].pos) < 1e-8)
assert expected[1].type == actual[1].type
assert getattr(expected, 'm', False) == actual.m
示例9: substitute_with_eval
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __dict__ [as 别名]
def substitute_with_eval(expression: sympy.Expr,
substitutions: Dict[str, Union[sympy.Expr, numpy.ndarray, str]]) -> sympy.Expr:
"""Substitutes only sympy.Symbols. Workaround for numpy like array behaviour. ~Factor 3 slower compared to subs"""
substitutions = {k: v if isinstance(v, sympy.Expr) else sympify(v)
for k, v in substitutions.items()}
for symbol in get_free_symbols(expression):
symbol_name = str(symbol)
if symbol_name not in substitutions:
substitutions[symbol_name] = symbol
string_representation = sympy.srepr(expression)
return eval(string_representation, sympy.__dict__, {'Symbol': substitutions.__getitem__,
'Mul': numpy_compatible_mul})
示例10: test_pansharpen_worker_uint8
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __dict__ [as 别名]
def test_pansharpen_worker_uint8(test_pansharp_data):
open_files, pan_window, _, g_args = test_pansharp_data
g_args.update(dst_dtype=np.__dict__['uint8'])
pan_output = _pansharpen_worker(open_files, pan_window, _, g_args)
assert pan_output.dtype == np.uint8
assert np.max(pan_output) <= 2**8
示例11: test_rescale
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __dict__ [as 别名]
def test_rescale(arr, ndv, dst_dtype):
if dst_dtype == np.__dict__['uint16']:
assert np.array_equal(
_rescale(arr, ndv, dst_dtype),
np.concatenate(
[
(arr).astype(dst_dtype),
_simple_mask(
arr.astype(dst_dtype),
(ndv, ndv, ndv)
).reshape(1, arr.shape[1], arr.shape[2])
]
)
)
else:
assert np.array_equal(
_rescale(arr, ndv, dst_dtype),
np.concatenate(
[
(arr / 257.0).astype(dst_dtype),
_simple_mask(
arr.astype(dst_dtype),
(ndv, ndv, ndv)
).reshape(1, arr.shape[1], arr.shape[2])
]
)
)
# Testing make_windows_block function's random element
示例12: select
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __dict__ [as 别名]
def select(self, fields, indices=None, **kwargs):
"""
Select only a few fields in the table
Parameters
----------
fields: str or sequence
fields to keep in the resulting table
indices: sequence or slice
extract only on these indices
returns
-------
tab: SimpleTable instance
resulting table
"""
_fields = self.keys(fields)
if fields == '*':
if indices is None:
return self
else:
tab = self.__class__(self[indices])
for k in self.__dict__.keys():
if k not in ('data', ):
setattr(tab, k, deepcopy(self.__dict__[k]))
return tab
else:
d = {}
for k in _fields:
_k = self.resolve_alias(k)
if indices is not None:
d[k] = self[_k][indices]
else:
d[k] = self[_k]
d['header'] = deepcopy(self.header)
tab = self.__class__(d)
for k in self.__dict__.keys():
if k not in ('data', ):
setattr(tab, k, deepcopy(self.__dict__[k]))
return tab
示例13: load_values
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __dict__ [as 别名]
def load_values(dir_logs, metrics, nb_epochs=-1, best=None):
json_files = {}
values = {}
# load argsup of best
if best:
if best['json'] not in json_files:
with open(osp.join(dir_logs, f'{best["json"]}.json')) as f:
json_files[best['json']] = json.load(f)
jfile = json_files[best['json']]
vals = jfile[best['name']]
end = len(vals) if nb_epochs == -1 else nb_epochs
argsup = np.__dict__[f'arg{best["order"]}'](vals[:end])
# load logs
for _key, metric in metrics.items():
# open json_files
if metric['json'] not in json_files:
with open(osp.join(dir_logs, f'{metric["json"]}.json')) as f:
json_files[metric['json']] = json.load(f)
jfile = json_files[metric['json']]
if 'train' in metric['name']:
epoch_key = 'train_epoch.epoch'
else:
epoch_key = 'eval_epoch.epoch'
if epoch_key in jfile:
epochs = jfile[epoch_key]
else:
epochs = jfile['epoch']
vals = jfile[metric['name']]
if not best:
end = len(vals) if nb_epochs == -1 else nb_epochs
argsup = np.__dict__[f'arg{metric["order"]}'](vals[:end])
try:
values[metric['name']] = epochs[argsup], vals[argsup]
except IndexError:
values[metric['name']] = epochs[argsup - 1], vals[argsup - 1]
return values