Python numpy.int_() Examples
The following are 30 code examples for showing how to use numpy.int_(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example 1
Project: Advanced_Lane_Lines Author: ChengZhongShen File: image_process.py License: MIT License | 6 votes |
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
Example 2
Project: recruit Author: Frank-qlu File: test_core.py License: Apache License 2.0 | 6 votes |
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))
Example 3
Project: recruit Author: Frank-qlu File: test_linalg.py License: Apache License 2.0 | 6 votes |
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))
Example 4
Project: recruit Author: Frank-qlu File: test_linalg.py License: Apache License 2.0 | 6 votes |
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, res_v = linalg.eig(a) assert_(res_v.dtype.type is np.float64) assert_(res.dtype.type is np.float64) assert_equal(a.shape, res_v.shape) assert_equal((0, 1), res.shape) # This is just for documentation, it might make sense to change: assert_(isinstance(a, np.ndarray)) a = np.zeros((0, 0), dtype=np.complex64).view(ArraySubclass) res, res_v = linalg.eig(a) assert_(res_v.dtype.type is np.complex64) assert_(res.dtype.type is np.complex64) assert_equal(a.shape, res_v.shape) assert_equal((0,), res.shape) # This is just for documentation, it might make sense to change: assert_(isinstance(a, np.ndarray))
Example 5
Project: recruit Author: Frank-qlu File: test_linalg.py License: Apache License 2.0 | 6 votes |
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, res_v = linalg.eigh(a) assert_(res_v.dtype.type is np.float64) assert_(res.dtype.type is np.float64) assert_equal(a.shape, res_v.shape) assert_equal((0, 1), res.shape) # This is just for documentation, it might make sense to change: assert_(isinstance(a, np.ndarray)) a = np.zeros((0, 0), dtype=np.complex64).view(ArraySubclass) res, res_v = linalg.eigh(a) assert_(res_v.dtype.type is np.complex64) assert_(res.dtype.type is np.float32) assert_equal(a.shape, res_v.shape) assert_equal((0,), res.shape) # This is just for documentation, it might make sense to change: assert_(isinstance(a, np.ndarray))
Example 6
Project: recruit Author: Frank-qlu File: test_scalarmath.py License: Apache License 2.0 | 6 votes |
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))
Example 7
Project: recruit Author: Frank-qlu File: test_indexing.py License: Apache License 2.0 | 6 votes |
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)]
Example 8
Project: recruit Author: Frank-qlu File: test_indexing.py License: Apache License 2.0 | 6 votes |
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)]
Example 9
Project: tenpy Author: tenpy File: lattice.py License: GNU General Public License v3.0 | 6 votes |
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)
Example 10
Project: mars Author: mars-project File: test_datasource_execute.py License: Apache License 2.0 | 6 votes |
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_)
Example 11
Project: mars Author: mars-project File: histogram.py License: Apache License 2.0 | 6 votes |
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)
Example 12
Project: westpa Author: westpa File: testyamlfe.py License: MIT License | 6 votes |
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
Example 13
Project: lambda-packs Author: ryfeus File: histograms.py License: MIT License | 6 votes |
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)
Example 14
Project: lambda-packs Author: ryfeus File: test_core.py License: MIT License | 6 votes |
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))
Example 15
Project: auto-alt-text-lambda-api Author: abhisuri97 File: test_core.py License: MIT License | 6 votes |
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))
Example 16
Project: auto-alt-text-lambda-api Author: abhisuri97 File: test_indexing.py License: MIT License | 6 votes |
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))
Example 17
Project: vnpy_crypto Author: birforce File: test_core.py License: MIT License | 6 votes |
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))
Example 18
Project: vnpy_crypto Author: birforce File: test_linalg.py License: MIT License | 6 votes |
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))
Example 19
Project: vnpy_crypto Author: birforce File: test_linalg.py License: MIT License | 6 votes |
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, res_v = linalg.eig(a) assert_(res_v.dtype.type is np.float64) assert_(res.dtype.type is np.float64) assert_equal(a.shape, res_v.shape) assert_equal((0, 1), res.shape) # This is just for documentation, it might make sense to change: assert_(isinstance(a, np.ndarray)) a = np.zeros((0, 0), dtype=np.complex64).view(ArraySubclass) res, res_v = linalg.eig(a) assert_(res_v.dtype.type is np.complex64) assert_(res.dtype.type is np.complex64) assert_equal(a.shape, res_v.shape) assert_equal((0,), res.shape) # This is just for documentation, it might make sense to change: assert_(isinstance(a, np.ndarray))
Example 20
Project: vnpy_crypto Author: birforce File: test_linalg.py License: MIT License | 6 votes |
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.eigvalsh(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.eigvalsh(a) assert_(res.dtype.type is np.float32) assert_equal((0,), res.shape) # This is just for documentation, it might make sense to change: assert_(isinstance(res, np.ndarray))
Example 21
Project: vnpy_crypto Author: birforce File: test_linalg.py License: MIT License | 6 votes |
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, res_v = linalg.eigh(a) assert_(res_v.dtype.type is np.float64) assert_(res.dtype.type is np.float64) assert_equal(a.shape, res_v.shape) assert_equal((0, 1), res.shape) # This is just for documentation, it might make sense to change: assert_(isinstance(a, np.ndarray)) a = np.zeros((0, 0), dtype=np.complex64).view(ArraySubclass) res, res_v = linalg.eigh(a) assert_(res_v.dtype.type is np.complex64) assert_(res.dtype.type is np.float32) assert_equal(a.shape, res_v.shape) assert_equal((0,), res.shape) # This is just for documentation, it might make sense to change: assert_(isinstance(a, np.ndarray))
Example 22
Project: EXOSIMS Author: dsavransky File: test_SurveySimulation.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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__)
Example 23
Project: risk-slim Author: ustunb File: helper_functions.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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_))
Example 24
Project: risk-slim Author: ustunb File: helper_functions.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def cast_to_integer(rho): """ casts numpy array to integer vector Parameters ---------- rho Returns ------- """ original_type = rho.dtype return np.require(np.require(rho, dtype=np.int_), dtype=original_type)
Example 25
Project: risk-slim Author: ustunb File: coefficient_set.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def _is_integer(self, x): return np.array_equal(x, np.require(x, dtype = np.int_))
Example 26
Project: MnemonicReader Author: HKUST-KnowComp File: data.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def __iter__(self): lengths = np.array( [(-l[0], -l[1], np.random.random()) for l in self.lengths], dtype=[('l1', np.int_), ('l2', np.int_), ('rand', np.float_)] ) indices = np.argsort(lengths, order=('l1', 'l2', 'rand')) batches = [indices[i:i + self.batch_size] for i in range(0, len(indices), self.batch_size)] if self.shuffle: np.random.shuffle(batches) return iter([i for batch in batches for i in batch])
Example 27
Project: recruit Author: Frank-qlu File: histograms.py License: Apache License 2.0 | 5 votes |
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)
Example 28
Project: recruit Author: Frank-qlu File: test_function_base.py License: Apache License 2.0 | 5 votes |
def test_non_bool_deprecation(self): choices = self.choices conditions = self.conditions[:] with warnings.catch_warnings(): warnings.filterwarnings("always") conditions[0] = conditions[0].astype(np.int_) assert_warns(DeprecationWarning, select, conditions, choices) conditions[0] = conditions[0].astype(np.uint8) assert_warns(DeprecationWarning, select, conditions, choices) warnings.filterwarnings("error") assert_raises(DeprecationWarning, select, conditions, choices)
Example 29
Project: recruit Author: Frank-qlu File: test_function_base.py License: Apache License 2.0 | 5 votes |
def test_n(self): x = list(range(3)) assert_raises(ValueError, diff, x, n=-1) output = [diff(x, n=n) for n in range(1, 5)] expected = [[1, 1], [0], [], []] assert_(diff(x, n=0) is x) for n, (expected, out) in enumerate(zip(expected, output), start=1): assert_(type(out) is np.ndarray) assert_array_equal(out, expected) assert_equal(out.dtype, np.int_) assert_equal(len(out), max(0, len(x) - n))
Example 30
Project: recruit Author: Frank-qlu File: test_nanfunctions.py License: Apache License 2.0 | 5 votes |
def test_dtype_error(self): for f in self.nanfuncs: for dtype in [np.bool_, np.int_, np.object_]: assert_raises(TypeError, f, _ndat, axis=1, dtype=dtype)