本文整理汇总了Python中numpy.fromregex函数的典型用法代码示例。如果您正苦于以下问题:Python fromregex函数的具体用法?Python fromregex怎么用?Python fromregex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromregex函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: readMaskRegion
def readMaskRegion(regfile):
box = numpy.fromregex(regfile,r"box\(([0-9]*\.?[0-9]+),(-[0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+)\",([0-9]*\.?[0-9]+)\",([0-9]*\.?[0-9]+)",
[('xc',numpy.float),('yc',numpy.float),('width',numpy.float),('height',numpy.float),('angle',numpy.float)])
try:
box[0]
except IndexError:
print 'Assuming a positive declination region.'
box = numpy.fromregex(regfile,r"box\(([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+)\",([0-9]*\.?[0-9]+)\",([0-9]*\.?[0-9]+)",[('xc',numpy.float),('yc',numpy.float),('width',numpy.float),('height',numpy.float),('angle',numpy.float)])
return box[0]
开发者ID:MCTwo,项目名称:DEIMOS,代码行数:10,代码来源:obsplan.py
示例2: loadobj
def loadobj(filename, load_normals=False):
""" load a wavefront obj file
loads vertices into a (x,y,z) struct array and vertex indices
into a n x 3 index array
only loads obj files vertex positions and also
only works with triangle meshes """
vertices = np.fromregex(open(filename), _vertex_regex, np.float)
if load_normals:
normals = np.fromregex(open(filename), _normal_regex, np.float)
triangles = np.fromregex(open(filename), _triangle_regex, np.int) - 1 # 1-based indexing in obj file format!
if load_normals:
return vertices, normals, triangles
else:
return vertices, triangles
开发者ID:KeeganRen,项目名称:cmm,代码行数:14,代码来源:wavefront_obj.py
示例3: readheader
def readheader(catalog):
'''
This function extracts the #ttype indexed header of a catalog.
Input:
catalog = [string], Name (perhaps including path) of the catalog
that contains all of the data (e.g. x,y,e1,e2,...). Must include
ttype header designations for the columns e.g.:
#ttype0 = objid
#ttype1 = x
Output:
dic = dictonary that contains the {ttype string,column #}.
'''
import numpy
import sys
header = numpy.fromregex(catalog,r"ttype([0-9]+)(?:\s)?=(?:\s)?(\w+)",
[('column',numpy.int64),('name','S20')])
# Determine if the catalog is 0 or 1 indexed and if 1 indexed then change to 0
if header['column'][0] == 1:
header['column']-=1
elif header['column'][0] != 0:
print 'readheader: the catalog is not ttype indexed, please index using format ttype(column#)=(column name), exiting'
sys.exit()
for i in range(len(header)):
if i == 0:
dic = {header[i][1]:header[i][0]}
else:
dic[header[i][1]]=header[i][0]
return dic
开发者ID:jmcelve2,项目名称:MCCutils,代码行数:28,代码来源:tools.py
示例4: get_stocks
def get_stocks():
global gldict
for name in names:
filename = "%s.csv" % name
if not os.path.exists(filename):
yh_download(name)
arr = fromregex(filename, yf_regex, yf_dtype)
gldict[name] = arr
开发者ID:PlamenStilyianov,项目名称:Python,代码行数:8,代码来源:stocks.py
示例5: read_orca_trj
def read_orca_trj(fname):
"""return numpy 2D array
"""
# http://stackoverflow.com/questions/14645789/
# numpy-reading-file-with-filtering-lines-on-the-fly
import numpy as np
regexp = r'\s+\w+' + r'\s+([-.0-9]+)' * 3 + r'\s*\n'
return np.fromregex(fname, regexp, dtype='f')
开发者ID:josejames00,项目名称:pytraj,代码行数:8,代码来源:qm.py
示例6: readregions
def readregions(regfile):
'''
regfile = (string) the ds9 region file, assumes that it was written using
'ds9' Format and 'image' Coordinate System
Currently this function only works on circles, ellipse, and box regions
'''
# find all the circle regions
circ = numpy.fromregex(regfile,r"circle\(([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+)",[('xc',numpy.float),('yc',numpy.float),('rc',numpy.float)])
# find all the elliptical regions
ellip = numpy.fromregex(regfile,r"ellipse\(([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+)",[('xc',numpy.float),('yc',numpy.float),('a',numpy.float),('b',numpy.float),('angle',numpy.float)])
# find all the box regions
box = numpy.fromregex(regfile,r"box\(([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+),([0-9]*\.?[0-9]+)",[('xc',numpy.float),('yc',numpy.float),('width',numpy.float),('height',numpy.float),('angle',numpy.float)])
return circ, ellip, box
开发者ID:jmcelve2,项目名称:MCCutils,代码行数:17,代码来源:ds9tools.py
示例7: test_record_3
def test_record_3(self):
c = StringIO.StringIO()
c.write('1312 foo\n1534 bar\n4444 qux')
c.seek(0)
dt = [('num', np.float64)]
x = np.fromregex(c, r"(\d+)\s+...", dt)
a = np.array([(1312,), (1534,), (4444,)], dtype=dt)
assert_array_equal(x, a)
开发者ID:GunioRobot,项目名称:numpy-refactor,代码行数:9,代码来源:test_io.py
示例8: test_record
def test_record(self):
c = StringIO.StringIO()
c.write('1.312 foo\n1.534 bar\n4.444 qux')
c.seek(0)
dt = [('num', np.float64), ('val', 'S3')]
x = np.fromregex(c, r"([0-9.]+)\s+(...)", dt)
a = np.array([(1.312, 'foo'), (1.534, 'bar'), (4.444, 'qux')], dtype=dt)
assert_array_equal(x, a)
开发者ID:8848,项目名称:Pymol-script-repo,代码行数:9,代码来源:test_io.py
示例9: test_record_2
def test_record_2(self):
c = StringIO()
c.write(asbytes("1312 foo\n1534 bar\n4444 qux"))
c.seek(0)
dt = [("num", np.int32), ("val", "S3")]
x = np.fromregex(c, r"(\d+)\s+(...)", dt)
a = np.array([(1312, "foo"), (1534, "bar"), (4444, "qux")], dtype=dt)
assert_array_equal(x, a)
开发者ID:hector1618,项目名称:numpy,代码行数:9,代码来源:test_io.py
示例10: test_record
def test_record(self):
c = StringIO()
c.write(asbytes("1.312 foo\n1.534 bar\n4.444 qux"))
c.seek(0)
dt = [("num", np.float64), ("val", "S3")]
x = np.fromregex(c, r"([0-9.]+)\s+(...)", dt)
a = np.array([(1.312, "foo"), (1.534, "bar"), (4.444, "qux")], dtype=dt)
assert_array_equal(x, a)
开发者ID:hector1618,项目名称:numpy,代码行数:9,代码来源:test_io.py
示例11: do_once
def do_once(self):
self.file.seek(0)
output = numpy.fromregex(
self.file,
self.line_re,
[('ip', 'S20'), ('day', 'S25'), ('month', 'S20'), ('year', 'S4'), ('time', 'S20'), ('method', 'S7'), ('path', 'S100'), ('size', numpy.int32)]
)
total_time_by_month = defaultdict(int)
for row in output:
total_time_by_month[(row[2], row[1])] += row[7]
开发者ID:pfitzsimmons,项目名称:SpeedDuel,代码行数:10,代码来源:log_parser.py
示例12: test_record_2
def test_record_2(self):
return # pass this test until #736 is resolved
c = StringIO.StringIO()
c.write("1312 foo\n1534 bar\n4444 qux")
c.seek(0)
dt = [("num", np.int32), ("val", "S3")]
x = np.fromregex(c, r"(\d+)\s+(...)", dt)
a = np.array([(1312, "foo"), (1534, "bar"), (4444, "qux")], dtype=dt)
assert_array_equal(x, a)
开发者ID:hadesain,项目名称:robothon,代码行数:10,代码来源:test_io.py
示例13: test_record_2
def test_record_2(self):
c = StringIO.StringIO()
c.write('1312 foo\n1534 bar\n4444 qux')
c.seek(0)
dt = [('num', np.int32), ('val', 'S3')]
x = np.fromregex(c, r"(\d+)\s+(...)", dt)
a = np.array([(1312, 'foo'), (1534, 'bar'), (4444, 'qux')],
dtype=dt)
assert_array_equal(x, a)
开发者ID:GunioRobot,项目名称:numpy-refactor,代码行数:10,代码来源:test_io.py
示例14: combine_history_statsfiles
def combine_history_statsfiles(cnavgdir):
statsfiles = glob.glob(cnavgdir + "/" + "HISTORY_STATS*")
sys.stderr.write("statsfiles: %s\n" % (str(statsfiles)))
mystats = np.array([])
mysims = []
runlens = []
for statsfile in statsfiles:
sim = int(re.match(".*HISTORY_STATS_(\d+)", statsfile).group(1))
mysims.append(sim)
historystats = np.fromregex(statsfile, r"\((\d+), (\d+)\)\t(\d+)\t(\d+)\t(\d+)\t(\d+)", dtype=int)
runlens.append(historystats.shape[0])
runlen = max(runlens)
for sim in mysims:
statsfile = os.path.join(cnavgdir, "HISTORY_STATS_%d" % sim)
historystats = np.fromregex(statsfile, r"\((\d+), (\d+)\)\t(\d+)\t(\d+)\t(\d+)\t(\d+)", dtype=int)
if mystats.size == 0:
mystats = np.zeros(((max(mysims) + 1) * runlen, historystats.shape[1] + 1), dtype=int)
hids = np.array(range(historystats.shape[0])) + sim * Global_BINWIDTH
i = sim * runlen
mystats[i : i + runlen, :] = np.hstack((np.atleast_2d(hids).T, historystats))
return mystats
开发者ID:TracyBallinger,项目名称:cnavgpost,代码行数:21,代码来源:event_cycles_module.py
示例15: parse
def parse(self,xmlHeaderFile,quick=True):
"""
Parse the usefull part of the xml header,
stripping time stamps and non ascii characters
"""
lightXML = StringIO.StringIO()
#to strip the non ascii characters
t = "".join(map(chr, range(256)))
d = "".join(map(chr, range(128,256)))
if not quick:
#store all time stamps in a big array
timestamps = np.fromregex(
xmlHeaderFile,
r'<TimeStamp HighInteger="(\d+)" LowInteger="(\d+)"/>',
float
)
xmlHeaderFile.seek(0)
relTimestamps = np.fromregex(
xmlHeaderFile,
r'<RelTimeStamp Time="(\f+)" Frame="(\d+)"/>|<RelTimeStamp Frame="[0-9]*" Time="[0-9.]*"/>',
float
)
xmlHeaderFile.seek(0)
for line in xmlHeaderFile:
lightXML.write(line.translate(t,d))
else:
#to strip the time stamps
m = re.compile(
r'''<TimeStamp HighInteger="[0-9]*" LowInteger="[0-9]*"/>|'''
+r'''<RelTimeStamp Time="[0-9.]*" Frame="[0-9]*"/>|'''
+r'''<RelTimeStamp Frame="[0-9]*" Time="[0-9.]*"/>'''
)
for line in xmlHeaderFile:
lightXML.write(''.join(m.split(line)).translate(t,d))
lightXML.seek(0)
self.xmlHeader = parse(lightXML)
开发者ID:MathieuLeocmach,项目名称:colloids,代码行数:39,代码来源:lif.py
示例16: main
def main():
args = options()
path=os.getcwd()
#folders=open(args.folder, 'r')
#for l in folders:
# fname=l.replace("\n", "")
# source=str(path)+"/"+str(args.imgfolder)+"/"+str(fname)
# destination=str(path)+"/"+str(args.outdir)
# shutil.move(source, destination)
snapshots=str(path)+"/"+str(args.imgfolder)+"/SnapshotInfo.csv"
#snapshot_data = genfromtxt(snapshots, delimiter=',')
regex="^.*B*.*$"
select=np.fromregex(snapshots,regex)
print snapshot_data
开发者ID:OpenGelo,项目名称:plantcv,代码行数:16,代码来源:util-move_image_folders_safe_save_023311.py
示例17: load_kaldi_priors
def load_kaldi_priors(path, prior_cutoff, uniform_smoothing_scaler=0.05):
assert 0 <= uniform_smoothing_scaler <= 1.0, (
"Expected 0 <= uniform_smoothing_scaler <=1, got %f" % uniform_smoothing_scaler
)
numbers = np.fromregex(path, r"([\d\.e+]+)", dtype=[('num', np.float32)])
class_counts = np.asarray(numbers['num'], dtype=theano.config.floatX)
# compute the uniform smoothing count
uniform_priors = np.ceil(class_counts.mean() * uniform_smoothing_scaler)
priors = (class_counts + uniform_priors) / class_counts.sum()
#floor zeroes to something small so log() on that will be different
# from -inf or better skip these in contribution at all i.e. set to -log(0)?
priors[priors < prior_cutoff] = prior_cutoff
assert np.all(priors > 0) and np.all(priors <= 1.0), (
"Prior probabilities outside [0,1] range."
)
log_priors = np.log(priors)
assert not np.any(np.isinf(log_priors)), (
"Log-priors contain -inf elements."
)
return log_priors
开发者ID:sunits,项目名称:Kaldi_stuff,代码行数:20,代码来源:nnet_train.py
示例18: get_dt
def get_dt(self):
"""
Returns the time step of the simulation.
Returns
-------
A float in seconds.
"""
data_file_path = self.get_data_path()
# matches floats and scientific floats
rg_flt = r"([-\+[0-9]+\.[0-9]*[Ee]*[\+-]*[0-9]*)"
# our UNIT_TIME is scaled to dt
dt = np.fromregex(
data_file_path,
r"\s+UNIT_TIME " +
rg_flt + r"\n",
dtype=np.dtype([('dt', 'float')])
)
return dt['dt'][0]
开发者ID:ALaDyn,项目名称:picongpu,代码行数:22,代码来源:find_time.py
示例19: implement
M, T, intercept = model
MMinv = la.inv( ## implement (X'X)^{-1} (X'Y)
np.dot( M.T, M ) )
coef = np.dot( MMinv,
np.dot( M.T, T ) )
## Estimate the residual standard deviation
resid = T - np.dot(M, coef)
dof = len( T ) - len( coef )
RSS = np.dot( resid.T, resid )
return (coef, RSS, dof, MMinv )
#####################################################################
#+ 0. Load the data (yes, it is a milestone!)
## Load the word count dataset
wordcount = np.fromregex(
'./data/wordcounts.txt', r"(\d+)\s+(.{,32})",
[ ( 'freq', np.int64 ), ( 'word', 'S32' ) ] )
#####################################################################
##+ 1. Check that Zipf's Law holds
## Pre-sort the frequencies: in ascending order of frequencies
wordcount.sort( order = 'freq' )
freqs = wordcount[ 'freq' ]
## PRoduce ranks: from 1 up to |W|
ranks = np.arange( 1, len( wordcount ) + 1, dtype = float )[::-1]
## The probability of a word frequency being not less than the
## frequency of a gien word w it exactly the ratio of the w's rank
## to the total number of words.
probs = ranks / len( wordcount )
开发者ID:ekolbey,项目名称:study_notes,代码行数:30,代码来源:homework01.py
示例20: score_part2
input = np.array(input, dtype=np.int64)
score = input.dot(weights_matrix)
if np.any(score < 0):
return 0
else:
return functools.reduce(operator.mul, score)
def score_part2(input, weights_matrix):
input = np.array(input, dtype=np.int64)
score = input.dot(weights_matrix)
if np.any(score < 0):
return 0
elif score[-1] != 500:
return 0
else:
return functools.reduce(operator.mul, score[:-1])
def partitions():
for x in range(101):
for y in range(101-x):
for z in range((101-x)-y):
for q in range(((101-x)-y)-z):
yield x,y,z,q
regex = r'\w+: capacity (-?\d+), durability (-?\d+), flavor (-?\d+), texture (-?\d+), calories (\d+)'
weights = np.fromregex('input.txt', regex, np.int64)
weights_no_cals = weights[:, :4]
print(max(score(split, weights_no_cals) for split in partitions()))
print(max(score_part2(split, weights) for split in partitions()))
开发者ID:cjm00,项目名称:adventofcode,代码行数:31,代码来源:15.py
注:本文中的numpy.fromregex函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论