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

All Samples(4284)  |  Call(4040)  |  Derive(0)  |  Import(244)
Convert the input to an array.

Parameters
----------
a : array_like
    Input data, in any form that can be converted to an array.  This
    includes lists, lists of tuples, tuples, tuples of tuples, tuples
    of lists and ndarrays.
dtype : data-type, optional
    By default, the data-type is inferred from the input data.
order : {'C', 'F'}, optional
    Whether to use row-major ('C') or column-major ('F' for FORTRAN)
    memory representation.  Defaults to 'C'.

Returns
-------
out : ndarray
    Array interpretation of `a`.  No copy is performed if the input
    is already an ndarray.  If `a` is a subclass of ndarray, a base
    class ndarray is returned.

See Also
--------
asanyarray : Similar function which passes through subclasses.
ascontiguousarray : Convert input to a contiguous array.
asfarray : Convert input to a floating point ndarray.
asfortranarray : Convert input to an ndarray with column-major
                 memory order.
asarray_chkfinite : Similar function which checks input for NaNs and Infs.
fromiter : Create an array from an iterator.
fromfunction : Construct an array by executing a function on grid
               positions.

Examples
--------
Convert a list into an array:

>>> a = [1, 2]
>>> np.asarray(a)
array([1, 2])

Existing arrays are not copied:

>>> a = np.array([1, 2])
>>> np.asarray(a) is a
True

If `dtype` is set, array is copied only if dtype does not match:

>>> a = np.array([1, 2], dtype=np.float32)
>>> np.asarray(a, dtype=np.float32) is a
True
>>> np.asarray(a, dtype=np.float64) is a
False

Contrary to `asanyarray`, ndarray subclasses are not passed through:

>>> issubclass(np.matrix, np.ndarray)
True
>>> a = np.matrix([[1, 2]])
>>> np.asarray(a) is a
False
>>> np.asanyarray(a) is a
True

        def asarray(a, dtype=None, order=None):
    """
    Convert the input to an array.

    Parameters
    ----------
    a : array_like
        Input data, in any form that can be converted to an array.  This
        includes lists, lists of tuples, tuples, tuples of tuples, tuples
        of lists and ndarrays.
    dtype : data-type, optional
        By default, the data-type is inferred from the input data.
    order : {'C', 'F'}, optional
        Whether to use row-major ('C') or column-major ('F' for FORTRAN)
        memory representation.  Defaults to 'C'.

    Returns
    -------
    out : ndarray
        Array interpretation of `a`.  No copy is performed if the input
        is already an ndarray.  If `a` is a subclass of ndarray, a base
        class ndarray is returned.

    See Also
    --------
    asanyarray : Similar function which passes through subclasses.
    ascontiguousarray : Convert input to a contiguous array.
    asfarray : Convert input to a floating point ndarray.
    asfortranarray : Convert input to an ndarray with column-major
                     memory order.
    asarray_chkfinite : Similar function which checks input for NaNs and Infs.
    fromiter : Create an array from an iterator.
    fromfunction : Construct an array by executing a function on grid
                   positions.

    Examples
    --------
    Convert a list into an array:

    >>> a = [1, 2]
    >>> np.asarray(a)
    array([1, 2])

    Existing arrays are not copied:

    >>> a = np.array([1, 2])
    >>> np.asarray(a) is a
    True

    If `dtype` is set, array is copied only if dtype does not match:

    >>> a = np.array([1, 2], dtype=np.float32)
    >>> np.asarray(a, dtype=np.float32) is a
    True
    >>> np.asarray(a, dtype=np.float64) is a
    False

    Contrary to `asanyarray`, ndarray subclasses are not passed through:

    >>> issubclass(np.matrix, np.ndarray)
    True
    >>> a = np.matrix([[1, 2]])
    >>> np.asarray(a) is a
    False
    >>> np.asanyarray(a) is a
    True

    """
    return array(a, dtype, copy=False, order=order)
        


src/m/a/matplotlib-HEAD/matplotlib/examples/event_handling/poly_editor.py   matplotlib(Download)
"""
from matplotlib.artist import Artist
from matplotlib.patches import Polygon, CirclePolygon
from numpy import sqrt, nonzero, equal, array, asarray, dot, amin, cos, sin
from matplotlib.mlab import dist_point_to_segment
 
 
    def get_ind_under_point(self, event):
        'get the index of the vertex under point if within epsilon tolerance'
 
        # display coords
        xy = asarray(self.poly.xy)
        xyt = self.poly.get_transform().transform(xy)
        xt, yt = xyt[:, 0], xyt[:, 1]

src/m/a/matplotlib-HEAD/examples/event_handling/poly_editor.py   matplotlib(Download)
"""
from matplotlib.artist import Artist
from matplotlib.patches import Polygon, CirclePolygon
from numpy import sqrt, nonzero, equal, array, asarray, dot, amin, cos, sin
from matplotlib.mlab import dist_point_to_segment
 
 
    def get_ind_under_point(self, event):
        'get the index of the vertex under point if within epsilon tolerance'
 
        # display coords
        xy = asarray(self.poly.xy)
        xyt = self.poly.get_transform().transform(xy)
        xt, yt = xyt[:, 0], xyt[:, 1]

src/m/a/Matplotlib--JJ-s-dev-HEAD/examples/event_handling/poly_editor.py   Matplotlib--JJ-s-dev(Download)
"""
from matplotlib.artist import Artist
from matplotlib.patches import Polygon, CirclePolygon
from numpy import sqrt, nonzero, equal, array, asarray, dot, amin, cos, sin
from matplotlib.mlab import dist_point_to_segment
 
 
    def get_ind_under_point(self, event):
        'get the index of the vertex under point if within epsilon tolerance'
 
        # display coords
        xy = asarray(self.poly.xy)
        xyt = self.poly.get_transform().transform(xy)
        xt, yt = xyt[:, 0], xyt[:, 1]

src/s/c/scipy-HEAD/scipy/stats/stats.py   scipy(Download)
pysum = sum  # save it before it gets overwritten
 
# Scipy imports.
from numpy import array, asarray, dot, ma, zeros, sum
import scipy.special as special
import scipy.linalg as linalg
import numpy as np
        if isinstance(a,np.ma.MaskedArray):
            log_a=np.log(np.ma.asarray(a, dtype=dtype))
        else:
            log_a=np.log(np.asarray(a, dtype=dtype))
    else:
        log_a = np.log(a)
    return np.exp(log_a.mean(axis=axis))
    tmean : float
 
    """
    a = asarray(a)
 
    # Cast to a float if this is an integer array. If it is already a float
    # array, leave it as is to preserve its precision.
    tvar : float
 
    """
    a = asarray(a)
    a = a.astype(float).ravel()
    if limits is None:
        n = len(a)
 
Returns: trimmed version of array a
"""
    a = asarray(a)
    lowercut = int(proportiontocut*len(a))
    uppercut = len(a) - lowercut
    if (lowercut >= uppercut):
 
    Returns: trimmed version of array a
    """
    a = asarray(a)
    if tail.lower() == 'right':
        lowercut = 0
        uppercut = len(a) - int(proportiontocut*len(a))
    - numpy.cov rowvar argument defaults to true, not false
    - numpy.cov bias argument defaults to false, not true
""", DeprecationWarning)
    m = asarray(m)
    if y is None:
        y = m
    else:
        y = asarray(y)
    http://www.statsoft.com/textbook/glosp.html#Pearson%20Correlation
    """
    # x and y should have same length.
    x = np.asarray(x)
    y = np.asarray(y)
    n = len(x)
    mx = x.mean()
    #      0.1]
    # rpb = 0.36149
 
    x = np.asarray(x, dtype=bool)
    y = np.asarray(y, dtype=float)
    n = len(x)
 
    """
    TINY = 1.0e-20
    if y is None:  # x is a (2, N) or (N, 2) shaped array_like
        x = asarray(x)
        if x.shape[0] == 2:
            x, y = x
        elif x.shape[1] == 2:
            x, y = x.T
        else:
            msg = "If only `x` is given as input, it has to be of shape (2, N) \
            or (N, 2), provided shape was %s" % str(x.shape)
            raise ValueError(msg)
    else:
        x = asarray(x)
            raise ValueError(msg)
    else:
        x = asarray(x)
        y = asarray(y)
    n = len(x)
    xmean = np.mean(x,None)
    ymean = np.mean(y,None)
 
    """
 
    f_obs = asarray(f_obs)
    k = len(f_obs)
    if f_exp is None:
        f_exp = array([np.sum(f_obs,axis=0)/float(k)] * len(f_obs),float)
    p-value multiply the returned p-value by 2.
 
    """
    x = asarray(x)
    y = asarray(y)
    n1 = len(x)
    n2 = len(y)
 
    Returns: T correction factor for U or H
    """
    sorted,posn = fastsort(asarray(rankvals))
    n = len(sorted)
    T = 0.0
    i = 0
    -------
 
    """
    x = np.asarray(x)
    x = np.where(x < 1.0, x, 1.0)  # if x > 1 then return 1.0
    return special.betainc(a, b, x)
 

src/s/h/shapely-3k-HEAD/examples/geoms.py   shapely-3k(Download)
from numpy import asarray
import pylab
from shapely.geometry import Point, LineString, Polygon
 
polygon = Polygon(((-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0), (1.0, -1.0)))
 
point_r = Point(-1.5, 1.2)
def plot_line(g, o):
    a = asarray(g)
    pylab.plot(a[:,0], a[:,1], o)
 
def fill_polygon(g, o):
    a = asarray(g.exterior)
    pylab.fill(a[:,0], a[:,1], o, alpha=0.5)
 
def fill_multipolygon(g, o):
    for g in g.geoms:
        fill_polygon(g, o)
 
if __name__ == "__main__":
    from numpy import asarray
    #pylab.axis([-2.0, 2.0, -1.5, 1.5])
    pylab.axis('tight')
 
    a = asarray(polygon.exterior)
    pylab.fill(a[:,0], a[:,1], 'c')
 
    plot_point(point_r, 'ro', 'b')

src/s/h/shapely-HEAD/examples/geoms.py   shapely(Download)
from numpy import asarray
import pylab
from shapely.geometry import Point, LineString, Polygon
 
polygon = Polygon(((-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0), (1.0, -1.0)))
 
point_r = Point(-1.5, 1.2)
def plot_line(g, o):
    a = asarray(g)
    pylab.plot(a[:,0], a[:,1], o)
 
def fill_polygon(g, o):
    a = asarray(g.exterior)
    pylab.fill(a[:,0], a[:,1], o, alpha=0.5)
 
def fill_multipolygon(g, o):
    for g in g.geoms:
        fill_polygon(g, o)
 
if __name__ == "__main__":
    from numpy import asarray
    #pylab.axis([-2.0, 2.0, -1.5, 1.5])
    pylab.axis('tight')
 
    a = asarray(polygon.exterior)
    pylab.fill(a[:,0], a[:,1], 'c')
 
    plot_point(point_r, 'ro', 'b')

src/s/c/scipy-0.8.0/scipy/stats/stats.py   scipy(Download)
pysum = sum  # save it before it gets overwritten
 
# Scipy imports.
from numpy import array, asarray, dot, ma, zeros, sum
import scipy.special as special
import scipy.linalg as linalg
import numpy as np
def _chk_asarray(a, axis):
    if axis is None:
        a = np.ravel(a)
        outaxis = 0
    else:
        a = np.asarray(a)
        outaxis = axis
def _chk2_asarray(a, b, axis):
    if axis is None:
        a = np.ravel(a)
        b = np.ravel(b)
        outaxis = 0
    else:
        a = np.asarray(a)
        b = np.asarray(b)
        if isinstance(a,np.ma.MaskedArray):
            log_a=np.log(np.ma.asarray(a, dtype=dtype))
        else:
            log_a=np.log(np.asarray(a, dtype=dtype))
    else:
        log_a = np.log(a)
    return np.exp(log_a.mean(axis=axis))
    tmean : float
 
    """
    a = asarray(a)
 
    # Cast to a float if this is an integer array. If it is already a float
    # array, leave it as is to preserve its precision.
    tvar : float
 
    """
    a = asarray(a)
    a = a.astype(float).ravel()
    if limits is None:
        n = len(a)
 
Returns: trimmed version of array a
"""
    a = asarray(a)
    lowercut = int(proportiontocut*len(a))
    uppercut = len(a) - lowercut
    if (lowercut >= uppercut):
 
    Returns: trimmed version of array a
    """
    a = asarray(a)
    if tail.lower() == 'right':
        lowercut = 0
        uppercut = len(a) - int(proportiontocut*len(a))
    - numpy.cov rowvar argument defaults to true, not false
    - numpy.cov bias argument defaults to false, not true
""", DeprecationWarning)
    m = asarray(m)
    if y is None:
        y = m
    else:
        y = asarray(y)
    http://www.statsoft.com/textbook/glosp.html#Pearson%20Correlation
    """
    # x and y should have same length.
    x = np.asarray(x)
    y = np.asarray(y)
    n = len(x)
    mx = x.mean()
    #      0.1]
    # rpb = 0.36149
 
    x = np.asarray(x, dtype=bool)
    y = np.asarray(y, dtype=float)
    n = len(x)
 
    """
    TINY = 1.0e-20
    if len(args) == 1:  # more than 1D array?
        args = asarray(args[0])
        if len(args) == 2:
            x = args[0]
            y = args[1]
        else:
            x = args[:,0]
            y = args[:,1]
    else:
        x = asarray(args[0])
        y = asarray(args[1])
 
    """
 
    f_obs = asarray(f_obs)
    k = len(f_obs)
    if f_exp is None:
        f_exp = array([np.sum(f_obs,axis=0)/float(k)] * len(f_obs),float)
    p-value multiply the returned p-value by 2.
 
    """
    x = asarray(x)
    y = asarray(y)
    n1 = len(x)
    n2 = len(y)
 
    Returns: T correction factor for U or H
    """
    sorted,posn = fastsort(asarray(rankvals))
    n = len(sorted)
    T = 0.0
    i = 0
    -------
 
    """
    x = np.asarray(x)
    x = np.where(x < 1.0, x, 1.0)  # if x > 1 then return 1.0
    return special.betainc(a, b, x)
 

src/s/c/scipy-HEAD/scipy/optimize/nonlin.py   scipy(Download)
import sys
import numpy as np
from scipy.linalg import norm, solve, inv, qr, svd, lstsq, LinAlgError
from numpy import asarray, dot, vdot
import scipy.sparse.linalg
import scipy.sparse
import scipy.lib.blas as blas
def _as_inexact(x):
    """Return `x` as an array, of either floats or complex floats"""
    x = asarray(x)
    if not np.issubdtype(x.dtype, np.inexact):
        return asarray(x, dtype=np.float_)
    return x
 
    elif isinstance(J, np.ndarray):
        if J.ndim > 2:
            raise ValueError('array must have rank <= 2')
        J = np.atleast_2d(np.asarray(J))
        if J.shape[0] != J.shape[1]:
            raise ValueError('array must be square')
 

src/n/u/numpy-refactor-HEAD/numpy/oldnumeric/arrayfns.py   numpy-refactor(Download)
           'to_corners', 'zmin_zmax']
 
import numpy as np
from numpy import asarray
 
class error(Exception):
    pass
 
def array_set(vals1, indices, vals2):
    indices = asarray(indices)
def array_set(vals1, indices, vals2):
    indices = asarray(indices)
    if indices.ndim != 1:
        raise ValueError, "index array must be 1-d"
    if not isinstance(vals1, np.ndarray):
        raise TypeError, "vals1 must be an ndarray"
    vals1 = asarray(vals1)
    vals2 = asarray(vals2)
def nz(x):
    x = asarray(x,dtype=np.ubyte)
    if x.ndim != 1:
        raise TypeError, "intput must have 1 dimension."
    indxs = np.flatnonzero(x != 0)
    return indxs[-1].item()+1
 
def reverse(x, n):
    x = asarray(x,dtype='d')
def zmin_zmax(z, ireg):
    z = asarray(z, dtype=float)
    ireg = asarray(ireg, dtype=int)
    if z.shape != ireg.shape or z.ndim != 2:
        raise ValueError, "z and ireg must be the same shape and 2-d"
    ix, iy = np.nonzero(ireg)
    # Now, add more indices

src/w/a/wafo-0.11/src/wafo/misc.py   wafo(Download)
from numpy import arange
from numpy import arctan2
from numpy import array
from numpy import asarray
from numpy import atleast_1d
from numpy import broadcast_arrays
from numpy import ceil
    #y  = x0.copy()
    xu = (n - 1) * (x0 - xo[0]) / (xo[-1] - xo[0])
 
    fi = asarray(floor(xu), dtype=int)
    fi = where(fi == n - 1, fi - 1, fi)
 
    xu = xu - fi

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