本文整理汇总了Python中numpy.intc方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.intc方法的具体用法?Python numpy.intc怎么用?Python numpy.intc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.intc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_jds
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [as 别名]
def set_jds(self, val1, val2):
"""Parse the time strings contained in val1 and set jd1, jd2"""
iterator = np.nditer([val1, None, None, None, None, None, None],
op_dtypes=([val1.dtype] + 5 * [np.intc]
+ [np.double]))
try:
for val, iy, im, id, ihr, imin, dsec in iterator:
timestr = val.item()
components = timestr.split()
iy[...], im[...], id[...], ihr[...], imin[...], sec = (
int(component) for component in components[:-1])
dsec[...] = sec + float(components[-1])
except Exception:
raise ValueError('Time {0} does not match {1} format'
.format(timestr, self.name))
self.jd1, self.jd2 = erfa.dtf2d(
self.scale.upper().encode('utf8'), *iterator.operands[1:])
示例2: nested_to_ring
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [as 别名]
def nested_to_ring(nested_index, nside):
"""
Convert a HEALPix 'nested' index to a HEALPix 'ring' index
Parameters
----------
nested_index : int or `~numpy.ndarray`
Healpix index using the 'nested' ordering
nside : int or `~numpy.ndarray`
Number of pixels along the side of each of the 12 top-level HEALPix tiles
Returns
-------
ring_index : int or `~numpy.ndarray`
Healpix index using the 'ring' ordering
"""
nside = np.asarray(nside, dtype=np.intc)
return _core.nested_to_ring(nested_index, nside)
示例3: _unsigned_subtract
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [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)
示例4: lists_to_matrix
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [as 别名]
def lists_to_matrix(self, WS, DS):
"""Convert array of word (or topic) and document indices to doc-term array
Parameters
-----------
(WS, DS) : tuple of two arrays
WS[k] contains the kth word in the corpus
DS[k] contains the document index for the kth word
Returns
-------
doc_word : array (D, V)
document-term array of counts
"""
D = max(DS) + 1
V = max(WS) + 1
doc_word = np.empty((D, V), dtype=np.intc)
for d in range(D):
for v in range(V):
doc_word[d, v] = np.count_nonzero(WS[DS == d] == v)
return doc_word
示例5: _unsigned_subtract
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [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)
示例6: transpose
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [as 别名]
def transpose(self, axes=None, copy=False):
if axes is not None:
raise ValueError(("Sparse matrices do not support "
"an 'axes' parameter because swapping "
"dimensions is the only logical permutation."))
num_rows, num_cols = self.shape
max_dim = max(self.shape)
# flip diagonal offsets
offsets = -self.offsets
# re-align the data matrix
r = np.arange(len(offsets), dtype=np.intc)[:, None]
c = np.arange(num_rows, dtype=np.intc) - (offsets % max_dim)[:, None]
pad_amount = max(0, max_dim-self.data.shape[1])
data = np.hstack((self.data, np.zeros((self.data.shape[0], pad_amount),
dtype=self.data.dtype)))
data = data[r, c]
return dia_matrix((data, offsets), shape=(
num_cols, num_rows), copy=copy)
示例7: perform
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [as 别名]
def perform(self, node, inputs, out):
# TODO support broadcast!
# TODO assert all input have the same shape
z, = out
if (z[0] is None or
z[0].shape != inputs[0].shape or
not z[0].is_c_contiguous()):
z[0] = theano.sandbox.cuda.CudaNdarray.zeros(inputs[0].shape)
if inputs[0].shape != inputs[1].shape:
raise TypeError("PycudaElemwiseSourceModuleOp:"
" inputs don't have the same shape!")
if inputs[0].size > 512:
grid = (int(numpy.ceil(inputs[0].size / 512.)), 1)
block = (512, 1, 1)
else:
grid = (1, 1)
block = (inputs[0].shape[0], inputs[0].shape[1], 1)
self.pycuda_fct(inputs[0], inputs[1], z[0],
numpy.intc(inputs[1].size), block=block, grid=grid)
示例8: make_thunk
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [as 别名]
def make_thunk(self, node, storage_map, _, _2):
mod = SourceModule("""
__global__ void my_fct(float * i0, float * o0, int size) {
int i = blockIdx.x*blockDim.x + threadIdx.x;
if(i<size){
o0[i] = i0[i]*2;
}
}""")
pycuda_fct = mod.get_function("my_fct")
inputs = [ storage_map[v] for v in node.inputs]
outputs = [ storage_map[v] for v in node.outputs]
def thunk():
z = outputs[0]
if z[0] is None or z[0].shape!=inputs[0][0].shape:
z[0] = cuda.CudaNdarray.zeros(inputs[0][0].shape)
grid = (int(numpy.ceil(inputs[0][0].size / 512.)),1)
pycuda_fct(inputs[0][0], z[0], numpy.intc(inputs[0][0].size),
block=(512,1,1), grid=grid)
return thunk
示例9: attributes_encoder
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [as 别名]
def attributes_encoder(attr):
"""Custom encoder for copying file attributes in Python 3"""
if isinstance(attr, (bytes, bytearray)):
return attr.decode('utf-8')
if isinstance(attr, (np.int_, np.intc, np.intp, np.int8, np.int16, np.int32,
np.int64, np.uint8, np.uint16, np.uint32, np.uint64)):
return int(attr)
elif isinstance(attr, (np.float_, np.float16, np.float32, np.float64)):
return float(attr)
elif isinstance(attr, (np.ndarray)):
if not isinstance(attr[0], (object)):
return attr.tolist()
elif isinstance(attr, (np.bool_)):
return bool(attr)
elif isinstance(attr, (np.void)):
return None
else:
return attr
#-- PURPOSE: help module to describe the optional input parameters
示例10: _mul_sparse_matrix
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [as 别名]
def _mul_sparse_matrix(self, other):
M, K1 = self.shape
K2, N = other.shape
major_axis = self._swap((M,N))[0]
indptr = np.empty(major_axis + 1, dtype=np.intc)
other = self.__class__(other) # convert to this format
fn = getattr(sparsetools, self.format + '_matmat_pass1')
fn(M, N, self.indptr, self.indices,
other.indptr, other.indices,
indptr)
nnz = indptr[-1]
indices = np.empty(nnz, dtype=np.intc)
data = np.empty(nnz, dtype=upcast(self.dtype,other.dtype))
fn = getattr(sparsetools, self.format + '_matmat_pass2')
fn(M, N, self.indptr, self.indices, self.data,
other.indptr, other.indices, other.data,
indptr, indices, data)
return self.__class__((data,indices,indptr),shape=(M,N))
示例11: tocoo
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [as 别名]
def tocoo(self,copy=True):
"""Return a COOrdinate representation of this matrix
When copy=False the index and data arrays are not copied.
"""
major_dim,minor_dim = self._swap(self.shape)
data = self.data
minor_indices = self.indices
if copy:
data = data.copy()
minor_indices = minor_indices.copy()
major_indices = np.empty(len(minor_indices), dtype=np.intc)
sparsetools.expandptr(major_dim,self.indptr,major_indices)
row,col = self._swap((major_indices,minor_indices))
from .coo import coo_matrix
return coo_matrix((data,(row,col)), self.shape)
示例12: tocsr
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [as 别名]
def tocsr(self):
""" Return Compressed Sparse Row format arrays for this matrix.
"""
indptr = np.asarray([len(x) for x in self.rows], dtype=np.intc)
indptr = np.concatenate((np.array([0], dtype=np.intc), np.cumsum(indptr)))
nnz = indptr[-1]
indices = []
for x in self.rows:
indices.extend(x)
indices = np.asarray(indices, dtype=np.intc)
data = []
for x in self.data:
data.extend(x)
data = np.asarray(data, dtype=self.dtype)
from .csr import csr_matrix
return csr_matrix((data, indices, indptr), shape=self.shape)
示例13: _validate_X_predict
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [as 别名]
def _validate_X_predict(self, X, check_input):
"""Validate X whenever one tries to predict, apply, predict_proba"""
if check_input:
X = check_array(X, dtype=DTYPE, accept_sparse="csr")
if issparse(X) and (X.indices.dtype != np.intc or
X.indptr.dtype != np.intc):
raise ValueError("No support for np.int64 index based "
"sparse matrices")
n_features = X.shape[1]
if self.n_features_ != n_features:
raise ValueError("Number of features of the model must "
"match the input. Model n_features is %s and "
"input n_features is %s "
% (self.n_features_, n_features))
return X
示例14: _default
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [as 别名]
def _default(obj):
"""
Convert dates and numpy objects in a json serializable format.
"""
if isinstance(obj, datetime):
return obj.strftime('%Y-%m-%dT%H:%M:%SZ')
elif isinstance(obj, date):
return obj.strftime('%Y-%m-%d')
elif isinstance(obj, (np.int_, np.intc, np.intp, np.int8, np.int16,
np.int32, np.int64, np.uint8, np.uint16,
np.uint32, np.uint64)):
return int(obj)
elif isinstance(obj, np.bool_):
return bool(obj)
elif isinstance(obj, (np.float_, np.float16, np.float32, np.float64,
np.complex_, np.complex64, np.complex128)):
return float(obj)
raise TypeError(f"Object of type '{obj.__class__.__name__}' is not JSON serializable")
示例15: lists_to_matrix
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import intc [as 别名]
def lists_to_matrix(WS, DS):
"""Convert array of word (or topic) and document indices to doc-term array
Parameters
-----------
(WS, DS) : tuple of two arrays
WS[k] contains the kth word in the corpus
DS[k] contains the document index for the kth word
Returns
-------
doc_word : array (D, V)
document-term array of counts
"""
D = max(DS) + 1
V = max(WS) + 1
doc_word = np.empty((D, V), dtype=np.intc)
for d in range(D):
for v in range(V):
doc_word[d, v] = np.count_nonzero(WS[DS == d] == v)
return doc_word