本文整理匯總了Python中numpy.int_方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.int_方法的具體用法?Python numpy.int_怎麽用?Python numpy.int_使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.int_方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: draw_lane_fit
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def draw_lane_fit(undist, warped ,Minv, left_fitx, right_fitx, ploty):
# Drawing
# Create an image to draw the lines on
warp_zero = np.zeros_like(warped).astype(np.uint8)
color_warp = np.dstack((warp_zero, warp_zero, warp_zero))
# Recast the x and y points into usable format for cv2.fillPoly()
pts_left = np.array([np.transpose(np.vstack([left_fitx, ploty]))])
pts_right = np.array([np.flipud(np.transpose(np.vstack([right_fitx, ploty])))])
pts = np.hstack((pts_left, pts_right))
# Draw the lane onto the warped blank image
cv2.fillPoly(color_warp, np.int_([pts]), (0,255,0))
# Warp the blank back to original image space using inverse perspective matrix(Minv)
newwarp = cv2.warpPerspective(color_warp, Minv, (undist.shape[1], undist.shape[0]))
# Combine the result with the original image
result = cv2.addWeighted(undist, 1, newwarp, 0.3, 0)
return result
示例2: _unsigned_subtract
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def _unsigned_subtract(a, b):
"""
Subtract two values where a >= b, and produce an unsigned result
This is needed when finding the difference between the upper and lower
bound of an int16 histogram
"""
# coerce to a single type
signed_to_unsigned = {
np.byte: np.ubyte,
np.short: np.ushort,
np.intc: np.uintc,
np.int_: np.uint,
np.longlong: np.ulonglong
}
dt = np.result_type(a, b)
try:
dt = signed_to_unsigned[dt.type]
except KeyError:
return np.subtract(a, b, dtype=dt)
else:
# we know the inputs are integers, and we are deliberately casting
# signed to unsigned
return np.subtract(a, b, casting='unsafe', dtype=dt)
示例3: test_allclose
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def test_allclose(self):
# Tests allclose on arrays
a = np.random.rand(10)
b = a + np.random.rand(10) * 1e-8
assert_(allclose(a, b))
# Test allclose w/ infs
a[0] = np.inf
assert_(not allclose(a, b))
b[0] = np.inf
assert_(allclose(a, b))
# Test allclose w/ masked
a = masked_array(a)
a[-1] = masked
assert_(allclose(a, b, masked_equal=True))
assert_(not allclose(a, b, masked_equal=False))
# Test comparison w/ scalar
a *= 1e-8
a[0] = 0
assert_(allclose(a, 0, masked_equal=True))
# Test that the function works for MIN_INT integer typed arrays
a = masked_array([np.iinfo(np.int_).min], dtype=np.int_)
assert_(allclose(a, a))
示例4: test_0_size
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def test_0_size(self):
# Check that all kinds of 0-sized arrays work
class ArraySubclass(np.ndarray):
pass
a = np.zeros((0, 1, 1), dtype=np.int_).view(ArraySubclass)
res = linalg.eigvals(a)
assert_(res.dtype.type is np.float64)
assert_equal((0, 1), res.shape)
# This is just for documentation, it might make sense to change:
assert_(isinstance(res, np.ndarray))
a = np.zeros((0, 0), dtype=np.complex64).view(ArraySubclass)
res = linalg.eigvals(a)
assert_(res.dtype.type is np.complex64)
assert_equal((0,), res.shape)
# This is just for documentation, it might make sense to change:
assert_(isinstance(res, np.ndarray))
示例5: test_no_seq_repeat_basic_array_like
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def test_no_seq_repeat_basic_array_like(self):
# Test that an array-like which does not know how to be multiplied
# does not attempt sequence repeat (raise TypeError).
# See also gh-7428.
class ArrayLike(object):
def __init__(self, arr):
self.arr = arr
def __array__(self):
return self.arr
# Test for simple ArrayLike above and memoryviews (original report)
for arr_like in (ArrayLike(np.ones(3)), memoryview(np.ones(3))):
assert_array_equal(arr_like * np.float32(3.), np.full(3, 3.))
assert_array_equal(np.float32(3.) * arr_like, np.full(3, 3.))
assert_array_equal(arr_like * np.int_(3), np.full(3, 3))
assert_array_equal(np.int_(3) * arr_like, np.full(3, 3))
示例6: test_dti_business_getitem
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def test_dti_business_getitem(self):
rng = pd.bdate_range(START, END)
smaller = rng[:5]
exp = DatetimeIndex(rng.view(np.ndarray)[:5])
tm.assert_index_equal(smaller, exp)
assert smaller.freq == rng.freq
sliced = rng[::5]
assert sliced.freq == BDay() * 5
fancy_indexed = rng[[4, 3, 2, 1, 0]]
assert len(fancy_indexed) == 5
assert isinstance(fancy_indexed, DatetimeIndex)
assert fancy_indexed.freq is None
# 32-bit vs. 64-bit platforms
assert rng[4] == rng[np.int_(4)]
示例7: test_dti_custom_getitem
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def test_dti_custom_getitem(self):
rng = pd.bdate_range(START, END, freq='C')
smaller = rng[:5]
exp = DatetimeIndex(rng.view(np.ndarray)[:5])
tm.assert_index_equal(smaller, exp)
assert smaller.freq == rng.freq
sliced = rng[::5]
assert sliced.freq == CDay() * 5
fancy_indexed = rng[[4, 3, 2, 1, 0]]
assert len(fancy_indexed) == 5
assert isinstance(fancy_indexed, DatetimeIndex)
assert fancy_indexed.freq is None
# 32-bit vs. 64-bit platforms
assert rng[4] == rng[np.int_(4)]
示例8: boundary_conditions
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def boundary_conditions(self, bc):
global bc_choices
if bc in list(bc_choices.keys()):
bc = [bc_choices[bc]] * self.dim
self.bc_shift = None
else:
bc = list(bc) # we modify entries...
self.bc_shift = np.zeros(self.dim - 1, np.int_)
for i, bc_i in enumerate(bc):
if isinstance(bc_i, int):
if i == 0:
raise ValueError("Invalid bc: first entry can't be a shift")
self.bc_shift[i - 1] = bc_i
bc[i] = bc_choices['periodic']
else:
bc[i] = bc_choices[bc_i]
if not np.any(self.bc_shift != 0):
self.bc_shift = None
self.bc = np.array(bc)
示例9: testLinspaceExecution
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def testLinspaceExecution(self):
a = linspace(2.0, 9.0, num=11, chunk_size=3)
res = self.executor.execute_tensor(a, concat=True)[0]
expected = np.linspace(2.0, 9.0, num=11)
np.testing.assert_allclose(res, expected)
a = linspace(2.0, 9.0, num=11, endpoint=False, chunk_size=3)
res = self.executor.execute_tensor(a, concat=True)[0]
expected = np.linspace(2.0, 9.0, num=11, endpoint=False)
np.testing.assert_allclose(res, expected)
a = linspace(2.0, 9.0, num=11, chunk_size=3, dtype=int)
res = self.executor.execute_tensor(a, concat=True)[0]
self.assertEqual(res.dtype, np.int_)
示例10: _unsigned_subtract
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def _unsigned_subtract(a, b):
"""
Subtract two values where a >= b, and produce an unsigned result
This is needed when finding the difference between the upper and lower
bound of an int16 histogram
"""
# coerce to a single type
signed_to_unsigned = {
np.byte: np.ubyte,
np.short: np.ushort,
np.intc: np.uintc,
np.int_: np.uint,
np.longlong: np.ulonglong
}
dt = np.result_type(a, b)
try:
dt = signed_to_unsigned[dt.type]
except KeyError: # pragma: no cover
return np.subtract(a, b, dtype=dt)
else:
# we know the inputs are integers, and we are deliberately casting
# signed to unsigned
return np.subtract(a, b, casting='unsafe', dtype=dt)
示例11: initialize
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def initialize(self):
self.pcoord_ndim = 1
self.pcoord_dtype = numpy.float32
self.pcoord_len = 5
self.bin_mapper = RectilinearBinMapper([ list(numpy.arange(0.0, 10.1, 0.1)) ] )
self.bin_target_counts = numpy.empty((self.bin_mapper.nbins,), numpy.int_)
self.bin_target_counts[...] = 10
self.test_variable_2 = "And I'm the second one"
# YAML Front end tests
# Implemented basic tests
# - returns the correct system
# given a system driver
# - returns the correct system
# given a yaml system
# - returns the correct system
# given both
# A class to test both paths at the same time
# if it works we assure we can load the driver
# AND overwrite it properly
示例12: test_allclose
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def test_allclose(self):
# Tests allclose on arrays
a = np.random.rand(10)
b = a + np.random.rand(10) * 1e-8
self.assertTrue(allclose(a, b))
# Test allclose w/ infs
a[0] = np.inf
self.assertTrue(not allclose(a, b))
b[0] = np.inf
self.assertTrue(allclose(a, b))
# Test allclose w/ masked
a = masked_array(a)
a[-1] = masked
self.assertTrue(allclose(a, b, masked_equal=True))
self.assertTrue(not allclose(a, b, masked_equal=False))
# Test comparison w/ scalar
a *= 1e-8
a[0] = 0
self.assertTrue(allclose(a, 0, masked_equal=True))
# Test that the function works for MIN_INT integer typed arrays
a = masked_array([np.iinfo(np.int_).min], dtype=np.int_)
self.assertTrue(allclose(a, a))
示例13: test_empty_tuple_index
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def test_empty_tuple_index(self):
# Empty tuple index creates a view
a = np.array([1, 2, 3])
assert_equal(a[()], a)
assert_(a[()].base is a)
a = np.array(0)
assert_(isinstance(a[()], np.int_))
# Regression, it needs to fall through integer and fancy indexing
# cases, so need the with statement to ignore the non-integer error.
with warnings.catch_warnings():
warnings.filterwarnings('ignore', '', DeprecationWarning)
a = np.array([1.])
assert_(isinstance(a[0.], np.float_))
a = np.array([np.array(1)], dtype=object)
assert_(isinstance(a[0.], np.ndarray))
示例14: test_observation_detection
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def test_observation_detection(self):
r"""Test observation_detection method.
Approach: Ensure that all outputs are set as expected
"""
exclude_mods = []
exclude_mod_type = 'sotoSS'
for mod in self.allmods:
if mod.__name__ in exclude_mods:
continue
if 'observation_detection' in mod.__dict__ or exclude_mod_type in mod.__name__:
spec = copy.deepcopy(self.spec)
if 'tieredScheduler' in mod.__name__:
self.script = resource_path('test-scripts/simplest_occ.json')
with open(self.script) as f:
spec = json.loads(f.read())
spec['occHIPs'] = resource_path('SurveySimulation/top100stars.txt')
with RedirectStreams(stdout=self.dev_null):
sim = mod(**spec)
#default settings should create dummy planet around first star
sInd = 0
pInds = np.where(sim.SimulatedUniverse.plan2star == sInd)[0]
detected, fZ, systemParams, SNR, FA = \
sim.observation_detection(sInd,1.0*u.d,\
sim.OpticalSystem.observingModes[0])
self.assertEqual(len(detected),len(pInds),\
'len(detected) != len(pInds) for %s'%mod.__name__)
self.assertIsInstance(detected[0],(int,np.int32,np.int64,np.int_),\
'detected elements not ints for %s'%mod.__name__)
for s in SNR[detected == 1]:
self.assertGreaterEqual(s,sim.OpticalSystem.observingModes[0]['SNR'],\
'detection SNR < mode requirement for %s'%mod.__name__)
self.assertIsInstance(FA, bool,\
'False Alarm not boolean for %s'%mod.__name__)
示例15: is_integer
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import int_ [as 別名]
def is_integer(rho):
"""
checks if numpy array is an integer vector
Parameters
----------
rho
Returns
-------
"""
return np.array_equal(rho, np.require(rho, dtype=np.int_))