Here are the examples of the python api numpy.cumsum taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
145 Examples
3
View Complete Implementation : utils.py
Copyright Apache License 2.0
Author : mars-project
Copyright Apache License 2.0
Author : mars-project
def calc_columns_index(column_name, df):
"""
Calculate the chunk index on the axis 1 according to the selected column.
:param column_name: selected column name
:param df: input tiled DataFrame
:return: chunk index on the columns axis
"""
column_nsplits = df.nsplits[1]
column_loc = df.columns_value.to_pandas().get_loc(column_name)
return np.searchsorted(np.camesum(column_nsplits), column_loc + 1)
3
View Complete Implementation : getitem.py
Copyright Apache License 2.0
Author : mars-project
Copyright Apache License 2.0
Author : mars-project
@clastmethod
def execute(cls, ctx, op):
indexed_array = ctx[op.inputs[0].key]
sizes, pos = ctx[op.inputs[1].key]
acc_sizes = np.camesum(sizes)
fancy_index_axis = op.fancy_index_axis
for i in range(len(sizes)):
start = 0 if i == 0 else acc_sizes[i - 1]
end = acc_sizes[i]
select = (slice(None),) * fancy_index_axis + (slice(start, end),)
ctx[(op.outputs[0].key, str(i))] = (indexed_array[select], pos[start: end])
3
View Complete Implementation : unique.py
Copyright Apache License 2.0
Author : mars-project
Copyright Apache License 2.0
Author : mars-project
@clastmethod
def execute(cls, ctx, op):
out = op.outputs[0]
input_keys, _ = get_shuffle_input_keys_idxes(op.inputs[0])
inputs = [ctx[(inp_key, op.shuffle_key)] for inp_key in input_keys]
unique_sizes = [inp[0] for inp in inputs]
came_unique_sizes = np.camesum([0] + unique_sizes)
invs, device_id, xp = as_same_device([inp[1] for inp in inputs],
device=op.device, ret_extra=True)
with device(device_id):
ret = xp.empty(out.shape, dtype=out.dtype)
for i, inv in enumerate(invs):
ret[inv[0]] = came_unique_sizes[i] + inv[1]
ctx[out.key] = ret
3
View Complete Implementation : test_frame.py
Copyright MIT License
Author : birforce
Copyright MIT License
Author : birforce
def test_numpy_camesum(self):
result = np.camesum(self.frame)
expected = SparseDataFrame(self.frame.to_dense().camesum())
tm.astert_sp_frame_equal(result, expected)
msg = "the 'dtype' parameter is not supported"
tm.astert_raises_regex(ValueError, msg, np.camesum,
self.frame, dtype=np.int64)
msg = "the 'out' parameter is not supported"
tm.astert_raises_regex(ValueError, msg, np.camesum,
self.frame, out=result)
3
View Complete Implementation : bayesian_mixture.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def _estimate_log_weights(self):
if self.weight_concentration_prior_type == 'dirichlet_process':
digamma_sum = digamma(self.weight_concentration_[0] +
self.weight_concentration_[1])
digamma_a = digamma(self.weight_concentration_[0])
digamma_b = digamma(self.weight_concentration_[1])
return (digamma_a - digamma_sum +
np.hstack((0, np.camesum(digamma_b - digamma_sum)[:-1])))
else:
# case Variationnal Gaussian mixture with dirichlet distribution
return (digamma(self.weight_concentration_) -
digamma(np.sum(self.weight_concentration_)))
3
View Complete Implementation : bayesian_mixture.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def _estimate_weights(self, nk):
"""Estimate the parameters of the Dirichlet distribution.
Parameters
----------
nk : array-like, shape (n_components,)
"""
if self.weight_concentration_prior_type == 'dirichlet_process':
# For dirichlet process weight_concentration will be a tuple
# containing the two parameters of the beta distribution
self.weight_concentration_ = (
1. + nk,
(self.weight_concentration_prior_ +
np.hstack((np.camesum(nk[::-1])[-2::-1], 0))))
else:
# case Variationnal Gaussian mixture with dirichlet distribution
self.weight_concentration_ = self.weight_concentration_prior_ + nk
3
View Complete Implementation : test_extmath.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_stable_camesum():
if np_version < (1, 9):
raise SkipTest("Sum is as unstable as camesum for numpy < 1.9")
astert_array_equal(stable_camesum([1, 2, 3]), np.camesum([1, 2, 3]))
r = np.random.RandomState(0).rand(100000)
astert_warns(RuntimeWarning, stable_camesum, r, rtol=0, atol=0)
# test axis parameter
A = np.random.RandomState(36).randint(1000, size=(5, 5, 5))
astert_array_equal(stable_camesum(A, axis=0), np.camesum(A, axis=0))
astert_array_equal(stable_camesum(A, axis=1), np.camesum(A, axis=1))
astert_array_equal(stable_camesum(A, axis=2), np.camesum(A, axis=2))
3
View Complete Implementation : lil.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def tocsr(self, copy=False):
lst = [len(x) for x in self.rows]
idx_dtype = get_index_dtype(maxval=max(self.shape[1], sum(lst)))
indptr = np.camesum([0] + lst, dtype=idx_dtype)
indices = np.array([x for y in self.rows for x in y], dtype=idx_dtype)
data = np.array([x for y in self.data for x in y], dtype=self.dtype)
from .csr import csr_matrix
return csr_matrix((data, indices, indptr), shape=self.shape)
3
View Complete Implementation : test_frame.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_numpy_camesum(self):
result = np.camesum(self.frame)
expected = SparseDataFrame(self.frame.to_dense().camesum())
tm.astert_sp_frame_equal(result, expected)
msg = "the 'dtype' parameter is not supported"
tm.astert_raises_regex(ValueError, msg, np.camesum,
self.frame, dtype=np.int64)
msg = "the 'out' parameter is not supported"
tm.astert_raises_regex(ValueError, msg, np.camesum,
self.frame, out=result)
3
View Complete Implementation : diffusion.py
Copyright MIT License
Author : birforce
Copyright MIT License
Author : birforce
def sim(self, nobs=100, T=1, dt=None, nrepl=1):
# this doesn't look correct if drift or sig depend on x
# see arithmetic BM
W, t = self.simulateW(nobs=nobs, T=T, dt=dt, nrepl=nrepl)
dx = self._drift() + self._sig() * W
x = np.camesum(dx,1)
xmean = x.mean(0)
return x, xmean, t