• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

All Samples(4746)  |  Call(4565)  |  Derive(0)  |  Import(181)
Sum of array elements over a given axis.

Parameters
----------
a : array_like
    Elements to sum.
axis : integer, optional
    Axis over which the sum is taken. By default `axis` is None,
    and all elements are summed.
dtype : dtype, optional
    The type of the returned array and of the accumulator in which
    the elements are summed.  By default, the dtype of `a` is used.
    An exception is when `a` has an integer type with less precision
    than the default platform integer.  In that case, the default
    platform integer is used instead.
out : ndarray, optional
    Array into which the output is placed.  By default, a new array is
    created.  If `out` is given, it must be of the appropriate shape
    (the shape of `a` with `axis` removed, i.e.,
    ``numpy.delete(a.shape, axis)``).  Its type is preserved. See
    `doc.ufuncs` (Section "Output arguments") for more details.

Returns
-------
sum_along_axis : ndarray
    An array with the same shape as `a`, with the specified
    axis removed.   If `a` is a 0-d array, or if `axis` is None, a scalar
    is returned.  If an output array is specified, a reference to
    `out` is returned.

See Also
--------
ndarray.sum : Equivalent method.

cumsum : Cumulative sum of array elements.

trapz : Integration of array values using the composite trapezoidal rule.

mean, average

Notes
-----
Arithmetic is modular when using integer types, and no error is
raised on overflow.

Examples
--------
>>> np.sum([0.5, 1.5])
2.0
>>> np.sum([0.5, 0.7, 0.2, 1.5], dtype=np.int32)
1
>>> np.sum([[0, 1], [0, 5]])
6
>>> np.sum([[0, 1], [0, 5]], axis=0)
array([0, 6])
>>> np.sum([[0, 1], [0, 5]], axis=1)
array([1, 5])

If the accumulator is too small, overflow occurs:

>>> np.ones(128, dtype=np.int8).sum(dtype=np.int8)
-128

        def sum(a, axis=None, dtype=None, out=None):
    """
    Sum of array elements over a given axis.

    Parameters
    ----------
    a : array_like
        Elements to sum.
    axis : integer, optional
        Axis over which the sum is taken. By default `axis` is None,
        and all elements are summed.
    dtype : dtype, optional
        The type of the returned array and of the accumulator in which
        the elements are summed.  By default, the dtype of `a` is used.
        An exception is when `a` has an integer type with less precision
        than the default platform integer.  In that case, the default
        platform integer is used instead.
    out : ndarray, optional
        Array into which the output is placed.  By default, a new array is
        created.  If `out` is given, it must be of the appropriate shape
        (the shape of `a` with `axis` removed, i.e.,
        ``numpy.delete(a.shape, axis)``).  Its type is preserved. See
        `doc.ufuncs` (Section "Output arguments") for more details.

    Returns
    -------
    sum_along_axis : ndarray
        An array with the same shape as `a`, with the specified
        axis removed.   If `a` is a 0-d array, or if `axis` is None, a scalar
        is returned.  If an output array is specified, a reference to
        `out` is returned.

    See Also
    --------
    ndarray.sum : Equivalent method.

    cumsum : Cumulative sum of array elements.

    trapz : Integration of array values using the composite trapezoidal rule.

    mean, average

    Notes
    -----
    Arithmetic is modular when using integer types, and no error is
    raised on overflow.

    Examples
    --------
    >>> np.sum([0.5, 1.5])
    2.0
    >>> np.sum([0.5, 0.7, 0.2, 1.5], dtype=np.int32)
    1
    >>> np.sum([[0, 1], [0, 5]])
    6
    >>> np.sum([[0, 1], [0, 5]], axis=0)
    array([0, 6])
    >>> np.sum([[0, 1], [0, 5]], axis=1)
    array([1, 5])

    If the accumulator is too small, overflow occurs:

    >>> np.ones(128, dtype=np.int8).sum(dtype=np.int8)
    -128

    """
    if isinstance(a, _gentype):
        res = _sum_(a)
        if out is not None:
            out[...] = res
            return out
        return res
    try:
        sum = a.sum
    except AttributeError:
        return _wrapit(a, 'sum', axis, dtype, out)
    return sum(axis, dtype, out)
        


src/y/t/yt-1.7/yt/extensions/volume_rendering/software_sampler.py   yt(Download)
            total_cells += na.prod(b.my_data[0].shape)
        LE = na.array(LE) - self.back_center
        RE = na.array(RE) - self.back_center
        LE = na.sum(LE * self.unit_vectors[2], axis=1)
        RE = na.sum(RE * self.unit_vectors[2], axis=1)
        dist = na.minimum(LE, RE)
        ind = na.argsort(dist)

src/a/l/algopy-HEAD/documentation/ICCS2010/odoe_example.py   algopy(Download)
 
# accumulate over the different directions
qbar = UTPM(numpy.zeros((D,1)))
qbar.data[:,0] = numpy.sum( qbars.data[:,:], axis=1)
 
#############################################
# compare with analytical solution

src/p/y/PyMVPA-HEAD/doc/examples/pylab_2d.py   PyMVPA(Download)
            res = np.asarray(pre)
        elif 'Nearest-Ne' in c:
            # Use the votes
            res = clf.ca.estimates[:, 1] / np.sum(clf.ca.estimates, axis=1)
        elif c == 'Logistic Regression':
            # get out the values used for the prediction
            res = np.asarray(clf.ca.estimates)

src/p/y/PyPWDG-HEAD/examples/3D/test.py   PyPWDG(Download)
    t.append(time.time())
    A2 = [A,A,A,A]
    t.append(time.time())
    B2 = numpy.sum(A2, axis=0)
    t.append(time.time())
    l = len(A2)
    B3 = numpy.reshape(numpy.dot(numpy.ones(l), numpy.reshape(A2, (l, -1))), (n,n))

src/n/i/NiPy-OLD-HEAD/examples/neurospin/demo_dmtx.py   NiPy-OLD(Download)
 
import matplotlib.pylab as mp
mp.figure()
mp.imshow(x1/np.sqrt(np.sum(x1**2,0)),interpolation='Nearest', aspect='auto')
mp.xlabel('conditions')
mp.ylabel('scan number')
if name1!=None:
    mp.xticks(np.arange(len(name1)),name1,rotation=60,ha='right')
    mp.subplots_adjust(top=0.95,bottom=0.25)
mp.title('Example of event-related design matrix')
 
mp.figure()
mp.imshow(x2/np.sqrt(np.sum(x2**2,0)),interpolation='Nearest', aspect='auto')
mp.title('Example of block design matrix')
 
mp.figure()
mp.imshow(x3/np.sqrt(np.sum(x3**2,0)),interpolation='Nearest', aspect='auto')
mp.xlabel('conditions')
mp.ylabel('scan number')
if name3!=None:

src/n/i/nipy-HEAD/examples/formula/parametric_design.py   nipy(Download)
# the columns or d/d_b0 and d/dl
 
tt = tval.view(np.float)
v1 = np.sum([hrf.glovert(tt - s)*np.exp(-4.5*a) for s,a  in zip(t, dt)], 0)
v2 = np.sum([-3.5*a*hrf.glovert(tt - s)*np.exp(-4.5*a) for s,a  in zip(t, dt)], 0)
 
V = np.array([v1,v2]).T

src/n/i/NiPy-OLD-HEAD/examples/formula/parametric_design.py   NiPy-OLD(Download)
# the columns or d/d_b0 and d/dl
 
tt = tval.view(np.float)
v1 = np.sum([hrf.glovert(tt - s)*np.exp(-4.5*a) for s,a  in zip(t, dt)], 0)
v2 = np.sum([-3.5*a*hrf.glovert(tt - s)*np.exp(-4.5*a) for s,a  in zip(t, dt)], 0)
 
V = np.array([v1,v2]).T

src/s/c/scikits.statsmodels-0.2.0/scikits/statsmodels/sandbox/regression/example_kernridge.py   scikits.statsmodels(Download)
#xs1 /= np.std(xs1[::k,:],0)   # normalize scale, could use cov to normalize
##y1true = np.sum(np.sin(xs1)+np.sqrt(xs1),1)[:,np.newaxis]
xs1 = np.sin(xs)#[:,np.newaxis]
y1true = np.sum(xs1 + 0.01*np.sqrt(np.abs(xs1)),1)[:,np.newaxis]
y1 = y1true + 0.10 * np.random.randn(m,1)
 
stride = 3 #use only some points as trainig points e.g 2 means every 2nd

src/i/p/ipython-py3k-HEAD/docs/examples/kernel/phistogram.py   ipython-py3k(Download)
    lower_edges = rc.pull('lower_edges', targets=0)
    hist_array = rc.gather('hist')
    hist_array.shape = (nengines,-1)
    total_hist = numpy.sum(hist_array, 0)
    if normed:
        total_hist = total_hist/numpy.sum(total_hist,dtype=float)
    return total_hist, lower_edges

src/n/i/NiPy-OLD-HEAD/examples/neurospin/neurospy/DesignMatrix.py   NiPy-OLD(Download)
    def show(self):
        """Vizualization of self
        """
        x = self._design
        import matplotlib.pylab as mp
        mp.figure()
        mp.imshow(x/np.sqrt(np.sum(x**2,0)),interpolation='Nearest', aspect='auto')

  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  Next