本文整理汇总了Python中numpy.__name__方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.__name__方法的具体用法?Python numpy.__name__怎么用?Python numpy.__name__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.__name__方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _model_to_dict
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __name__ [as 别名]
def _model_to_dict(model):
"""Convert a sklearn model object to a dictionary"""
dictionary = {
"module": type(model).__module__,
"class": type(model).__name__,
"params": model.get_params(deep=True),
"coefs": {
attr: copy.deepcopy(getattr(model, attr))
for attr in model.__dir__()
if not attr.startswith("__") and attr.endswith("_")
}
}
if "tree_" in dictionary["coefs"]:
# Not funny. sklearn.tree objects are not directly
# serializable to json. Hence, we must dump them by ourselves.
dictionary["coefs"]["tree_"] = RetrievalProduct._tree_to_dict(
dictionary["coefs"]["tree_"]
)
return RetrievalProduct._encode_numpy(dictionary)
示例2: count_params
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __name__ [as 别名]
def count_params(self):
"""Count the total number of scalars composing the weights.
Returns:
An integer count.
Raises:
RuntimeError: if the layer isn't yet built
(in which case its weights aren't yet defined).
"""
if not self.built:
if self.__class__.__name__ == 'Sequential':
self.build() # pylint: disable=no-value-for-parameter
else:
raise RuntimeError('You tried to call `count_params` on ' + self.name +
', but the layer isn\'t built. '
'You can build it manually via: `' + self.name +
'.build(batch_input_shape)`.')
return sum([K.count_params(p) for p in self.weights])
示例3: _updated_config
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __name__ [as 别名]
def _updated_config(self):
"""Util hared between different serialization methods.
Returns:
Model config with Keras version information added.
"""
from tensorflow.contrib.keras.python.keras import __version__ as keras_version # pylint: disable=g-import-not-at-top
config = self.get_config()
model_config = {
'class_name': self.__class__.__name__,
'config': config,
'keras_version': keras_version,
'backend': K.backend()
}
return model_config
示例4: _updated_config
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __name__ [as 别名]
def _updated_config(self):
"""Util hared between different serialization methods.
# Returns
Model config with Keras version information added.
"""
from .. import __version__ as keras_version
config = self.get_config()
model_config = {
'class_name': self.__class__.__name__,
'config': config,
'keras_version': keras_version,
'backend': K.backend()
}
return model_config
示例5: to_json
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __name__ [as 别名]
def to_json(self, **kwargs):
"""Returns a JSON string containing the timeseries generator
configuration. To load a generator from a JSON string, use
`keras.preprocessing.sequence.timeseries_generator_from_json(json_string)`.
# Arguments
**kwargs: Additional keyword arguments
to be passed to `json.dumps()`.
# Returns
A JSON string containing the tokenizer configuration.
"""
config = self.get_config()
timeseries_generator_config = {
'class_name': self.__class__.__name__,
'config': config
}
return json.dumps(timeseries_generator_config, **kwargs)
示例6: test_linear_regression_numpy
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __name__ [as 别名]
def test_linear_regression_numpy(self):
""" Test the linear regression using numpy (if installed). """
# test that numpy is installed
try:
import numpy
numpy.__name__
except ImportError:
raise unittest.SkipTest('cannot test as optional numpy is not installed')
# perform the test with numpy
from supvisors.utils import get_linear_regression, get_simple_linear_regression
xdata = [2, 4, 6, 8, 10, 12]
ydata = [3, 4, 5, 6, 7, 8]
# test linear regression
a, b = get_linear_regression(xdata, ydata)
self.assertAlmostEqual(0.5, a)
self.assertAlmostEqual(2.0, b)
# test simple linear regression
a, b = get_simple_linear_regression(ydata)
self.assertAlmostEqual(1.0, a)
self.assertAlmostEqual(3.0, b)
示例7: init_backends
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __name__ [as 别名]
def init_backends():
init_environment()
# populate available backend modules
global BACKENDS
BACKENDS = {}
import numpy
if numpy.__name__ == 'bohrium':
logger.warning('Running veros with "python -m bohrium" is discouraged '
'(use "--backend bohrium" instead)')
import numpy_force
numpy = numpy_force
BACKENDS['numpy'] = numpy
try:
import bohrium
except ImportError:
logger.warning('Could not import Bohrium (Bohrium backend will be unavailable)')
BACKENDS['bohrium'] = None
else:
BACKENDS['bohrium'] = bohrium
示例8: _clean
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __name__ [as 别名]
def _clean(value):
""" Convert numpy numeric types to their python equivalents. """
if isinstance(value, np.ndarray):
if value.dtype.kind == 'S':
return np.char.decode(value).tolist()
else:
return value.tolist()
elif type(value).__module__ == np.__name__:
# h5py==2.8.0 on windows sometimes fails to cast this from an np.float64 to a python.float
# We have to let the user do this themselves, since casting here could be dangerous
# https://github.com/h5py/h5py/issues/1051
conversion = value.item() # np.asscalar(value) was deprecated in v1.16
if isinstance(conversion, bytes):
conversion = conversion.decode()
return conversion
elif isinstance(value, bytes):
return value.decode()
else:
return value
示例9: type_to_builtin_type
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __name__ [as 别名]
def type_to_builtin_type(type):
# Infer from numpy type if it is one
if type.__module__ == np.__name__:
return numpy_type_to_builtin_type(type)
# Otherwise, try to infer from a few generic python types
if np.issubclass_(type, bool):
return types_bool
elif np.issubclass_(type, six.integer_types):
return types_int32
elif np.issubclass_(type, six.string_types):
return types_str
elif np.issubclass_(type, float):
return types_fp32
else:
raise TypeError("Could not determine builtin type for " + str(type))
示例10: all_same
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __name__ [as 别名]
def all_same(val_array):
'''
Check if all the values in given list the same
Parameters
----------
numpy_list: numpy array
'''
# check if val_array is a numpy array
if type(val_array).__module__ == np.__name__:
val = val_array.tolist()
if isinstance(val[0], list):
#handle list of lists
return all(round(x[0]) == round(val[0][0]) for x in val)
else:
#handle single list
return all(round(x) == round(val[0]) for x in val)
else:
raise Exception('This function only takes a numpy array')
示例11: face_covered_frame
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __name__ [as 别名]
def face_covered_frame(self, input_frame_with_faces):
"""Function to draw black recs over detected faces.
This function remove eny 'noise' and help detector detecting palm.
:param input_frame_with_faces (np.ndarray): a frame with faces, that needed to be covered.
"""
try:
# make sure input is np.ndarray
assert type(input_frame_with_faces).__module__ == np.__name__
except AssertionError as error:
self.logger.exception(error)
return
# Preparation
self._preprocessed_input_frame = input_frame_with_faces.copy()
gray = cv2.cvtColor(self._preprocessed_input_frame, cv2.COLOR_BGR2GRAY)
faces = self._face_detector.detectMultiScale(gray, 1.3, 5)
# Black rectangle over faces to remove skin noises.
for (x, y, w, h) in faces:
self._preprocessed_input_frame[y - self._face_padding_y:y + h + self._face_padding_y,
x - self._face_padding_x:x + w + self._face_padding_x, :] = 0
示例12: compute_output_shape
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __name__ [as 别名]
def compute_output_shape(self, input_shape):
"""Computes the output shape of the layer.
Assumes that the layer will be built
to match that input shape provided.
# Arguments
input_shape: Shape tuple (tuple of integers)
or list of shape tuples (one per output tensor of the layer).
Shape tuples can include None for free dimensions,
instead of an integer.
# Returns
An input shape tuple.
"""
if hasattr(self, 'get_output_shape_for'):
msg = "Class `{}.{}` defines `get_output_shape_for` but does not override `compute_output_shape`. " + \
"If this is a Keras 1 layer, please implement `compute_output_shape` to support Keras 2."
warnings.warn(msg.format(type(self).__module__, type(self).__name__), stacklevel=2)
return input_shape
示例13: count_params
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import __name__ [as 别名]
def count_params(self):
"""Counts the total number of scalars composing the weights.
# Returns
An integer count.
# Raises
RuntimeError: if the layer isn't yet built
(in which case its weights aren't yet defined).
"""
if not self.built:
if self.__class__.__name__ == 'Sequential':
self.build()
else:
raise RuntimeError('You tried to call `count_params` on ' +
self.name + ', but the layer isn\'t built. '
'You can build it manually via: `' +
self.name + '.build(batch_input_shape)`.')
return count_params(self.weights)