本文整理汇总了Python中numpy.iinfo函数的典型用法代码示例。如果您正苦于以下问题:Python iinfo函数的具体用法?Python iinfo怎么用?Python iinfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iinfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_noise
def add_noise(sim):
det_left = sim.outarr[:, :sim.nxpix]
det_mid = sim.outarr[:, sim.nxpix:2*sim.nxpix]
det_right = sim.outarr[:, 2*sim.nxpix:3*sim.nxpix]
shape = det_left.shape
det_left += det_bias(sim.dl_bias, det="left")
det_mid += det_bias(sim.dm_bias, det="middle")
det_right += det_bias(sim.dr_bias, det="right")
det_left += readout_noise(sim.dl_ron, shape, det="left")
det_mid += readout_noise(sim.dm_ron, shape, det="middle")
det_right += readout_noise(sim.dr_ron, shape, det="right")
det_left += dark_current(sim.dl_dc, sim.tobs, shape, det="left")
det_mid += dark_current(sim.dm_dc, sim.tobs, shape, det="middle")
det_right += dark_current(sim.dr_dc, sim.tobs, shape, det="right")
sim.outarr = gain(sim.outarr, sim.inv_gain)
if sim.outarr.max() > np.iinfo(np.uint16).max:
log.info("Clipping array values larger than %s.", np.iinfo(np.uint16).max)
sim.outarr[sim.outarr > np.iinfo(np.uint16).max] = np.iinfo(np.uint16).max
sim.outarr = np.asarray(sim.outarr, dtype=np.uint16)
log.info("Converting image array back to %s.", sim.outarr.dtype)
示例2: test_implementation_limits
def test_implementation_limits(self):
min_td = Timedelta(Timedelta.min)
max_td = Timedelta(Timedelta.max)
# GH 12727
# timedelta limits correspond to int64 boundaries
assert min_td.value == np.iinfo(np.int64).min + 1
assert max_td.value == np.iinfo(np.int64).max
# Beyond lower limit, a NAT before the Overflow
assert (min_td - Timedelta(1, 'ns')) is NaT
with pytest.raises(OverflowError):
min_td - Timedelta(2, 'ns')
with pytest.raises(OverflowError):
max_td + Timedelta(1, 'ns')
# Same tests using the internal nanosecond values
td = Timedelta(min_td.value - 1, 'ns')
assert td is NaT
with pytest.raises(OverflowError):
Timedelta(min_td.value - 2, 'ns')
with pytest.raises(OverflowError):
Timedelta(max_td.value + 1, 'ns')
示例3: able_int_type
def able_int_type(values):
""" Find the smallest integer numpy type to contain sequence `values`
Prefers uint to int if minimum is >= 0
Parameters
----------
values : sequence
sequence of integer values
Returns
-------
itype : None or numpy type
numpy integer type or None if no integer type holds all `values`
Examples
--------
>>> able_int_type([0, 1]) == np.uint8
True
>>> able_int_type([-1, 1]) == np.int8
True
"""
if any([v % 1 for v in values]):
return None
mn = min(values)
mx = max(values)
if mn >= 0:
for ityp in np.sctypes['uint']:
if mx <= np.iinfo(ityp).max:
return ityp
for ityp in np.sctypes['int']:
info = np.iinfo(ityp)
if mn >= info.min and mx <= info.max:
return ityp
return None
示例4: testInfNan
def testInfNan(self):
i4 = np.iinfo(np.int32)
i8 = np.iinfo(np.int64)
self._compare(np.inf, np.float32, np.inf, False)
self._compare(np.inf, np.float64, np.inf, False)
if sys.byteorder == "big":
self._compare(np.inf, np.int32, i4.max, False)
self._compare(np.inf, np.int64, i8.max, False)
else:
# np.float64("np.inf").astype(np.int32) is negative on x86 but positive on ppc64le
# Numpy link to relevant discussion - https://github.com/numpy/numpy/issues/9040
# Tensorflow link to relevant discussion - https://github.com/tensorflow/tensorflow/issues/9360
if platform.machine() == "ppc64le":
self._compare(-np.inf, np.int32, i4.min, False)
self._compare(-np.inf, np.int64, i8.min, False)
else:
self._compare(np.inf, np.int32, i4.min, False)
self._compare(np.inf, np.int64, i8.min, False)
self._compare(-np.inf, np.float32, -np.inf, False)
self._compare(-np.inf, np.float64, -np.inf, False)
self._compare(-np.inf, np.int32, i4.min, False)
self._compare(-np.inf, np.int64, i8.min, False)
self.assertAllEqual(np.isnan(self._cast(np.nan, np.float32, False)), True)
self.assertAllEqual(np.isnan(self._cast(np.nan, np.float64, False)), True)
self._compare(np.nan, np.int32, i4.min, False)
self._compare(np.nan, np.int64, i8.min, False)
self._compare(np.inf, np.float32, np.inf, True)
self._compare(np.inf, np.float64, np.inf, True)
self._compare(-np.inf, np.float32, -np.inf, True)
self._compare(-np.inf, np.float64, -np.inf, True)
self.assertAllEqual(np.isnan(self._cast(np.nan, np.float32, True)), True)
self.assertAllEqual(np.isnan(self._cast(np.nan, np.float64, True)), True)
示例5: initBuffers
def initBuffers(self,puzzle):
#define lengths buffer and copy to the GPU
#as we will not read from this buffer later, mapping is not required
self.lengths = np.full(self.simulations,np.iinfo(np.int16).max,dtype=np.int16)
self.lengthsBuffer = cl.Buffer(self.context, cl.mem_flags.READ_WRITE | cl.mem_flags.COPY_HOST_PTR, hostbuf=self.lengths)
#define buffer for aggregated lengths for each workgroup
self.groupLengths = np.full(self.workGroups,np.iinfo(np.int16).max,dtype=np.int16)
self.groupLengthsBuffer = cl.Buffer(self.context, cl.mem_flags.READ_WRITE | cl.mem_flags.USE_HOST_PTR, hostbuf=self.groupLengths)
#map group lengths buffer
cl.enqueue_map_buffer(self.queue,self.groupLengthsBuffer,cl.map_flags.READ,0,self.groupLengths.shape,self.groupLengths.dtype)
#get the input puzzle ready for the kernel; convert to 8 bit int (char)
p = np.array(puzzle['puzzle']).astype(np.int8)
#subtract 1 so that -1 denotes a gap and 0 denotes a square to be filled
p = p - np.ones_like(p,dtype=p.dtype)
#copy the puzzle, one for each simulation
self.puzzles = np.zeros((self.simulations,self.height,self.width),dtype=p.dtype)
self.puzzles[:,0:self.height,0:self.width] = p
#define puzzles buffer and copy data (we do not need to worry about getting data out of this buffer, so mapping isn't required)
#this buffer contains the input puzzles, one for each invocation (the puzzle is too large to hold in local or shared memory)
self.puzzlesFlattened = self.puzzles.ravel()
self.puzzlesBuffer = cl.Buffer(self.context, cl.mem_flags.READ_WRITE | cl.mem_flags.COPY_HOST_PTR, hostbuf=self.puzzlesFlattened)
#define output buffer for best solutions aggregated across workgroups
self.solutions = self.puzzles[0:self.workGroups]
self.solutionsFlattened = self.solutions.ravel()
self.solutionsBuffer = cl.Buffer(self.context, cl.mem_flags.READ_WRITE | cl.mem_flags.USE_HOST_PTR, hostbuf=self.solutionsFlattened)
#map solutions buffer
cl.enqueue_map_buffer(self.queue,self.solutionsBuffer,cl.map_flags.READ,0,self.solutionsFlattened.shape,self.solutions.dtype)
示例6: _random_integers
def _random_integers(size, dtype):
# We do not generate integers outside the int64 range
platform_int_info = np.iinfo('int_')
iinfo = np.iinfo(dtype)
return np.random.randint(max(iinfo.min, platform_int_info.min),
min(iinfo.max, platform_int_info.max),
size=size).astype(dtype)
示例7: test_implementation_limits
def test_implementation_limits(self):
min_td = Timedelta(Timedelta.min)
max_td = Timedelta(Timedelta.max)
# GH 12727
# timedelta limits correspond to int64 boundaries
self.assertTrue(min_td.value == np.iinfo(np.int64).min + 1)
self.assertTrue(max_td.value == np.iinfo(np.int64).max)
# Beyond lower limit, a NAT before the Overflow
self.assertIsInstance(min_td - Timedelta(1, 'ns'),
pd.tslib.NaTType)
with tm.assertRaises(OverflowError):
min_td - Timedelta(2, 'ns')
with tm.assertRaises(OverflowError):
max_td + Timedelta(1, 'ns')
# Same tests using the internal nanosecond values
td = Timedelta(min_td.value - 1, 'ns')
self.assertIsInstance(td, pd.tslib.NaTType)
with tm.assertRaises(OverflowError):
Timedelta(min_td.value - 2, 'ns')
with tm.assertRaises(OverflowError):
Timedelta(max_td.value + 1, 'ns')
示例8: _range_scale
def _range_scale(self):
""" Calculate scaling, intercept based on data range and output type """
mn, mx = self.finite_range() # Values of self.array.dtype type
out_dtype = self._out_dtype
if mx == mn: # Only one number in array
self.inter = mn
return
# Straight mx-mn can overflow.
if mn.dtype.kind == 'f': # Already floats
# float64 and below cast correctly to longdouble. Longdouble needs
# no casting
mn2mx = np.diff(np.array([mn, mx], dtype=np.longdouble))
else: # max possible (u)int range is 2**64-1 (int64, uint64)
# int_to_float covers this range. On windows longdouble is the same
# as double so mn2mx will be 2**64 - thus overestimating slope
# slightly. Casting to int needed to allow mx-mn to be larger than
# the largest (u)int value
mn2mx = int_to_float(as_int(mx) - as_int(mn), np.longdouble)
if out_dtype.kind == 'f':
# Type range, these are also floats
info = type_info(out_dtype)
t_mn_mx = info['min'], info['max']
else:
t_mn_mx = np.iinfo(out_dtype).min, np.iinfo(out_dtype).max
t_mn_mx= [int_to_float(v, np.longdouble) for v in t_mn_mx]
# We want maximum precision for the calculations. Casting will
# not lose precision because min/max are of fp type.
assert [v.dtype.kind for v in t_mn_mx] == ['f', 'f']
scaled_mn2mx = np.diff(np.array(t_mn_mx, dtype = np.longdouble))
slope = mn2mx / scaled_mn2mx
self.inter = mn - t_mn_mx[0] * slope
self.slope = slope
if not np.all(np.isfinite([self.slope, self.inter])):
raise ScalingError("Slope / inter not both finite")
示例9: testInfNan
def testInfNan(self):
i4 = np.iinfo(np.int32)
i8 = np.iinfo(np.int64)
self._compare(np.inf, np.float32, np.inf, False)
self._compare(np.inf, np.float64, np.inf, False)
if sys.byteorder == "big":
self._compare(np.inf, np.int32, i4.max, False)
self._compare(np.inf, np.int64, i8.max, False)
else:
self._compare(np.inf, np.int32, i4.min, False)
self._compare(np.inf, np.int64, i8.min, False)
self._compare(-np.inf, np.float32, -np.inf, False)
self._compare(-np.inf, np.float64, -np.inf, False)
self._compare(-np.inf, np.int32, i4.min, False)
self._compare(-np.inf, np.int64, i8.min, False)
self.assertAllEqual(np.isnan(self._cast(np.nan, np.float32, False)), True)
self.assertAllEqual(np.isnan(self._cast(np.nan, np.float64, False)), True)
self._compare(np.nan, np.int32, i4.min, False)
self._compare(np.nan, np.int64, i8.min, False)
self._compare(np.inf, np.float32, np.inf, True)
self._compare(np.inf, np.float64, np.inf, True)
self._compare(-np.inf, np.float32, -np.inf, True)
self._compare(-np.inf, np.float64, -np.inf, True)
self.assertAllEqual(np.isnan(self._cast(np.nan, np.float32, True)), True)
self.assertAllEqual(np.isnan(self._cast(np.nan, np.float64, True)), True)
示例10: __init__
def __init__(self, name, unit='s', nullable=True):
min_val, max_val = np.iinfo('int64').min, np.iinfo('int64').max,
super(DurationIntervalType, self).__init__(
name, True, 64, nullable=nullable,
min_value=min_val,
max_value=max_val)
self.unit = unit
示例11: iter_raw_buffers
def iter_raw_buffers(self):
"""Return an iterator over raw buffers.
Returns
-------
raw_buffer : generator
Generator for iteration over raw buffers.
"""
# self.tmax_samp should be included
iter_times = list(zip(
list(range(self.tmin_samp, self.tmax_samp, self.buffer_size)),
list(range(self.tmin_samp + self.buffer_size,
self.tmax_samp + 1, self.buffer_size))))
last_iter_sample = iter_times[-1][1] if iter_times else self.tmin_samp
if last_iter_sample < self.tmax_samp + 1:
iter_times.append((last_iter_sample, self.tmax_samp + 1))
for ii, (start, stop) in enumerate(iter_times):
# wait for correct number of samples to be available
self.ft_client.wait(stop, np.iinfo(np.uint32).max,
np.iinfo(np.uint32).max)
# get the samples (stop index is inclusive)
raw_buffer = self.ft_client.getData([start, stop - 1]).transpose()
yield raw_buffer
示例12: getGDALRasterType
def getGDALRasterType(self):
'''
Gets the output raster type
'''
index = self.numberComboBox.currentIndex()
if index == 0:
min = numpy.iinfo(numpy.uint8).min
max = numpy.iinfo(numpy.uint8).max
return (osgeo.gdal.GDT_Byte, min, max)
elif index == 1:
min = numpy.iinfo(numpy.uint16).min
max = numpy.iinfo(numpy.uint16).max
return (osgeo.gdal.GDT_UInt16, min, max)
elif index == 2:
min = numpy.iinfo(numpy.int16).min
max = numpy.iinfo(numpy.int16).max
return (osgeo.gdal.GDT_Int16, min, max)
elif index == 3:
min = numpy.iinfo(numpy.uint32).min
max = numpy.iinfo(numpy.uint32).max
return (osgeo.gdal.GDT_UInt32, min, max)
elif index == 4:
min = numpy.iinfo(numpy.int32).min
max = numpy.iinfo(numpy.int32).max
return (osgeo.gdal.GDT_Int32, min, max)
elif index == 5:
min = numpy.finfo(numpy.float32).min
max = numpy.finfo(numpy.float32).max
return (osgeo.gdal.GDT_Float32, min, max)
elif index == 6:
min = numpy.finfo(numpy.float64).min
max = numpy.finfo(numpy.float64).max
return (osgeo.gdal.GDT_Float64, min, max)
示例13: munchetal_filter
def munchetal_filter(im, wlevel, sigma, wname='db15'):
# Wavelet decomposition:
coeffs = pywt.wavedec2(im.astype(np.float32), wname, level=wlevel)
coeffsFlt = [coeffs[0]]
# FFT transform of horizontal frequency bands:
for i in range(1, wlevel + 1):
# FFT:
fcV = np.fft.fftshift(np.fft.fft(coeffs[i][1], axis=0))
my, mx = fcV.shape
# Damping of vertical stripes:
damp = 1 - np.exp(-(np.arange(-np.floor(my / 2.), -np.floor(my / 2.) + my) ** 2) / (2 * (sigma ** 2)))
dampprime = np.kron(np.ones((1, mx)), damp.reshape((damp.shape[0], 1)))
fcV = fcV * dampprime
# Inverse FFT:
fcVflt = np.real(np.fft.ifft(np.fft.ifftshift(fcV), axis=0))
cVHDtup = (coeffs[i][0], fcVflt, coeffs[i][2])
coeffsFlt.append(cVHDtup)
# Get wavelet reconstruction:
im_f = np.real(pywt.waverec2(coeffsFlt, wname))
# Return image according to input type:
if (im.dtype == 'uint16'):
# Check extrema for uint16 images:
im_f[im_f < np.iinfo(np.uint16).min] = np.iinfo(np.uint16).min
im_f[im_f > np.iinfo(np.uint16).max] = np.iinfo(np.uint16).max
# Return filtered image (an additional row and/or column might be present):
return im_f[0:im.shape[0], 0:im.shape[1]].astype(np.uint16)
else:
return im_f[0:im.shape[0], 0:im.shape[1]]
示例14: clean
def clean(data):
data_wso = data.astype(np.int)
masked = np.ma.array(data_wso)
masked[:,np.arange(0,2592,16)] = np.ma.masked
#Set the mean of each spectra to zero
#med_col = np.mean(masked,axis=1)
med_col = np.min((\
np.mean(masked[:,:2592/5],axis=1),\
np.mean(masked[:,-2592/5:],axis=1)),\
axis=0)
data_wso = data_wso - med_col[:,np.newaxis]
#Shift the mean to 128
data_wso = data_wso + 128
#Set the right proprieties to the data
data_wso[:,np.arange(0,2592,16)] = 0
dtype_min = np.iinfo(data.dtype).min
dtype_max = np.iinfo(data.dtype).max
np.clip(data_wso, dtype_min, dtype_max, out=data_wso)
data_wso = np.around(data_wso)
data = data_wso.astype(data.dtype)
return data
示例15: _iu2iu
def _iu2iu(self):
# (u)int to (u)int
mn, mx = [as_int(v) for v in self.finite_range()]
# range may be greater than the largest integer for this type.
# as_int needed to work round numpy 1.4.1 int casting bug
out_dtype = self._out_dtype
t_min, t_max = np.iinfo(out_dtype).min, np.iinfo(out_dtype).max
type_range = as_int(t_max) - as_int(t_min)
mn2mx = mx - mn
if mn2mx <= type_range: # might offset be enough?
if t_min == 0: # uint output - take min to 0
# decrease offset with floor_exact, meaning mn >= t_min after
# subtraction. But we may have pushed the data over t_max,
# which we check below
inter = floor_exact(mn - t_min, self.scaler_dtype)
else: # int output - take midpoint to 0
# ceil below increases inter, pushing scale up to 0.5 towards
# -inf, because ints have abs min == abs max + 1
midpoint = mn + as_int(np.ceil(mn2mx / 2.0))
# Floor exact decreases inter, so pulling scaled values more
# positive. This may make mx - inter > t_max
inter = floor_exact(midpoint, self.scaler_dtype)
# Need to check still in range after floor_exact-ing
int_inter = as_int(inter)
assert mn - int_inter >= t_min
if mx - int_inter <= t_max:
self.inter = inter
return
# Try slope options (sign flip) and then range scaling
super(SlopeInterArrayWriter, self)._iu2iu()