本文整理汇总了Python中axes.Axes._init方法的典型用法代码示例。如果您正苦于以下问题:Python Axes._init方法的具体用法?Python Axes._init怎么用?Python Axes._init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类axes.Axes
的用法示例。
在下文中一共展示了Axes._init方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: empty
# 需要导入模块: from axes import Axes [as 别名]
# 或者: from axes.Axes import _init [as 别名]
def empty(axes=None, dims=None, shape=None, dtype=float):
""" Initialize an empty array
axes and dims have the same meaning as DimArray's initializer
shape, optional: can be provided in combination with `dims`
if `axes=` is omitted.
>>> a = empty([('time',[2000,2001]),('items',['a','b','c'])])
>>> a.fill(3)
>>> a
dimarray: 6 non-null elements (0 null)
dimensions: 'time', 'items'
0 / time (2): 2000 to 2001
1 / items (3): a to c
array([[ 3., 3., 3.],
[ 3., 3., 3.]])
>>> b = empty(dims=('time','items'), shape=(2, 3))
See also:
---------
empty_like, ones, zeros, nans
"""
axes = Axes._init(axes, dims=dims, shape=shape)
if shape is None:
shape = [ax.size for ax in axes]
values = np.empty(shape, dtype=dtype)
return DimArray(values, axes=axes, dims=dims)
示例2: __init__
# 需要导入模块: from axes import Axes [as 别名]
# 或者: from axes.Axes import _init [as 别名]
def __init__(self, values=None, axes=None, dims=None, labels=None, copy=False, dtype=None, _indexing=None, _indexing_broadcast=None, **kwargs):
""" Initialization. See help on DimArray.
"""
# check if attached to values (e.g. DimArray object)
if hasattr(values, "axes") and axes is None:
axes = values.axes
# default options
if _indexing is None: _indexing = get_option('indexing.by')
if _indexing_broadcast is None: _indexing_broadcast = get_option('indexing.broadcast')
#
# array values
#
# if masked array, replace mask by NaN
if isinstance(values, np.ma.MaskedArray):
try:
values = values.filled(np.nan) # fill mask with nans
# first convert to float
except:
values = np.ma.asarray(values, dtype=float).filled(np.nan) # fill mask with nans
if values is not None:
values = np.array(values, copy=copy, dtype=dtype)
#
# Initialize the axes
#
if axes is None and labels is None:
assert values is not None, "values= or/and axes=, labels= required to determine dimensions"
axes = Axes._init(axes, dims=dims, labels=labels, shape=values.shape if values is not None else None)
assert type(axes) is Axes
# if values not provided, create empty data, filled with NaNs if dtype is float
if values is None:
values = np.empty([ax.size for ax in axes], dtype=dtype)
if dtype in (float, None, np.dtype(float)):
values.fill(np.nan)
else:
warnings.warn("no nan representation for {}, array left empty".format(repr(dtype)))
#
# store all fields
#
self.values = values
self.axes = axes
## options
self._indexing = _indexing
self._indexing_broadcast = _indexing_broadcast
#
# metadata (see Metadata type in metadata.py)
#
#for k in kwargs:
# setncattr(self, k, kwargs[k]) # perform type-checking and store in self._metadata
self._metadata = kwargs
# Check consistency between axes and values
inferred = tuple([ax.size for ax in self.axes])
if inferred != self.values.shape:
msg = """\
shape inferred from axes: {}
shape inferred from data: {}
mismatch between values and axes""".format(inferred, self.values.shape)
raise Exception(msg)
# If a general ordering relationship of the class is assumed,
# always sort the class
if self._order is not None and self.dims != tuple(dim for dim in self._order if dim in self.dims):
present = filter(lambda x: x in self.dims, self._order) # prescribed
missing = filter(lambda x: x not in self._order, self.dims) # not
order = missing + present # prepend dimensions not found in ordering relationship
obj = self.transpose(order)
self.values = obj.values
self.axes = obj.axes