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

All Samples(5228)  |  Call(4776)  |  Derive(0)  |  Import(452)
Return a new array of given shape and type, filled with ones.

Please refer to the documentation for `zeros` for further details.

See Also
--------
zeros, ones_like

Examples
--------
>>> np.ones(5)
array([ 1.,  1.,  1.,  1.,  1.])

>>> np.ones((5,), dtype=np.int)
array([1, 1, 1, 1, 1])

>>> np.ones((2, 1))
array([[ 1.],
       [ 1.]])

>>> s = (2,2)
>>> np.ones(s)
array([[ 1.,  1.],
       [ 1.,  1.]])

        def ones(shape, dtype=None, order='C'):
    """
    Return a new array of given shape and type, filled with ones.

    Please refer to the documentation for `zeros` for further details.

    See Also
    --------
    zeros, ones_like

    Examples
    --------
    >>> np.ones(5)
    array([ 1.,  1.,  1.,  1.,  1.])

    >>> np.ones((5,), dtype=np.int)
    array([1, 1, 1, 1, 1])

    >>> np.ones((2, 1))
    array([[ 1.],
           [ 1.]])

    >>> s = (2,2)
    >>> np.ones(s)
    array([[ 1.,  1.],
           [ 1.,  1.]])

    """
    a = empty(shape, dtype, order)
    try:
        a.fill(1)
        # Above is faster now after addition of fast loops.
        #a = zeros(shape, dtype, order)
        #a+=1
    except TypeError:
        obj = _maketup(dtype, 1)
        a.fill(obj)
    return a
        


src/m/a/matplotlib-HEAD/matplotlib/examples/api/donut_demo.py   matplotlib(Download)
 
inside_vertices = make_circle(0.5)
outside_vertices = make_circle(1.0)
codes = np.ones(len(inside_vertices), dtype=mpath.Path.code_type) * mpath.Path.LINETO
codes[0] = mpath.Path.MOVETO
 
for i, (inside, outside) in enumerate(((1, 1), (1, -1), (-1, 1), (-1, -1))):

src/m/a/matplotlib-HEAD/examples/api/donut_demo.py   matplotlib(Download)
 
inside_vertices = make_circle(0.5)
outside_vertices = make_circle(1.0)
codes = np.ones(len(inside_vertices), dtype=mpath.Path.code_type) * mpath.Path.LINETO
codes[0] = mpath.Path.MOVETO
 
for i, (inside, outside) in enumerate(((1, 1), (1, -1), (-1, 1), (-1, -1))):

src/m/o/modave-HEAD/examples/cxx/ex2.py   modave(Download)
dz = (zmax - zmin) / float(nz1 - 1)
zs = numpy.array( [zmin + k*dz for k in range(nz1)] )
 
xxs = numpy.multiply.outer( numpy.ones((nz1, ny1), dtype=xs.dtype), xs)
yys = numpy.multiply.outer( \
    numpy.multiply.outer( numpy.ones((nz1,), dtype=ys.dtype), ys) , numpy.ones((nx1,), \
                                                                   dtype=ys.dtype))
zzs = numpy.multiply.outer(zs, numpy.ones((ny1, nx1), dtype=zs.dtype))

src/m/a/Matplotlib--JJ-s-dev-HEAD/examples/api/donut_demo.py   Matplotlib--JJ-s-dev(Download)
 
inside_vertices = make_circle(0.5)
outside_vertices = make_circle(1.0)
codes = np.ones(len(inside_vertices), dtype=mpath.Path.code_type) * mpath.Path.LINETO
codes[0] = mpath.Path.MOVETO
 
for i, (inside, outside) in enumerate(((1, 1), (1, -1), (-1, 1), (-1, -1))):

src/a/l/algopy-HEAD/documentation/sphinx/examples/minimal_surface.py   algopy(Download)
    for m in range(M):
        L[n,m] = 2.5 * ( (x_grid[n]-0.5)**2 + (y_grid[m]-0.5)**2 <= 1./16)
 
U = 100*numpy.ones((M,M),dtype=float)
 
Z,s = projected_gradients(u,O_tilde,dO_tilde,[L,U])
 

src/m/a/matplotlib-HEAD/matplotlib/examples/event_handling/viewlims.py   matplotlib(Download)
    def __call__(self, xstart, xend, ystart, yend):
        self.x = np.linspace(xstart, xend, self.width)
        self.y = np.linspace(ystart, yend, self.height).reshape(-1,1)
        c = self.x + 1.0j * self.y
        threshold_time = np.zeros((self.height, self.width))
        z = np.zeros(threshold_time.shape, dtype=np.complex)
        mask = np.ones(threshold_time.shape, dtype=np.bool)

src/m/a/matplotlib-HEAD/examples/event_handling/viewlims.py   matplotlib(Download)
    def __call__(self, xstart, xend, ystart, yend):
        self.x = np.linspace(xstart, xend, self.width)
        self.y = np.linspace(ystart, yend, self.height).reshape(-1,1)
        c = self.x + 1.0j * self.y
        threshold_time = np.zeros((self.height, self.width))
        z = np.zeros(threshold_time.shape, dtype=np.complex)
        mask = np.ones(threshold_time.shape, dtype=np.bool)

src/m/a/Matplotlib--JJ-s-dev-HEAD/examples/event_handling/viewlims.py   Matplotlib--JJ-s-dev(Download)
    def __call__(self, xstart, xend, ystart, yend):
        self.x = np.linspace(xstart, xend, self.width)
        self.y = np.linspace(ystart, yend, self.height).reshape(-1,1)
        c = self.x + 1.0j * self.y
        threshold_time = np.zeros((self.height, self.width))
        z = np.zeros(threshold_time.shape, dtype=np.complex)
        mask = np.ones(threshold_time.shape, dtype=np.bool)

src/p/y/pymc-HEAD/pymc/examples/gelman_bioassay.py   pymc(Download)
from pymc import *
from numpy import ones, array
 
n = 5*ones(4,dtype=int)
dose=array([-.86,-.3,-.05,.73])
 
@stochastic

src/i/p/ipython-py3k-HEAD/docs/examples/kernel/mcpricer.py   ipython-py3k(Download)
    h = 1.0/days
    const1 = exp((r-0.5*sigma**2)*h)
    const2 = sigma*sqrt(h)
    stock_price = S*np.ones(paths, dtype='float64')
    stock_price_sum = np.zeros(paths, dtype='float64')
    for j in range(days):
        growth_factor = const1*np.exp(const2*np.random.standard_normal(paths))

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