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

All Samples(16539)  |  Call(15592)  |  Derive(0)  |  Import(947)
zeros(shape, dtype=float, order='C')

Return a new array of given shape and type, filled with zeros.

Parameters
----------
shape : int or sequence of ints
    Shape of the new array, e.g., ``(2, 3)`` or ``2``.
dtype : data-type, optional
    The desired data-type for the array, e.g., `numpy.int8`.  Default is
    `numpy.float64`.
order : {'C', 'F'}, optional
    Whether to store multidimensional data in C- or Fortran-contiguous
    (row- or column-wise) order in memory.

Returns
-------
out : ndarray
    Array of zeros with the given shape, dtype, and order.

See Also
--------
zeros_like : Return an array of zeros with shape and type of input.
ones_like : Return an array of ones with shape and type of input.
empty_like : Return an empty array with shape and type of input.
ones : Return a new array setting values to one.
empty : Return a new uninitialized array.

Examples
--------
>>> np.zeros(5)
array([ 0.,  0.,  0.,  0.,  0.])

>>> np.zeros((5,), dtype=numpy.int)
array([0, 0, 0, 0, 0])

>>> np.zeros((2, 1))
array([[ 0.],
       [ 0.]])

>>> s = (2,2)
>>> np.zeros(s)
array([[ 0.,  0.],
       [ 0.,  0.]])

>>> np.zeros((2,), dtype=[('x', 'i4'), ('y', 'i4')]) # custom dtype
array([(0, 0), (0, 0)],
      dtype=[('x', '<i4'), ('y', '<i4')])

src/a/l/algopy-HEAD/documentation/AD_tutorial_TU_Berlin/example7_simple_computation_of_the_hessian.py   algopy(Download)
at x = (3,7)
"""
 
import numpy; from numpy import sin,cos, array, zeros
from taylorpoly import UTPS
def f_fcn(x):
    return sin(x[0] + cos(x[1])*x[0])
 
S = array([[1,0,1],[0,1,1]], dtype=float)
P = S.shape[1]
print 'seed matrix with P = %d directions S = \n'%P, S
x1 = UTPS(zeros(1+2*P), P = P)
x2 = UTPS(zeros(1+2*P), P = P)
x2.data[0] = 7; x2.data[1::2] = S[1,:]
y = f_fcn([x1,x2])
print 'x1=',x1;  print 'x2=',x2; print 'y=',y
H = zeros((2,2),dtype=float)
H[0,0] = 2*y.coeff[0,2]
H[1,0] = H[0,1] = (y.coeff[2,2] - y.coeff[0,2] - y.coeff[1,2])
H[1,1] =  2*y.coeff[1,2]

src/p/y/pydy-HEAD/examples/rollingdisc/plot_rollingdisc.py   pydy(Download)
#!/usr/bin/env python
import rollingdisc_lib as rd
from scipy.integrate import odeint
from numpy import array, arange, zeros, roots, sin, cos, tan, pi, complex
import matplotlib.pyplot as plt
 
# Dimensions of a quarter
def plot_energy(t, x):
    # Plot the kinetic energy, potential energy, and total energy
    ke = zeros((n,1))
    pe = zeros((n,1))
    te = zeros((n,1))
    for i in range(n):
        ke[i], pe[i] = rd.energy(x[i,:], params)
def plot_eval():
    #### Eigenvalue plot #####
    u2 = arange(-30, 30.01, 0.01, dtype=complex)
    n = len(u1)
    eval = zeros((n,3), dtype=complex)
    for i, u in enumerate(u1):
        eval[i] = rd.evals(u, (g, r))
def animate_motion(x, k):
    # Animate using Visual-Python
    CO = zeros((n, 3))
    B2 = zeros((n, 3))
    C1 = zeros((n, 3))
    C3 = zeros((n, 3))
    CN = zeros((n, 3))

src/p/y/pyadolc-HEAD/examples/comparison_with_sympy.py   pyadolc(Download)
import sympy
import adolc
import numpy
from numpy import array, zeros, ones, shape
from numpy.random import random
from numpy.linalg import norm
 
def df(x):
    g = zeros(shape(x),dtype=float)
    for n in range(N):
        for d in range(D):
            for m in range(N):
                if n != m:
                    g[n,d] -= (x[n,d] - x[m,d])/norm(x[n,:]-x[m,:])**3
    return g
 
def ddf(x):
    N,D = shape(x)
    H = zeros((N,D,N,D),dtype=float)

src/p/y/python-opencl-HEAD/examples/ocl_bandwidth_test.py   python-opencl(Download)
'''
 
from time import clock, time
from numpy import arange, array, ndarray, zeros
import opencl
 
 
def test_bandwidth_range(start, end, increment, kind, devices):
    count = 1 + ((end - start) / increment)
    mem_sizes = ndarray(count, dtype=int)
    bandwidths = zeros(count, dtype=float)
 
    # Print information for use
    if kind == DEVICE_TO_HOST:

src/p/y/python-opencl-0.2/examples/ocl_bandwidth_test.py   python-opencl(Download)
'''
 
from time import clock, time
from numpy import arange, array, ndarray, zeros
import opencl
 
 
def test_bandwidth_range(start, end, increment, kind, devices):
    count = 1 + ((end - start) / increment)
    mem_sizes = ndarray(count, dtype=int)
    bandwidths = zeros(count, dtype=float)
 
    # Print information for use
    if kind == DEVICE_TO_HOST:

src/m/a/matplotlib-HEAD/py4science/examples/filtilt_demo.py   matplotlib(Download)
following code has been tested with Python 2.4.4 and Scipy 0.5.1.
"""
 
from numpy import (vstack, hstack, eye, ones, zeros, linalg,
                   newaxis, r_, flipud, convolve, matrix, array)
 
from scipy.signal import lfilter
    n=max(len(a),len(b))
 
    zin = (  eye(n-1) - hstack( (-a[1:n,newaxis],
                                 vstack((eye(n-2), zeros(n-2))))))
 
    zid =  b[1:n] - a[1:n]*b[0]
 
        raise ValueError(e)
 
    if len(a) < ntaps:
        a=r_[a,zeros(len(b)-len(a))]
 
    if len(b) < ntaps:
        b=r_[b,zeros(len(a)-len(b))]

src/p/y/pysparse-HEAD/trunk/examples/jdsym_test.py   pysparse(Download)
from pysparse.sparse import spmatrix
from pysparse.eigen import jdsym
from pysparse.itsolvers.krylov import qmrs
from numpy import zeros, dot, allclose, multiply, random
from math import sqrt
 
class diagPrecShifted:
    def __init__(self, A, M, sigma):
        self.shape = A.shape
        n = self.shape[0]
        self.dinv = zeros(n, 'd')
def computeResiduals(A, M, lmbd, Q):
    kconv = lmbd.shape[0]
    residuals = zeros((kconv, ), 'd')
    r = zeros((n, ), 'd')
    u = zeros((n, ), 'd')
    t = zeros((n, ), 'd')
    for k in xrange(kconv):
 
print 'Test 1'
 
lmbd_exact = zeros(ncv, 'd')
for k in xrange(ncv):
    lmbd_exact[k] =  A[k,k]
 
kconv, lmbd, Q, it, it_inner = jdsym.jdsym(As, None, None, ncv,
                                           0.0, tol, 150, qmrs,
                                           jmin=5, jmax=10, eps_tr=1e-4, clvl=1)
 
assert ncv == kconv
assert allclose(computeResiduals(As, None, lmbd, Q), zeros(kconv), 0.0, tol)
 
print 'Test 2',
 
lmbd_exact = zeros(ncv, 'd')
for k in xrange(ncv):
    lmbd_exact[k] =  A[k,k]/M[k,k]
 
                                           jmin=5, jmax=10, eps_tr=1e-4, clvl=1)
 
assert ncv == kconv
assert allclose(computeResiduals(As, Ms, lmbd, Q), zeros(kconv), 0.0, normM*tol)
assert allclose(lmbd, lmbd_exact, normM*tol*tol, 0.0)
 
print 'OK'
 
#-------------------------------------------------------------------------------
# Test 3: general case
 
print 'Test 3',
 
lmbd_exact = zeros(ncv, 'd')
                                           0.0, tol, 150, qmrs,
                                           jmin=5, jmax=10, eps_tr=1e-4, clvl=1)
assert ncv == kconv
assert allclose(computeResiduals(As, Ms, lmbd, Q), zeros(kconv), 0.0, normM*tol)
assert allclose(lmbd, lmbd_exact, normM*tol*tol, 0.0)
 
print 'OK'
 
#-------------------------------------------------------------------------------
# Test 4: K = None, with X0
 
print 'Test 4',
 
lmbd_exact = zeros(ncv, 'd')
                                           clvl=1, V0=X0)
 
assert ncv == kconv
assert allclose(computeResiduals(As, Ms, lmbd, Q), zeros(kconv), 0.0, normM*tol)
assert allclose(lmbd, lmbd_exact, normM*tol*tol, 0.0)
 
print 'OK'

src/p/y/pysparse-HEAD/examples/jdsym_test.py   pysparse(Download)
from pysparse.sparse import spmatrix
from pysparse.eigen import jdsym
from pysparse.itsolvers.krylov import qmrs
from numpy import zeros, dot, allclose, multiply, random
from math import sqrt
 
class diagPrecShifted:
    def __init__(self, A, M, sigma):
        self.shape = A.shape
        n = self.shape[0]
        self.dinv = zeros(n, 'd')
def computeResiduals(A, M, lmbd, Q):
    kconv = lmbd.shape[0]
    residuals = zeros((kconv, ), 'd')
    r = zeros((n, ), 'd')
    u = zeros((n, ), 'd')
    t = zeros((n, ), 'd')
    for k in xrange(kconv):
 
print 'Test 1'
 
lmbd_exact = zeros(ncv, 'd')
for k in xrange(ncv):
    lmbd_exact[k] =  A[k,k]
 
kconv, lmbd, Q, it, it_inner = jdsym.jdsym(As, None, None, ncv,
                                           0.0, tol, 150, qmrs,
                                           jmin=5, jmax=10, eps_tr=1e-4, clvl=1)
 
assert ncv == kconv
assert allclose(computeResiduals(As, None, lmbd, Q), zeros(kconv), 0.0, tol)
 
print 'Test 2',
 
lmbd_exact = zeros(ncv, 'd')
for k in xrange(ncv):
    lmbd_exact[k] =  A[k,k]/M[k,k]
 
                                           jmin=5, jmax=10, eps_tr=1e-4, clvl=1)
 
assert ncv == kconv
assert allclose(computeResiduals(As, Ms, lmbd, Q), zeros(kconv), 0.0, normM*tol)
assert allclose(lmbd, lmbd_exact, normM*tol*tol, 0.0)
 
print 'OK'
 
#-------------------------------------------------------------------------------
# Test 3: general case
 
print 'Test 3',
 
lmbd_exact = zeros(ncv, 'd')
                                           0.0, tol, 150, qmrs,
                                           jmin=5, jmax=10, eps_tr=1e-4, clvl=1)
assert ncv == kconv
assert allclose(computeResiduals(As, Ms, lmbd, Q), zeros(kconv), 0.0, normM*tol)
assert allclose(lmbd, lmbd_exact, normM*tol*tol, 0.0)
 
print 'OK'
 
#-------------------------------------------------------------------------------
# Test 4: K = None, with X0
 
print 'Test 4',
 
lmbd_exact = zeros(ncv, 'd')
                                           clvl=1, V0=X0)
 
assert ncv == kconv
assert allclose(computeResiduals(As, Ms, lmbd, Q), zeros(kconv), 0.0, normM*tol)
assert allclose(lmbd, lmbd_exact, normM*tol*tol, 0.0)
 
print 'OK'

src/c/s/csc-pysparse-HEAD/examples/jdsym_test.py   csc-pysparse(Download)
from pysparse import spmatrix, jdsym, itsolvers
from numpy import zeros, dot, allclose, multiply
from math import sqrt
import RandomArray
 
class diagPrecShifted:
    def __init__(self, A, M, sigma):
        self.shape = A.shape
        n = self.shape[0]
        self.dinv = zeros(n, 'd')
def computeResiduals(A, M, lmbd, Q):
    kconv = lmbd.shape[0]
    residuals = zeros((kconv, ), 'd')
    r = zeros((n, ), 'd')
    u = zeros((n, ), 'd')
    t = zeros((n, ), 'd')
    for k in xrange(kconv):
 
print 'Test 1'
 
lmbd_exact = zeros(ncv, 'd')
for k in xrange(ncv):
    lmbd_exact[k] =  A[k,k]
 
kconv, lmbd, Q, it, it_inner = jdsym.jdsym(As, None, None, ncv, 0.0, tol, 150, itsolvers.qmrs,
                                           jmin=5, jmax=10, eps_tr=1e-4, clvl=1)
 
assert ncv == kconv
assert allclose(computeResiduals(As, None, lmbd, Q), zeros(kconv), 0.0, tol)
 
print 'Test 2',
 
lmbd_exact = zeros(ncv, 'd')
for k in xrange(ncv):
    lmbd_exact[k] =  A[k,k]/M[k,k]
 
                                           jmin=5, jmax=10, eps_tr=1e-4, clvl=1)
 
assert ncv == kconv
assert allclose(computeResiduals(As, Ms, lmbd, Q), zeros(kconv), 0.0, normM*tol)
assert allclose(lmbd, lmbd_exact, normM*tol*tol, 0.0)
 
print 'OK'
 
#-------------------------------------------------------------------------------
# Test 3: general case
 
print 'Test 3',
 
lmbd_exact = zeros(ncv, 'd')
kconv, lmbd, Q, it, it_inner = jdsym.jdsym(As, Ms, K, ncv, 0.0, tol, 150, itsolvers.qmrs,
                                           jmin=5, jmax=10, eps_tr=1e-4, clvl=1)
assert ncv == kconv
assert allclose(computeResiduals(As, Ms, lmbd, Q), zeros(kconv), 0.0, normM*tol)
assert allclose(lmbd, lmbd_exact, normM*tol*tol, 0.0)
 
print 'OK'
 
#-------------------------------------------------------------------------------
# Test 4: K = None, with X0
 
print 'Test 4',
 
lmbd_exact = zeros(ncv, 'd')
 
# Fixme: RandomArray.random is broken AMD64
# X0 = RandomArray.random((n,ncv))
X0 = zeros((n,ncv), 'd')
for k in xrange(ncv):
    X0[k,k] = 10000
 
kconv, lmbd, Q, it, it_inner = jdsym.jdsym(As, Ms, None, ncv, 0.0, tol, 150, itsolvers.qmrs,
                                           jmin=5, jmax=10, eps_tr=1e-4, clvl=1, V0=X0)
 
assert ncv == kconv
assert allclose(computeResiduals(As, Ms, lmbd, Q), zeros(kconv), 0.0, normM*tol)

src/p/y/pysparse-1.1.1-dev/examples/jdsym_test.py   pysparse(Download)
from pysparse.sparse import spmatrix
from pysparse.eigen import jdsym
from pysparse.itsolvers.krylov import qmrs
from numpy import zeros, dot, allclose, multiply, random
from math import sqrt
 
class diagPrecShifted:
    def __init__(self, A, M, sigma):
        self.shape = A.shape
        n = self.shape[0]
        self.dinv = zeros(n, 'd')
def computeResiduals(A, M, lmbd, Q):
    kconv = lmbd.shape[0]
    residuals = zeros((kconv, ), 'd')
    r = zeros((n, ), 'd')
    u = zeros((n, ), 'd')
    t = zeros((n, ), 'd')
    for k in xrange(kconv):
 
print 'Test 1'
 
lmbd_exact = zeros(ncv, 'd')
for k in xrange(ncv):
    lmbd_exact[k] =  A[k,k]
 
kconv, lmbd, Q, it, it_inner = jdsym.jdsym(As, None, None, ncv,
                                           0.0, tol, 150, qmrs,
                                           jmin=5, jmax=10, eps_tr=1e-4, clvl=1)
 
assert ncv == kconv
assert allclose(computeResiduals(As, None, lmbd, Q), zeros(kconv), 0.0, tol)
 
print 'Test 2',
 
lmbd_exact = zeros(ncv, 'd')
for k in xrange(ncv):
    lmbd_exact[k] =  A[k,k]/M[k,k]
 
                                           jmin=5, jmax=10, eps_tr=1e-4, clvl=1)
 
assert ncv == kconv
assert allclose(computeResiduals(As, Ms, lmbd, Q), zeros(kconv), 0.0, normM*tol)
assert allclose(lmbd, lmbd_exact, normM*tol*tol, 0.0)
 
print 'OK'
 
#-------------------------------------------------------------------------------
# Test 3: general case
 
print 'Test 3',
 
lmbd_exact = zeros(ncv, 'd')
                                           0.0, tol, 150, qmrs,
                                           jmin=5, jmax=10, eps_tr=1e-4, clvl=1)
assert ncv == kconv
assert allclose(computeResiduals(As, Ms, lmbd, Q), zeros(kconv), 0.0, normM*tol)
assert allclose(lmbd, lmbd_exact, normM*tol*tol, 0.0)
 
print 'OK'
 
#-------------------------------------------------------------------------------
# Test 4: K = None, with X0
 
print 'Test 4',
 
lmbd_exact = zeros(ncv, 'd')
                                           clvl=1, V0=X0)
 
assert ncv == kconv
assert allclose(computeResiduals(As, Ms, lmbd, Q), zeros(kconv), 0.0, normM*tol)
assert allclose(lmbd, lmbd_exact, normM*tol*tol, 0.0)
 
print 'OK'

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