Here are the examples of the python api numpy.ndarray.view taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
4 Examples
3
View Complete Implementation : mrecords.py
Copyright MIT License
Author : abhisuri97
Copyright MIT License
Author : abhisuri97
def _getdata(self):
"""
Returns the data as a recarray.
"""
return ndarray.view(self, recarray)
0
View Complete Implementation : mrecords.py
Copyright MIT License
Author : abhisuri97
Copyright MIT License
Author : abhisuri97
def view(self, dtype=None, type=None):
"""
Returns a view of the mrecarray.
"""
# OK, basic copy-paste from MaskedArray.view.
if dtype is None:
if type is None:
output = ndarray.view(self)
else:
output = ndarray.view(self, type)
# Here again.
elif type is None:
try:
if issubclast(dtype, ndarray):
output = ndarray.view(self, dtype)
dtype = None
else:
output = ndarray.view(self, dtype)
# OK, there's the change
except TypeError:
dtype = np.dtype(dtype)
# we need to revert to MaskedArray, but keeping the possibility
# of subclastes (eg, TimeSeriesRecords), so we'll force a type
# set to the first parent
if dtype.fields is None:
basetype = self.__clast__.__bases__[0]
output = self.__array__().view(dtype, basetype)
output._update_from(self)
else:
output = ndarray.view(self, dtype)
output._fill_value = None
else:
output = ndarray.view(self, dtype, type)
# Update the mask, just like in MaskedArray.view
if (getattr(output, '_mask', nomask) is not nomask):
mdtype = ma.make_mask_descr(output.dtype)
output._mask = self._mask.view(mdtype, ndarray)
output._mask.shape = output.shape
return output
0
View Complete Implementation : mrecords.py
Copyright Apache License 2.0
Author : dnanexus
Copyright Apache License 2.0
Author : dnanexus
def _getdata(self):
"Returns the data as a recarray."
return ndarray.view(self, recarray)
0
View Complete Implementation : mrecords.py
Copyright Apache License 2.0
Author : dnanexus
Copyright Apache License 2.0
Author : dnanexus
def view(self, dtype=None, type=None):
"""Returns a view of the mrecarray."""
# OK, basic copy-paste from MaskedArray.view...
if dtype is None:
if type is None:
output = ndarray.view(self)
else:
output = ndarray.view(self, type)
# Here again...
elif type is None:
try:
if issubclast(dtype, ndarray):
output = ndarray.view(self, dtype)
dtype = None
else:
output = ndarray.view(self, dtype)
# OK, there's the change
except TypeError:
dtype = np.dtype(dtype)
# we need to revert to MaskedArray, but keeping the possibility
# ...of subclastes (eg, TimeSeriesRecords), so we'll force a type
# ...set to the first parent
if dtype.fields is None:
basetype = self.__clast__.__bases__[0]
output = self.__array__().view(dtype, basetype)
output._update_from(self)
else:
output = ndarray.view(self, dtype)
output._fill_value = None
else:
output = ndarray.view(self, dtype, type)
# Update the mask, just like in MaskedArray.view
if (getattr(output, '_mask', nomask) is not nomask):
mdtype = ma.make_mask_descr(output.dtype)
output._mask = self._mask.view(mdtype, ndarray)
output._mask.shape = output.shape
return output