本文整理汇总了Python中numpy.number方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.number方法的具体用法?Python numpy.number怎么用?Python numpy.number使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.number方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: revisitFilter
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def revisitFilter(self,sInds,tmpCurrentTimeNorm):
"""Helper method for Overloading Revisit Filtering
Args:
sInds - indices of stars still in observation list
tmpCurrentTimeNorm (MJD) - the simulation time after overhead was added in MJD form
Returns:
sInds - indices of stars still in observation list
"""
tovisit = np.zeros(self.TargetList.nStars, dtype=bool)
if len(sInds) > 0:
tovisit[sInds] = ((self.starVisits[sInds] == min(self.starVisits[sInds])) \
& (self.starVisits[sInds] < self.nVisitsMax))#Checks that no star has exceeded the number of revisits and the indicies of all considered stars have minimum number of observations
#The above condition should prevent revisits so long as all stars have not been observed
if self.starRevisit.size != 0:
dt_rev = np.abs(self.starRevisit[:,1]*u.day - tmpCurrentTimeNorm)
ind_rev = [int(x) for x in self.starRevisit[dt_rev < self.dt_max,0]
if x in sInds]
tovisit[ind_rev] = (self.starVisits[ind_rev] < self.nVisitsMax)
sInds = np.where(tovisit)[0]
return sInds
示例2: one_from_two_pdm
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def one_from_two_pdm(two_pdm, nelec):
'''Return a 1-rdm, given a 2-rdm to contract.
Args:
two_pdm : ndarray
A (spin-free) 2-particle reduced density matrix.
nelec: int
The number of electrons contributing to the RDMs.
Returns:
one_pdm : ndarray
The (spin-free) 1-particle reduced density matrix.
'''
# Last two indices refer to middle two second quantized operators in the 2RDM
one_pdm = numpy.einsum('ikjj->ik', two_pdm)
one_pdm /= (numpy.sum(nelec)-1)
return one_pdm
示例3: kernel
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def kernel(self, h1e, eri, norb, nelec, ci0=None,
tol=None, lindep=None, max_cycle=None, max_space=None,
nroots=None, davidson_only=None, pspace_size=None,
orbsym=None, wfnsym=None, ecore=0, **kwargs):
if isinstance(nelec, (int, numpy.number)):
nelecb = nelec//2
neleca = nelec - nelecb
else:
neleca, nelecb = nelec
link_indexa = cistring.gen_linkstr_index(range(norb), neleca)
link_indexb = cistring.gen_linkstr_index(range(norb), nelecb)
e, c = direct_spin1.kernel_ms1(self, h1e, eri, norb, nelec, ci0,
(link_indexa,link_indexb),
tol, lindep, max_cycle, max_space, nroots,
davidson_only, pspace_size, ecore=ecore,
**kwargs)
self.eci, self.ci = e, c
return e, c
示例4: reorder_eri
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def reorder_eri(eri, norb, orbsym):
if orbsym is None:
return [eri], numpy.arange(norb), numpy.zeros(norb,dtype=numpy.int32)
# map irrep IDs of Dooh or Coov to D2h, C2v
# see symm.basis.linearmole_symm_descent
orbsym = numpy.asarray(orbsym) % 10
# irrep of (ij| pair
trilirrep = (orbsym[:,None]^orbsym)[numpy.tril_indices(norb)]
# and the number of occurence for each irrep
dimirrep = numpy.asarray(numpy.bincount(trilirrep), dtype=numpy.int32)
# we sort the irreps of (ij| pair, to group the pairs which have same irreps
# "order" is irrep-id-sorted index. The (ij| paired is ordered that the
# pair-id given by order[0] comes first in the sorted pair
# "rank" is a sorted "order". Given nth (ij| pair, it returns the place(rank)
# of the sorted pair
old_eri_irrep = numpy.asarray(trilirrep, dtype=numpy.int32)
rank_in_irrep = numpy.empty_like(old_eri_irrep)
p0 = 0
eri_irs = [numpy.zeros((0,0))] * TOTIRREPS
for ir, nnorb in enumerate(dimirrep):
idx = numpy.asarray(numpy.where(trilirrep == ir)[0], dtype=numpy.int32)
rank_in_irrep[idx] = numpy.arange(nnorb, dtype=numpy.int32)
eri_irs[ir] = lib.take_2d(eri, idx, idx)
p0 += nnorb
return eri_irs, rank_in_irrep, old_eri_irrep
示例5: write_ci
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def write_ci(fout, fcivec, norb, nelec, ncore=0):
from pyscf import fci
if isinstance(nelec, (int, numpy.number)):
nelecb = nelec//2
neleca = nelec - nelecb
else:
neleca, nelecb = nelec
fout.write('NELACTIVE, NDETS, NORBCORE, NORBACTIVE\n')
fout.write(' %5d %5d %5d %5d\n' % (neleca+nelecb, fcivec.size, ncore, norb))
fout.write('COEFFICIENT/ OCCUPIED ACTIVE SPIN ORBITALS\n')
nb = fci.cistring.num_strings(norb, nelecb)
stringsa = fci.cistring.gen_strings4orblist(range(norb), neleca)
stringsb = fci.cistring.gen_strings4orblist(range(norb), nelecb)
def str2orbidx(string, ncore):
bstring = bin(string)
return [i+1+ncore for i,s in enumerate(bstring[::-1]) if s == '1']
addrs = numpy.argsort(abs(fcivec.ravel()))
for iaddr in reversed(addrs):
addra, addrb = divmod(iaddr, nb)
idxa = ['%3d' % x for x in str2orbidx(stringsa[addra], ncore)]
idxb = ['%3d' % (-x) for x in str2orbidx(stringsb[addrb], ncore)]
#TODO:add a cuttoff and a counter for ndets
fout.write('%18.10E %s %s\n' % (fcivec[addra,addrb], ' '.join(idxa), ' '.join(idxb)))
示例6: from_fcivec
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def from_fcivec(ci0, norb, nelec, frozen=None):
'''Extract CISD coefficients from FCI coefficients'''
if not (frozen is None or frozen == 0):
raise NotImplementedError
if isinstance(nelec, (int, numpy.number)):
nelecb = nelec//2
neleca = nelec - nelecb
else:
neleca, nelecb = nelec
nocc = neleca
nvir = norb - nocc
t1addr, t1sign = t1strs(norb, nocc)
c0 = ci0[0,0]
c1 = ci0[0,t1addr] * t1sign
c2 = numpy.einsum('i,j,ij->ij', t1sign, t1sign, ci0[t1addr[:,None],t1addr])
c1 = c1.reshape(nocc,nvir)
c2 = c2.reshape(nocc,nvir,nocc,nvir).transpose(0,2,1,3)
return amplitudes_to_cisdvec(c0, c1, c2)
示例7: __rmul__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def __rmul__(sys1, sys2):
"""Pre-multiply an input/output systems by a scalar/matrix"""
if isinstance(sys2, (int, float, np.number)):
# TODO: Scale the output
raise NotImplemented("Scalar multiplication not yet implemented")
elif isinstance(sys2, np.ndarray):
# TODO: Post-multiply by a matrix
raise NotImplemented("Matrix multiplication not yet implemented")
elif isinstance(sys1, StateSpace) and isinstance(sys2, StateSpace):
# Special case: maintain linear systems structure
new_ss_sys = StateSpace.__rmul__(sys1, sys2)
# TODO: set input and output names
new_io_sys = LinearIOSystem(new_ss_sys)
return new_io_sys
elif not isinstance(sys2, InputOutputSystem):
raise ValueError("Unknown I/O system object ", sys1)
else:
# Both systetms are InputOutputSystems => use __mul__
return InputOutputSystem.__mul__(sys2, sys1)
示例8: set_outputs
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def set_outputs(self, outputs, prefix='y'):
"""Set the number/names of the system outputs.
Parameters
----------
outputs : int, list of str, or None
Description of the system outputs. This can be given as an integer
count or as a list of strings that name the individual signals.
If an integer count is specified, the names of the signal will be
of the form `u[i]` (where the prefix `u` can be changed using the
optional prefix parameter).
prefix : string, optional
If `outputs` is an integer, create the names of the states using
the given prefix (default = 'y'). The names of the input will be
of the form `prefix[i]`.
"""
self.noutputs, self.output_index = \
self._process_signal_list(outputs, prefix=prefix)
示例9: set_states
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def set_states(self, states, prefix='x'):
"""Set the number/names of the system states.
Parameters
----------
states : int, list of str, or None
Description of the system states. This can be given as an integer
count or as a list of strings that name the individual signals.
If an integer count is specified, the names of the signal will be
of the form `u[i]` (where the prefix `u` can be changed using the
optional prefix parameter).
prefix : string, optional
If `states` is an integer, create the names of the states using
the given prefix (default = 'x'). The names of the input will be
of the form `prefix[i]`.
"""
self.nstates, self.state_index = \
self._process_signal_list(states, prefix=prefix)
示例10: set_input_map
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def set_input_map(self, input_map):
"""Set the input map for an interconnected I/O system.
Parameters
----------
input_map : 2D array
Specify the matrix that will be used to multiply the vector of
system inputs to obtain the vector of subsystem inputs. These
values are added to the inputs specified in the connection map.
"""
# Figure out the number of internal inputs
ninputs = sum(sys.ninputs for sys in self.syslist)
# Make sure the input map is the right size
if input_map.shape[0] != ninputs:
ValueError("Input map is not the right shape")
self.input_map = input_map
self.ninputs = input_map.shape[1]
示例11: __truediv__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def __truediv__(self, other):
"""Divide two LTI objects."""
if isinstance(other, (int, float, complex, np.number)):
return FRD(self.fresp * (1/other), self.omega,
smooth=(self.ifunc is not None))
else:
other = _convertToFRD(other, omega=self.omega)
if (self.inputs > 1 or self.outputs > 1 or
other.inputs > 1 or other.outputs > 1):
raise NotImplementedError(
"FRD.__truediv__ is currently only implemented for SISO "
"systems.")
return FRD(self.fresp/other.fresp, self.omega,
smooth=(self.ifunc is not None) and
(other.ifunc is not None))
# TODO: Remove when transition to python3 complete
示例12: evalfr
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def evalfr(self, omega):
"""Evaluate a transfer function at a single angular frequency.
self._evalfr(omega) returns the value of the frequency response
at frequency omega.
Note that a "normal" FRD only returns values for which there is an
entry in the omega vector. An interpolating FRD can return
intermediate values.
"""
warn("FRD.evalfr(omega) will be deprecated in a future release "
"of python-control; use sys.eval(omega) instead",
PendingDeprecationWarning) # pragma: no coverage
return self._evalfr(omega)
# Define the `eval` function to evaluate an FRD at a given (real)
# frequency. Note that we choose to use `eval` instead of `evalfr` to
# avoid confusion with :func:`evalfr`, which takes a complex number as its
# argument. Similarly, we don't use `__call__` to avoid confusion between
# G(s) for a transfer function and G(omega) for an FRD object.
示例13: issiso
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def issiso(sys, strict=False):
"""
Check to see if a system is single input, single output
Parameters
----------
sys : LTI system
System to be checked
strict: bool (default = False)
If strict is True, do not treat scalars as SISO
"""
if isinstance(sys, (int, float, complex, np.number)) and not strict:
return True
elif not isinstance(sys, LTI):
raise ValueError("Object is not an LTI system")
# Done with the tricky stuff...
return sys.issiso()
# Return the timebase (with conversion if unspecified)
示例14: timebase
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def timebase(sys, strict=True):
"""Return the timebase for an LTI system
dt = timebase(sys)
returns the timebase for a system 'sys'. If the strict option is
set to False, dt = True will be returned as 1.
"""
# System needs to be either a constant or an LTI system
if isinstance(sys, (int, float, complex, np.number)):
return None
elif not isinstance(sys, LTI):
raise ValueError("Timebase not defined")
# Return the sample time, with converstion to float if strict is false
if (sys.dt == None):
return None
elif (strict):
return float(sys.dt)
return sys.dt
# Check to see if two timebases are equal
示例15: test_ticket_1539
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import number [as 别名]
def test_ticket_1539(self):
dtypes = [x for x in np.typeDict.values()
if (issubclass(x, np.number)
and not issubclass(x, np.timedelta64))]
a = np.array([], np.bool_) # not x[0] because it is unordered
failures = []
for x in dtypes:
b = a.astype(x)
for y in dtypes:
c = a.astype(y)
try:
np.dot(b, c)
except TypeError:
failures.append((x, y))
if failures:
raise AssertionError("Failures: %r" % failures)