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
from pymc import * from numpy import ones, array n = 5*ones(4,dtype=int) dose=array([-.86,-.3,-.05,.73]) @stochastic
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
src/a/q/aqsis-HEAD/trunk/testing/prototypes/texfilt/downsample_test.py aqsis(Download)
import matplotlib.pylab as pylab import numpy from numpy import r_, size, zeros, ones, ceil, floor, array, linspace, meshgrid import scipy from scipy.signal import boxcar, convolve2d as conv2
def boxKer(width, scale): ''' Trivial box filter kernel ''' return ones(width+1)
def imConv(im, ker, conv2Func=conv2): ''' Convolve an image with the given filter kernel ''' res = zeros(im.shape) normalisation = conv2Func(ones(im.shape[0:2],'d'), ker, 'full') # compute how much of the full convolution to trim from top left and bottom right
mipSize = list(mipmap[0].shape) mipSize[dim] = len mipmapImg = ones(mipSize)*0.7 pos = 0 for mipLevel in mipmap: if dim == 0:
src/a/q/aqsis-HEAD/testing/prototypes/texfilt/downsample_test.py aqsis(Download)
import matplotlib.pylab as pylab import numpy from numpy import r_, size, zeros, ones, ceil, floor, array, linspace, meshgrid import scipy from scipy.signal import boxcar, convolve2d as conv2
def boxKer(width, scale): ''' Trivial box filter kernel ''' return ones(width+1)
def imConv(im, ker, conv2Func=conv2): ''' Convolve an image with the given filter kernel ''' res = zeros(im.shape) normalisation = conv2Func(ones(im.shape[0:2],'d'), ker, 'full') # compute how much of the full convolution to trim from top left and bottom right
mipSize = list(mipmap[0].shape) mipSize[dim] = len mipmapImg = ones(mipSize)*0.7 pos = 0 for mipLevel in mipmap: if dim == 0:
src/p/y/pyfusion-HEAD/examples/Boyds/wid_specgram.py pyfusion(Download)
""" from matplotlib.widgets import RadioButtons, Button import pylab as pl from numpy import sin, pi, ones, hanning, hamming, bartlett, kaiser, arange, blackman, cos, sqrt, log10, fft import pyfusion
def local_none(vec):
return(ones(len(vec)))
def local_hanning(vec):
return(hanning(len(vec)))
def local_hamming(vec):
src/b/i/BIP-0.5.2/BIP/Bayes/Samplers/MCMC.py BIP(Download)
import numpy as np from liveplots.xmlrpcserver import rpc_plot from numpy import array, mean,isnan, nan_to_num, var, sqrt, inf, exp, greater, less, identity, ones, zeros, floor, log, recarray, nan from numpy.random import random, multivariate_normal, multinomial, rand from scipy.stats import cov, uniform, norm, scoreatpercentile
end = relevantHistoryEnd
N = end - start
if N==0:
self._R = np.inf*np.ones(self.nchains)
return
N = min(min([len(self.seqhist[c]) for c in range(self.nchains)]), N)
seq = [self.seqhist[c][-N:] for c in range(self.nchains)]
#self.sequenceHistories = np.zeros((self.nchains, self.dimensions, self.maxChainDraws))
# initialize the temporary storage vectors
self.currentVectors = zeros((self.nchains, self.dimensions))
self.currentLiks = ones(self.nchains)*-inf
self.scaling_factor = 2.38/sqrt(2*DEpairs*self.dimensions)
self.setup_xmlrpc_plotserver()
for d in range(delta):
d1, d2 = sample(others, 2)
dif+=array(d1)-array(d2)
zi = array(proptheta[c])+(ones(self.dimensions)+e)*gam*dif+eps
#revert offlimits proposals
for i in xrange(len(zi)):
if zi[i]<= self.parlimits[i][0] or zi[i]>= self.parlimits[i][1]:# or isnan(zi):
src/s/c/scipy-HEAD/scipy/weave/size_check.py scipy(Download)
from numpy import ones, ndarray, array, asarray, concatenate, zeros, shape, \
alltrue, equal, divide, arccos, arcsin, arctan, cos, cosh, \
sin, sinh, exp, ceil, floor, fabs, log, log10, sqrt, argmin, \
argmax, argsort, around, absolute, sign, negative, float32
import sys
def time_it():
import time
expr = "ex[:,1:,1:] = ca_x[:,1:,1:] * ex[:,1:,1:]" \
"+ cb_y_x[:,1:,1:] * (hz[:,1:,1:] - hz[:,:-1,1:])" \
"- cb_z_x[:,1:,1:] * (hy[:,1:,1:] - hy[:,1:,:-1])"
ex = ones((10,10,10),dtype=float32)
ca_x = ones((10,10,10),dtype=float32)
cb_y_x = ones((10,10,10),dtype=float32)
cb_z_x = ones((10,10,10),dtype=float32)
hz = ones((10,10,10),dtype=float32)
hy = ones((10,10,10),dtype=float32)
return asarray(x),asarray(y)
else:
diff = abs(Nx - Ny)
front = ones(diff, int)
if Nx > Ny:
return asarray(x), concatenate((front,y))
elif Ny > Nx:
src/p/y/pyfusion-HEAD/examples/Boyds/plot_bar_fs_list.py pyfusion(Download)
def plot_bar_fs_list(fs_list, orientation='horizontal', width=None, hold=1):
""" accept a flucstruc list and plot as an overlapped bar
width is the bar width relative to unity.
"""
import pylab as pl
from numpy import zeros, ones, arange, array
#data=exp(-0.5*arange(10))
for (i,fs) in enumerate(fs_list):
if fs.svd.id!=fs0.svd.id: ec0[i]='gray'
wid0=width*ones(len(data))
if orientation=='horizontal': (wid0,data)=(data,wid0)
pl.bar(left,data,wid0, bottom, color='c', hold=hold, edgecolor=ec0, **com_kw)
src/p/y/pymc-HEAD/pymc/examples/model_4.py pymc(Download)
""" from pymc import * from numpy import array, ones, append from numpy.random import randint __all__ = ['disasters_array', 'switchpoint', 'early_mean', 'late_mean', 'disasters']
# Define data and stochastics
switchpoint = DiscreteUniform('switchpoint',lower=0,upper=110)
means = Exponential('means',beta=ones(2))
@stochastic(observed=True, dtype=int)
def disasters( value = disasters_array,
src/s/c/scipy-0.8.0/scipy/weave/size_check.py scipy(Download)
from numpy import ones, ndarray, array, asarray, concatenate, zeros, shape, \
alltrue, equal, divide, arccos, arcsin, arctan, cos, cosh, \
sin, sinh, exp, ceil, floor, fabs, log, log10, sqrt, argmin, \
argmax, argsort, around, absolute, sign, negative, float32
import sys
def time_it():
import time
expr = "ex[:,1:,1:] = ca_x[:,1:,1:] * ex[:,1:,1:]" \
"+ cb_y_x[:,1:,1:] * (hz[:,1:,1:] - hz[:,:-1,1:])" \
"- cb_z_x[:,1:,1:] * (hy[:,1:,1:] - hy[:,1:,:-1])"
ex = ones((10,10,10),dtype=float32)
ca_x = ones((10,10,10),dtype=float32)
cb_y_x = ones((10,10,10),dtype=float32)
cb_z_x = ones((10,10,10),dtype=float32)
hz = ones((10,10,10),dtype=float32)
hy = ones((10,10,10),dtype=float32)
return asarray(x),asarray(y)
else:
diff = abs(Nx - Ny)
front = ones(diff, int)
if Nx > Ny:
return asarray(x), concatenate((front,y))
elif Ny > Nx:
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next