def read_input(f): if not f: raise Exception("invalid file") numbers = [] for line in fileinput.input(f): if not fileinput.isfirstline(): numbers.append(int(line.strip())) return numbers
def getNumbersFromErrLog(): numbers = [] file = open("F:\Workspace\_data\log\\resumeSpider\error-logging3.log", "r") lines = file.readlines() for line in lines: beginIndex = line.index("-") endIndex = line.index(".zip") number = line[beginIndex + 1: endIndex] numbers.append(number) file.close() print(numbers) return numbers
def MyLoop(x): i = 0 n = x numbers = [] #*** while i < n: numbers.append(i) print numbers print "at the bottom is %d" % numbers[i] i = i + 1 print n, i for num in numbers: print num
def _get_node_number(shader: str, taken_numbers: dict) -> int: if shader not in taken_numbers: taken_numbers[shader] = [None] numbers = taken_numbers[shader] for i, n in enumerate(numbers): if n is None: numbers[i] = i return i # If no empty slot is found, add the next bigger number to the end of the list num = len(numbers) numbers.append(num) return num
def fill_out_numbers(peaks, rate): """Fill in numbers between peaks. Parameters ---------- peaks : array-like Peaks to fill between. rate : float Rate to use between peaks. Examples -------- >>> fill_out_numbers([0, 1, -1], rate=0.25) array([ 0. , 0.25, 0.5 , 0.75, 1. , 0.75, 0.5 , 0.25, 0. , -0.25, -0.5 , -0.75, -1. ]) >>> fill_out_numbers([[0, 1, -1], [1, 2, -2]], rate=0.25) array([[ 0. , 1. , -1. ], [ 0.25, 1.25, -1.25], [ 0.5 , 1.5 , -1.5 ], [ 0.75, 1.75, -1.75], [ 1. , 2. , -2. ]]) Ported from the MATLAB function written by Mark Denavit. """ peaks = np.array(peaks) if len(peaks.shape) == 1: peaks = peaks.reshape(peaks.size, 1) if peaks.shape[0] == 1: peaks = peaks.T numpeaks = peaks.shape[0] numbers = [peaks[0, :]] for i in range(numpeaks - 1): diff = peaks[i + 1, :] - peaks[i, :] numsteps = int(np.maximum(2, 1 + np.ceil(np.max(np.abs(diff / rate))))) numbers_to_add = np.linspace(peaks[i, :], peaks[i + 1, :], numsteps) numbers.append(numbers_to_add[1:, :]) numbers = np.vstack(numbers) if 1 in numbers.shape: numbers = numbers.flatten() return numbers
sean0 += case[i] else: pat1 ^= case[i] sean1 += case[i] i += 1 if (pat0 == pat1): return max(sean0, sean1) return 0 def analyze(case, n): pattern = [] numbers_split = case.rstrip().split(' ') numbers = [] for number in numbers_split: numbers.append(int(number)) actual_max = 0 pattern.append(1) for i in range(1, n): pattern.append(0) while (pattern.count(0) > 0): sum = sum_check(numbers, pattern, n) if (sum > actual_max): actual_max = sum advance_one(pattern, n) # print pattern if (actual_max > 0): return actual_max else:
from _ast import Num from PIL.ImImagePlugin import number import numbers i = 0 numbers = [] while i < 6: print "At the top i is %d" % i numbers.append(i) i = i + 1 print "Numbers now:", numbers print "At the bottom i is %d" % i print "The numbers:" for num in numbers: print num def MyLoop(x): i = 0 n = x numbers = [] #*** while i < n: numbers.append(i) print numbers print "at the bottom is %d" % numbers[i] i = i + 1 print n, i for num in numbers: print num
def interpolate_1d_linear_old( x_in, val_in, x_out, x_tolerance=0, out_of_bounds='nan', assume_sorted=True, many_nans=False, ): """Linear 1D-interpolation for numbers or datetime. x_in and x_out can be floats or datetime.datetime instances. Parameters ---------- x_in : array of floats or list of datetime.datetime x_out : array of floats or list of datetime.datetime val_in : array of floats same length as x_in x_tolerance : float or datetime.timedelta, optional only nearest neighbours that are close than x_tolerance are considered. 0 causes infinite tolerance! Default: 0. out_of_bounds : {'zero', 'nan', 'nearest', float} out of bounds value are replaced by this assume_sorted : bool if True, the function assumes that x_in be sorted in rising order many_nans : bool Switch this to True, if either x_in or val_in contain a lot of nan's. The function yields exactly the same result, regardless on whether many_nans is True or False. It is just a matter of performance. If x_in or val_in contain a lot of nan's, switching this to True will speed up the function. If they don't, it will slow down the function. Returns ------- val_out : array The output is a linear interpolation between the sample values given in values_sample at the times given in val_in. Notes ----- float vs datetime.datetime: If some of x_in, x_out, or x_tolerance are given in numerical values and others as instances of datetime.datetime (or datetime.timedelta in the case of x_tolerance), the numericals are considered as seconds (since 1970). x_tolercance: if 0, this is interpreted as infinite tolerance! Author ------ Written in 2014-2016 by Andreas Anhaeuser Insitute for Geophysics and Meteorology University of Cologne Germany <*****@*****.**> """ #### CHECK INPUT ### if not len(x_in) == len(val_in): raise LookupError('x_in and val_in must be of the same length.') #### Unsorted # recursively call function if unsorted: if not assume_sorted: idx_old = np.argsort(x_in) xi_sor = sorted(x_in) vi_sor = [val_in[i] for i in idx_old] o = out_of_bounds return interpolate_1d_linear(x_in = xi_sor, val_in = vi_sor, x_out = x_out, x_tolerance = x_tolerance, out_of_bounds = o, assume_sorted = True) # this is for dealing with out of bounds values lateron: if out_of_bounds in ['nan', 'NaN']: oob = 'val' oobv = np.nan elif out_of_bounds in ['zero', 'zeros', '0']: oob = 'val' oobv = 0. elif isinstance(out_of_bounds, numbers.Number): oob = 'val' oobv = out_of_bounds else: oob = 'nn' oobv = None # special case: empty input array: if len(x_in) == 0: return np.array([oobv] * len(x_out)) # special case: empty output array: if len(x_out) == 0: return np.array([]) # copy arrays and convert to np.array: xi = x_in[:] xo = x_out[:] vi = val_in[:] tol = x_tolerance # convert datetime_list into a numerical list: for c in [xi, xo, vi]: if isinstance(c[0], dt.datetime): c[:] = du.datetime_to_seconds(c) # convert numpy arrays to lists: def convert(x): if isinstance(x, np.ndarray): return x.tolist() else: return x xi = convert(xi) xo = convert(xo) vi = convert(vi) # convert tol from timedelta to numerical: if isinstance(tol, dt.timedelta): tol = tol.seconds # convert tol==0 to inf: if tol == 0: tol = np.inf #### NaN's # If vi contains a lot of nan's, this will slow down nearest_neighbour. # For this reason, delete these elements from xi and vi: if many_nans: n = 0 numbers = [] for n in range(len(xi)): if not (np.isnan(vi[n]) or np.isnan(xi[n])): numbers.append(n) xi = [xi[n] for n in numbers] vi = [vi[n] for n in numbers] #### INTERPOLATION # interpolation function: def f(xlo, xhi, vlo, vhi, x): """Linear interpolation function.""" return ((x-xlo) * vhi + (xhi-x) * vlo) / (xhi-xlo) # initialization: valout = [] N = len(xo) n = 0 for x in xo: n += 1 ### # FIND NEAREST NEIGHBOURS AND DETERMINE DISTANCES # nearest neighbours: xlo, ilo, vlo = nearest_neighbour( xi, x, direction='down', values=vi, skip_nans=True, assume_sorted=True) xhi, ihi, vhi = nearest_neighbour( xi, x, direction='up', values=vi, skip_nans=True, assume_sorted=True) # if no nearest neighbour is found: if xlo==None: xlo = -np.inf if xhi==None: xhi = +np.inf if vlo==None: vlo = np.nan if vhi==None: vhi = np.nan # distances: distlo = x-xlo disthi = xhi-x dist = [distlo, disthi] ### # DETERMINE THE INTERPOLATED VALUE v CORRESPONDING TO x # special case: x is exactly on a non-nan input point: if max(dist) == 0: v = vlo # (vlo==vhi in this case) # finite tolerance: elif tol < np.inf: inbounds = (distlo <= tol, disthi <= tol) if inbounds == (True, True): v = f(xlo, xhi, vlo, vhi, x) elif inbounds == (True, False): v = vlo elif inbounds == (False, True): v = vhi elif inbounds == (False, False) and oob == 'val': v = oobv elif inbounds == (False, False) and oob == 'nn': if distlo <= disthi: v = vlo else: v = vhi # infinite tolerance: elif tol == np.inf: neighbours = (distlo<np.inf,disthi<np.inf) if neighbours==(True, True): v = f(xlo,xhi,vlo,vhi,x) elif False in neighbours and oob=='val': v = oobv elif False in neighbours and oob=='nn': if distlo<=disthi: v = vlo else: v = vhi # EXTEND OUTPUT ARRAY BY v: valout.append(v) return np.array(valout)