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

All Samples(33696)  |  Call(32082)  |  Derive(0)  |  Import(1614)
array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)

Create an array.

Parameters
----------
object : array_like
    An array, any object exposing the array interface, an
    object whose __array__ method returns an array, or any
    (nested) sequence.
dtype : data-type, optional
    The desired data-type for the array.  If not given, then
    the type will be determined as the minimum type required
    to hold the objects in the sequence.  This argument can only
    be used to 'upcast' the array.  For downcasting, use the
    .astype(t) method.
copy : bool, optional
    If true (default), then the object is copied.  Otherwise, a copy
    will only be made if __array__ returns a copy, if obj is a
    nested sequence, or if a copy is needed to satisfy any of the other
    requirements (`dtype`, `order`, etc.).
order : {'C', 'F', 'A'}, optional
    Specify the order of the array.  If order is 'C' (default), then the
    array will be in C-contiguous order (last-index varies the
    fastest).  If order is 'F', then the returned array
    will be in Fortran-contiguous order (first-index varies the
    fastest).  If order is 'A', then the returned array may
    be in any order (either C-, Fortran-contiguous, or even
    discontiguous).
subok : bool, optional
    If True, then sub-classes will be passed-through, otherwise
    the returned array will be forced to be a base-class array (default).
ndmin : int, optional
    Specifies the minimum number of dimensions that the resulting
    array should have.  Ones will be pre-pended to the shape as
    needed to meet this requirement.

Examples
--------
>>> np.array([1, 2, 3])
array([1, 2, 3])

Upcasting:

>>> np.array([1, 2, 3.0])
array([ 1.,  2.,  3.])

More than one dimension:

>>> np.array([[1, 2], [3, 4]])
array([[1, 2],
       [3, 4]])

Minimum dimensions 2:

>>> np.array([1, 2, 3], ndmin=2)
array([[1, 2, 3]])

Type provided:

>>> np.array([1, 2, 3], dtype=complex)
array([ 1.+0.j,  2.+0.j,  3.+0.j])

Data-type consisting of more than one element:

>>> x = np.array([(1,2),(3,4)],dtype=[('a','<i4'),('b','<i4')])
>>> x['a']
array([1, 3])

Creating an array from sub-classes:

>>> np.array(np.mat('1 2; 3 4'))
array([[1, 2],
       [3, 4]])

>>> np.array(np.mat('1 2; 3 4'), subok=True)
matrix([[1, 2],
        [3, 4]])

src/p/y/pyfusion-HEAD/examples/test_savez.py   pyfusion(Download)
#    debug_save_compress=False;
 
global verbose
from numpy import savez, array, arange, remainder, mod, sin, pi, min, max, \
        size, diff, random, mean, unique, sort, sqrt, float32
from time import time
from pylab import plot, show
    If bits=0, find the natural accuracy.  eps defaults to 3e-6, and 
    is the error relative to the larest element, as is maxerror.
    """
    from numpy import max, std, array, min, sort, diff, unique
    if eps==0: eps=3e-6
    if maxcount==0: maxcount=10
    count=1
except: verbose=1
 
print('====== synthetic marginal precision timebase test =========')
noisytime=1+array(arange(1e4),dtype=float32)/1e6
tim=discretise_array(noisytime,eps=eps,verbose=verbose)
 
pushd=os.getcwd()

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)
def H_fcn(x):
    H11 = -(1+cos(x[1]))**2*sin(x[0]+cos(x[1])*x[0])
    H21 = -sin(x[1]) * cos(x[0] + cos(x[1])*x[0]) \
          +sin(x[1]) *x[0]*(1+ cos(x[1]))*sin(x[0]+cos(x[1])*x[0])
    H22 = -cos(x[1])*x[0]*cos(x[0]+cos(x[1])*x[0])\
          -(sin(x[1])*x[0])**2*sin(x[0]+cos(x[1])*x[0])
    return array([[H11, H21],[H21,H22]])

src/a/l/algopy-HEAD/documentation/sphinx/examples/first_order_forward.py   algopy(Download)
import numpy; from numpy import array
from algopy import UTPM, zeros
 
def F(x):
    y = zeros(3, dtype=x)
    y[0] = x[0]*x[1]
    y[1] = x[1]*x[2]
    y[2] = x[2]*x[0]
    return y
 
x0 = array([1,3,5],dtype=float)
x1 = array([1,0,0],dtype=float)
    A[1,1] = x[0]**cos(x[1])
    return log( dot(x.T,  dot( inv(A), x)))
 
x = numpy.array([3.,7.])
x = UTPM.init_jacobian(x)
 
y = f(x)

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
    return invlogit(a+b*d)
 
"""deaths ~ binomial(n, p)"""
deaths = Binomial('deaths', n=n, p=theta, value=array([0,1,3,5], dtype=float), observed=True)
 

src/p/y/PyProp-HEAD/examples/combined/hd+_vibration/potential_data.py   PyProp(Download)
 
"""
 
from numpy import array, double
 
GridIon = array([0.250, 0.500, 0.750, 1.000, 1.250,\
 		1.500, 1.750, 2.000, 2.250, 2.500,\
		80.00, 100.00, 200.00, 10000.00 ], dtype=double)
 
 
Potential_1s_sigma_G = array([-1.8985550000, -1.7349900000, \
		-1.5823853333, -1.4517850000, -1.3417950000, \
		-1.2489896667, -1.1701445714, -1.1026350000, \
		-1.0443954444, -0.9938250000, -0.9496553636, \
		-0.5050000010, -0.5001000000], dtype=double)
 
 
Potential_2p_sigma_U = array([-0.5041900000, -0.5168850000, \
		-0.5377353333, -0.5648150000, -0.5945750000, \
		-0.6231696667, -0.6478795714, -0.6675350000, \
		-0.6820804444, -0.6920700000, -0.6982653636, \
 
"""
 
GridNeutral = array([0.4000, 0.4500, 0.5000, 0.5500,\
 		0.6500, 0.7000, 0.7500, 0.8000, 0.9000, \
		1.0000, 1.1000, 1.2000, 1.3000, 1.3500, \
		1.3900, 1.4000, 1.4010, 1.4011, 1.4100, \
		7.8000, 8.0000, 8.2500, 8.5000, 9.0000, \
		9.5000, 10.0000], dtype=double)
 
PotentialNeutral = array([-2.6202028000, -2.5731504222, -2.5266270000,\
		-2.4809525182, -2.3928229385, -2.3505975286, \
		-2.3096690333, -2.2700556000, -2.1947533111, \
		-2.1245385000, -2.0591471091, -1.9982675333, \

src/p/y/PyPWDG-HEAD/examples/2D/squarecommon.py   PyPWDG(Download)
from pypwdg import PlaneWaves
from pypwdg import setup,runParallel,gmshMesh
from pypwdg import generic_boundary_data, dirichlet
from numpy import array,sqrt
 
k = 15
direction=array([[1.0,1.0]])/sqrt(2)
 
runParallel()
 
bounds=array([[0,1],[0,1],[0,0]],dtype='d')
npoints=array([100,100,1])
 
comp=setup(gmshMesh('square.msh',dim=2),k=k,nquadpoints=20,nplanewaves=15,bnddata=bnddata)

src/p/y/PyPWDG-HEAD/examples/2D/soundsoft.py   PyPWDG(Download)
from pypwdg import PlaneWaves
from pypwdg import setup,runParallel,gmshMesh
from pypwdg import zero_dirichlet,generic_boundary_data 
from numpy import array,sqrt
 
k = 15
direction=array([[1.0,1.0]])/sqrt(2)
 
runParallel()
 
bounds=array([[-2,2],[-2,2],[0,0]],dtype='d')
npoints=array([200,200,1])
 
comp.writeSolution(bounds,npoints,fname='soundsoft.vti')

src/p/y/pymc-2.1beta/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
    return invlogit(a+b*d)
 
"""deaths ~ binomial(n, p)"""
deaths = Binomial('deaths', n=n, p=theta, value=array([0,1,3,5], dtype=float), observed=True)
 

src/m/a/matplotlib-HEAD/toolkits/basemap-0.9.6.1/examples/pupynere.py   matplotlib(Download)
import itertools
import mmap
 
from numpy import ndarray, zeros, array
 
 
ABSENT       = '\x00' * 8
        typecode = typecodes[nc_type-1]
        if nc_type != 2:  # not char 
            values = struct.unpack('>%s' % (typecode * n), values)
            values = array(values, dtype=typecode) 
        else:
            # Remove EOL terminator.
            if values.endswith('\x00'): values = values[:-1]

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
 
# PART 1: computation with SYMPY
################################
 
xs = array([[sympy.Symbol('x%d%d'%(n,d)) for d in range(D)] for n in range(N)])
# computing the function f: R^(NxD) -> R symbolically
fs = 0
for n in range(1,N):
        fs += 1/tmp
 
# computing the gradient symbolically
dfs = array([[sympy.diff(fs, xs[n,d]) for d in range(D)] for n in range(N)])
 
# computing the Hessian symbolically
ddfs = array([[[[ sympy.diff(dfs[m,e], xs[n,d]) for d in range(D)] for n in range(N)] for e in range(D) ] for m in range(N)])
def sym_df(x):
    symdict = dict()
    for n in range(N):
        for d in range(D):
            symdict[xs[n,d]] = x[n,d]
    return array([[dfs[n,d].subs(symdict).evalf() for d in range(D)] for n in range(N)])
 
def sym_ddf(x):
    symdict = dict()
    for n in range(N):
        for d in range(D):
            symdict[xs[n,d]] = x[n,d]
    return array([[[[ ddfs[m,e,n,d].subs(symdict).evalf() for d in range(D)] for n in range(N)] for e in range(D)] for m in range(N)],dtype=float)

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