Python numpy.long() Examples
The following are 30
code examples of numpy.long().
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 also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: test_model_wrappers.py From ngraph-python with Apache License 2.0 | 6 votes |
def test_attribute_wrapper(): def attribute_value_test(attribute_value): node = make_node('Abs', ['X'], [], name='test_node', test_attribute=attribute_value) model = make_model(make_graph([node], 'test_graph', [ make_tensor_value_info('X', onnx.TensorProto.FLOAT, [1, 2]), ], []), producer_name='ngraph') wrapped_attribute = ModelWrapper(model).graph.node[0].get_attribute('test_attribute') return wrapped_attribute.get_value() tensor = make_tensor('test_tensor', onnx.TensorProto.FLOAT, [1], [1]) assert attribute_value_test(1) == 1 assert type(attribute_value_test(1)) == np.long assert attribute_value_test(1.0) == 1.0 assert type(attribute_value_test(1.0)) == np.float assert attribute_value_test('test') == 'test' assert attribute_value_test(tensor)._proto == tensor assert attribute_value_test([1, 2, 3]) == [1, 2, 3] assert attribute_value_test([1.0, 2.0, 3.0]) == [1.0, 2.0, 3.0] assert attribute_value_test(['test1', 'test2']) == ['test1', 'test2'] assert attribute_value_test([tensor, tensor])[1]._proto == tensor
Example #2
Source File: test_random.py From recruit with Apache License 2.0 | 6 votes |
def test_respect_dtype_singleton(self): # See gh-7203 for dt in self.itype: lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1 sample = self.rfunc(lbnd, ubnd, dtype=dt) assert_equal(sample.dtype, np.dtype(dt)) for dt in (bool, int, np.long): lbnd = 0 if dt is bool else np.iinfo(dt).min ubnd = 2 if dt is bool else np.iinfo(dt).max + 1 # gh-7284: Ensure that we get Python data types sample = self.rfunc(lbnd, ubnd, dtype=dt) assert_(not hasattr(sample, 'dtype')) assert_equal(type(sample), dt)
Example #3
Source File: test_random.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_respect_dtype_singleton(self): # See gh-7203 for dt in self.itype: lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1 sample = self.rfunc(lbnd, ubnd, dtype=dt) assert_equal(sample.dtype, np.dtype(dt)) for dt in (bool, int, np.long): lbnd = 0 if dt is bool else np.iinfo(dt).min ubnd = 2 if dt is bool else np.iinfo(dt).max + 1 # gh-7284: Ensure that we get Python data types sample = self.rfunc(lbnd, ubnd, dtype=dt) assert_(not hasattr(sample, 'dtype')) assert_equal(type(sample), dt)
Example #4
Source File: makePathFromOutline.py From fontgoggles with Apache License 2.0 | 6 votes |
def makePathFromArrays(points, tags, contours): n_contours = len(contours) n_points = len(tags) assert len(points) >= n_points assert points.shape[1:] == (2,) if points.dtype != numpy.long: points = numpy.floor(points + [0.5, 0.5]) points = points.astype(numpy.long) assert tags.dtype == numpy.byte assert contours.dtype == numpy.short path = objc.objc_object( c_void_p=_makePathFromArrays( n_contours, n_points, points.ctypes.data_as(FT_Vector_p), tags.ctypes.data_as(c_char_p), contours.ctypes.data_as(c_short_p))) # See comment in makePathFromOutline() path.release() return path
Example #5
Source File: MNIST_gold_only.py From glc with Apache License 2.0 | 6 votes |
def prepare_data(corruption_matrix, gold_fraction=0.5, merge_valset=True): np.random.seed(1) mnist_images = np.copy(mnist.train.images) mnist_labels = np.copy(mnist.train.labels) if merge_valset: mnist_images = np.concatenate([mnist_images, np.copy(mnist.validation.images)], axis=0) mnist_labels = np.concatenate([mnist_labels, np.copy(mnist.validation.labels)]) indices = np.arange(len(mnist_labels)) np.random.shuffle(indices) mnist_images = mnist_images[indices] mnist_labels = mnist_labels[indices].astype(np.long) num_gold = int(len(mnist_labels)*gold_fraction) num_silver = len(mnist_labels) - num_gold for i in range(num_silver): mnist_labels[i] = np.random.choice(num_classes, p=corruption_matrix[mnist_labels[i]]) dataset = {'x': mnist_images, 'y': mnist_labels} gold = {'x': dataset['x'][num_silver:], 'y': dataset['y'][num_silver:]} return dataset, gold, num_gold, num_silver
Example #6
Source File: MNIST_experiments_pytorch.py From glc with Apache License 2.0 | 6 votes |
def prepare_data(corruption_matrix, gold_fraction=0.5, merge_valset=True): np.random.seed(1) mnist_images = np.copy(mnist.train.images) mnist_labels = np.copy(mnist.train.labels) if merge_valset: mnist_images = np.concatenate([mnist_images, np.copy(mnist.validation.images)], axis=0) mnist_labels = np.concatenate([mnist_labels, np.copy(mnist.validation.labels)]) indices = np.arange(len(mnist_labels)) np.random.shuffle(indices) mnist_images = mnist_images[indices] mnist_labels = mnist_labels[indices].astype(np.long) num_gold = int(len(mnist_labels)*gold_fraction) num_silver = len(mnist_labels) - num_gold for i in range(num_silver): mnist_labels[i] = np.random.choice(num_classes, p=corruption_matrix[mnist_labels[i]]) dataset = {'x': mnist_images, 'y': mnist_labels} gold = {'x': dataset['x'][num_silver:], 'y': dataset['y'][num_silver:]} return dataset, gold, num_gold, num_silver
Example #7
Source File: test_random.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_respect_dtype_singleton(self): # See gh-7203 for dt in self.itype: lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1 sample = self.rfunc(lbnd, ubnd, dtype=dt) assert_equal(sample.dtype, np.dtype(dt)) for dt in (bool, int, np.long): lbnd = 0 if dt is bool else np.iinfo(dt).min ubnd = 2 if dt is bool else np.iinfo(dt).max + 1 # gh-7284: Ensure that we get Python data types sample = self.rfunc(lbnd, ubnd, dtype=dt) assert_(not hasattr(sample, 'dtype')) assert_equal(type(sample), dt)
Example #8
Source File: Twitter_gold_only.py From glc with Apache License 2.0 | 6 votes |
def prepare_data(corruption_matrix, gold_fraction=0.5, merge_valset=True): np.random.seed(1) twitter_tweets = np.copy(X_train) twitter_labels = np.copy(Y_train) if merge_valset: twitter_tweets = np.concatenate([twitter_tweets, np.copy(X_dev)], axis=0) twitter_labels = np.concatenate([twitter_labels, np.copy(Y_dev)]) indices = np.arange(len(twitter_labels)) np.random.shuffle(indices) twitter_tweets = twitter_tweets[indices] twitter_labels = twitter_labels[indices].astype(np.long) num_gold = int(len(twitter_labels)*gold_fraction) num_silver = len(twitter_labels) - num_gold for i in range(num_silver): twitter_labels[i] = np.random.choice(num_classes, p=corruption_matrix[twitter_labels[i]]) dataset = {'x': twitter_tweets, 'y': twitter_labels} gold = {'x': dataset['x'][num_silver:], 'y': dataset['y'][num_silver:]} return dataset, gold, num_gold, num_silver
Example #9
Source File: Twitter_experiments_pytorch.py From glc with Apache License 2.0 | 6 votes |
def prepare_data(corruption_matrix, gold_fraction=0.5, merge_valset=True): np.random.seed(1) twitter_tweets = np.copy(X_train) twitter_labels = np.copy(Y_train) if merge_valset: twitter_tweets = np.concatenate([twitter_tweets, np.copy(X_dev)], axis=0) twitter_labels = np.concatenate([twitter_labels, np.copy(Y_dev)]) indices = np.arange(len(twitter_labels)) np.random.shuffle(indices) twitter_tweets = twitter_tweets[indices] twitter_labels = twitter_labels[indices].astype(np.long) num_gold = int(len(twitter_labels)*gold_fraction) num_silver = len(twitter_labels) - num_gold for i in range(num_silver): twitter_labels[i] = np.random.choice(num_classes, p=corruption_matrix[twitter_labels[i]]) dataset = {'x': twitter_tweets, 'y': twitter_labels} gold = {'x': dataset['x'][num_silver:], 'y': dataset['y'][num_silver:]} return dataset, gold, num_gold, num_silver
Example #10
Source File: data_helper.py From HGNN with MIT License | 6 votes |
def load_ft(data_dir, feature_name='GVCNN'): data = scio.loadmat(data_dir) lbls = data['Y'].astype(np.long) if lbls.min() == 1: lbls = lbls - 1 idx = data['indices'].item() if feature_name == 'MVCNN': fts = data['X'][0].item().astype(np.float32) elif feature_name == 'GVCNN': fts = data['X'][1].item().astype(np.float32) else: print(f'wrong feature name{feature_name}!') raise IOError idx_train = np.where(idx == 1)[0] idx_test = np.where(idx == 0)[0] return fts, lbls, idx_train, idx_test
Example #11
Source File: sudoku_solver.py From dgl with Apache License 2.0 | 6 votes |
def solve_sudoku(puzzle): """ Solve sudoku puzzle using RRN. :param puzzle: an array-like data with shape [9, 9], blank positions are filled with 0 :return: a [9, 9] shaped numpy array """ puzzle = np.array(puzzle, dtype=np.long).reshape([-1]) model_path = 'ckpt' if not os.path.exists(model_path): os.mkdir(model_path) model_filename = os.path.join(model_path, 'rrn-sudoku.pkl') if not os.path.exists(model_filename): print('Downloading model...') url = 'https://data.dgl.ai/models/rrn-sudoku.pkl' urllib.request.urlretrieve(url, model_filename) model = torch.load(model_filename, map_location='cpu') g = _basic_sudoku_graph() sudoku_indices = np.arange(0, 81) rows = sudoku_indices // 9 cols = sudoku_indices % 9 g.ndata['row'] = torch.tensor(rows, dtype=torch.long) g.ndata['col'] = torch.tensor(cols, dtype=torch.long) g.ndata['q'] = torch.tensor(puzzle, dtype=torch.long) g.ndata['a'] = torch.tensor(puzzle, dtype=torch.long) pred, _ = model(g, False) pred = pred.cpu().data.numpy().reshape([9, 9]) return pred
Example #12
Source File: fixes.py From skutil with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _is_integer(x): """Determine whether some object ``x`` is an integer type (int, long, etc). This is part of the ``fixes`` module, since Python 3 removes the long datatype, we have to check the version major. Parameters ---------- x : object The item to assess whether is an integer. Returns ------- bool True if ``x`` is an integer type """ return (not isinstance(x, (bool, np.bool))) and \ isinstance(x, (numbers.Integral, int, np.int, np.long, long)) # no long type in python 3
Example #13
Source File: test_random.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_respect_dtype_singleton(self): # See gh-7203 for dt in self.itype: lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1 sample = self.rfunc(lbnd, ubnd, dtype=dt) self.assertEqual(sample.dtype, np.dtype(dt)) for dt in (np.bool, np.int, np.long): lbnd = 0 if dt is np.bool else np.iinfo(dt).min ubnd = 2 if dt is np.bool else np.iinfo(dt).max + 1 # gh-7284: Ensure that we get Python data types sample = self.rfunc(lbnd, ubnd, dtype=dt) self.assertFalse(hasattr(sample, 'dtype')) self.assertEqual(type(sample), dt)
Example #14
Source File: test_random.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_respect_dtype_singleton(self): # See gh-7203 for dt in self.itype: lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1 sample = self.rfunc(lbnd, ubnd, dtype=dt) assert_equal(sample.dtype, np.dtype(dt)) for dt in (bool, int, np.long): lbnd = 0 if dt is bool else np.iinfo(dt).min ubnd = 2 if dt is bool else np.iinfo(dt).max + 1 # gh-7284: Ensure that we get Python data types sample = self.rfunc(lbnd, ubnd, dtype=dt) assert_(not hasattr(sample, 'dtype')) assert_equal(type(sample), dt)
Example #15
Source File: test_random.py From vnpy_crypto with MIT License | 6 votes |
def test_respect_dtype_singleton(self): # See gh-7203 for dt in self.itype: lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1 sample = self.rfunc(lbnd, ubnd, dtype=dt) assert_equal(sample.dtype, np.dtype(dt)) for dt in (bool, int, np.long): lbnd = 0 if dt is bool else np.iinfo(dt).min ubnd = 2 if dt is bool else np.iinfo(dt).max + 1 # gh-7284: Ensure that we get Python data types sample = self.rfunc(lbnd, ubnd, dtype=dt) assert_(not hasattr(sample, 'dtype')) assert_equal(type(sample), dt)
Example #16
Source File: test_regression.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_array_side_effect(self): # The second use of itemsize was throwing an exception because in # ctors.c, discover_itemsize was calling PyObject_Length without # checking the return code. This failed to get the length of the # number 2, and the exception hung around until something checked # PyErr_Occurred() and returned an error. assert_equal(np.dtype('S10').itemsize, 10) np.array([['abc', 2], ['long ', '0123456789']], dtype=np.string_) assert_equal(np.dtype('S10').itemsize, 10)
Example #17
Source File: stata.py From Computable with MIT License | 5 votes |
def __init__(self, offset, value): self._value = value if type(value) is int or type(value) is long: self._str = value - offset is 1 and \ '.' or ('.' + chr(value - offset + 96)) else: self._str = '.'
Example #18
Source File: test_regression.py From Computable with MIT License | 5 votes |
def test_object_array_self_reference(self): # Object arrays with references to themselves can cause problems a = np.array(0, dtype=object) a[()] = a assert_raises(TypeError, int, a) assert_raises(TypeError, long, a) assert_raises(TypeError, float, a) assert_raises(TypeError, oct, a) assert_raises(TypeError, hex, a) # This was causing a to become like the above a = np.array(0, dtype=object) a[...] += 1 assert_equal(a, 1)
Example #19
Source File: test_regression.py From Computable with MIT License | 5 votes |
def test_array_side_effect(self): assert_equal(np.dtype('S10').itemsize, 10) A = np.array([['abc', 2], ['long ', '0123456789']], dtype=np.string_) # This was throwing an exception because in ctors.c, # discover_itemsize was calling PyObject_Length without checking # the return code. This failed to get the length of the number 2, # and the exception hung around until something checked # PyErr_Occurred() and returned an error. assert_equal(np.dtype('S10').itemsize, 10)
Example #20
Source File: test_ufunc.py From Computable with MIT License | 5 votes |
def test_matrix_multiply(self): self.compare_matrix_multiply_results(np.long) self.compare_matrix_multiply_results(np.double)
Example #21
Source File: datasets.py From kaggle-google-quest with MIT License | 5 votes |
def __init__(self, x_features, question_ids, answer_ids, seg_question_ids, seg_answer_ids, idxs, targets=None): self.question_ids = question_ids[idxs].astype(np.long) self.answer_ids = answer_ids[idxs].astype(np.long) self.seg_question_ids = seg_question_ids[idxs].astype(np.long) self.seg_answer_ids = seg_answer_ids[idxs].astype(np.long) self.x_features = x_features[idxs].astype(np.float32) if targets is not None: self.targets = targets[idxs].astype(np.float32) else: self.targets = np.zeros((self.x_features.shape[0], N_TARGETS), dtype=np.float32)
Example #22
Source File: test_regression.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_array_side_effect(self): # The second use of itemsize was throwing an exception because in # ctors.c, discover_itemsize was calling PyObject_Length without # checking the return code. This failed to get the length of the # number 2, and the exception hung around until something checked # PyErr_Occurred() and returned an error. assert_equal(np.dtype('S10').itemsize, 10) np.array([['abc', 2], ['long ', '0123456789']], dtype=np.string_) assert_equal(np.dtype('S10').itemsize, 10)
Example #23
Source File: test_regression.py From Computable with MIT License | 5 votes |
def test_signed_integer_division_overflow(self): """Ticket #1317.""" def test_type(t): min = np.array([np.iinfo(t).min]) min //= -1 with np.errstate(divide="ignore"): for t in (np.int8, np.int16, np.int32, np.int64, np.int, np.long): test_type(t)
Example #24
Source File: test_regression.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_signed_integer_division_overflow(self): # Ticket #1317. def test_type(t): min = np.array([np.iinfo(t).min]) min //= -1 with np.errstate(divide="ignore"): for t in (np.int8, np.int16, np.int32, np.int64, int, np.long): test_type(t)
Example #25
Source File: generator.py From crnn.pytorch with Apache License 2.0 | 5 votes |
def __getitem__(self, item): image, indices, target_len = self.gen_image() if self.direction == 'horizontal': image = np.transpose(image[:, :, np.newaxis], axes=(2, 1, 0)) # [H,W,C]=>[C,W,H] else: image = np.transpose(image[:, :, np.newaxis], axes=(2, 0, 1)) # [H,W,C]=>[C,H,W] # 标准化 image = image.astype(np.float32) / 255. image -= 0.5 image /= 0.5 target = np.zeros(shape=(self.max_len,), dtype=np.long) target[:target_len] = indices input_len = self.im_w // 4 - 3 return image, target, input_len, target_len
Example #26
Source File: test_ufunc.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_matrix_multiply(self): self.compare_matrix_multiply_results(np.long) self.compare_matrix_multiply_results(np.double)
Example #27
Source File: test_random.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_random_integers_max_int(self): # Tests whether random_integers can generate the # maximum allowed Python int that can be converted # into a C long. Previous implementations of this # method have thrown an OverflowError when attempting # to generate this integer. with suppress_warnings() as sup: w = sup.record(DeprecationWarning) actual = np.random.random_integers(np.iinfo('l').max, np.iinfo('l').max) assert_(len(w) == 1) desired = np.iinfo('l').max assert_equal(actual, desired)
Example #28
Source File: test_ufunc.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_matrix_multiply(self): self.compare_matrix_multiply_results(np.long) self.compare_matrix_multiply_results(np.double)
Example #29
Source File: test_regression.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_signed_integer_division_overflow(self): # Ticket #1317. def test_type(t): min = np.array([np.iinfo(t).min]) min //= -1 with np.errstate(divide="ignore"): for t in (np.int8, np.int16, np.int32, np.int64, int, np.long): test_type(t)
Example #30
Source File: stata.py From Computable with MIT License | 5 votes |
def __init__(self, fname, data, convert_dates=None, write_index=True, encoding="latin-1", byteorder=None): super(StataWriter, self).__init__(encoding) self._convert_dates = convert_dates self._write_index = write_index # attach nobs, nvars, data, varlist, typlist self._prepare_pandas(data) if byteorder is None: byteorder = sys.byteorder self._byteorder = _set_endianness(byteorder) self._file = _open_file_binary_write( fname, self._encoding or self._default_encoding ) self.type_converters = {253: np.long, 252: int}