Exemple #1
0
def _col_chunks(l, max_rows, row_first=False):
    """Yield successive max_rows-sized column chunks from l."""
    if row_first:
        ncols = (len(l) // max_rows) + (len(l) % max_rows > 0)
        for i in py3compat.xrange(ncols):
            yield [l[j] for j in py3compat.xrange(i, len(l), ncols)]
    else:
        for i in py3compat.xrange(0, len(l), max_rows):
            yield l[i:(i + max_rows)]
Exemple #2
0
def _col_chunks(l, max_rows, row_first=False):
    """Yield successive max_rows-sized column chunks from l."""
    if row_first:
        ncols = (len(l) // max_rows) + (len(l) % max_rows > 0)
        for i in py3compat.xrange(ncols):
            yield [l[j] for j in py3compat.xrange(i, len(l), ncols)]
    else:
        for i in py3compat.xrange(0, len(l), max_rows):
            yield l[i:(i + max_rows)]
Exemple #3
0
 def wrapper(*args, **kargs):
     offspring = func(*args, **kargs)
     for child in offspring:
         for i in xrange(len(child)):
             if child[i] > max:
                 child[i] = max
             elif child[i] < min:
                 child[i] = min
     return offspring
Exemple #4
0
 def area(self):
     '''
     Compute the grain area for each grain
     
     :return: g_arean array of scalar of grain area in mm^2
     :rtype: g_area np.array
     '''
     
     g_map=self.grain_label()
     
     g_area=np.zeros(np.max(g_map.field))
     
     for i in list(xrange(np.size(g_area))):
         g_area[i]=np.size(np.where(g_map.field==i))*g_map.res**2.
         
     return g_area
Exemple #5
0
def select_random_ports(n):
    """Selects and return n random ports that are available."""
    ports = []
    for i in xrange(n):
        sock = socket.socket()
        sock.bind(('', 0))
        while sock.getsockname()[1] in _random_ports:
            sock.close()
            sock = socket.socket()
            sock.bind(('', 0))
        ports.append(sock)
    for i, sock in enumerate(ports):
        port = sock.getsockname()[1]
        sock.close()
        ports[i] = port
        _random_ports.add(port)
    return ports
def select_random_ports(n):
    """Selects and return n random ports that are available."""
    ports = []
    for i in xrange(n):
        sock = socket.socket()
        sock.bind(('', 0))
        while sock.getsockname()[1] in _random_ports:
            sock.close()
            sock = socket.socket()
            sock.bind(('', 0))
        ports.append(sock)
    for i, sock in enumerate(ports):
        port = sock.getsockname()[1]
        sock.close()
        ports[i] = port
        _random_ports.add(port)
    return ports
Exemple #7
0
def _chunks(l, n):
    """Yield successive n-sized chunks from l."""
    for i in py3compat.xrange(0, len(l), n):
        yield l[i:i+n]
Exemple #8
0
def make_2d_list(rows, cols):
    a = []
    for row in xrange(rows):
        a += [[0] * cols]
    return a
Exemple #9
0
a = [[2, 3, 4], [5, 6, 7]]
print(a)
"""
Dynamic Allocation
"""

#=========================================================
# Create a variable-sized 2d list
#=========================================================
# (1) Append each row
rows = 3
cols = 2

a = []
for row in xrange(rows):
    a += [[0] * cols]

print("This IS ok.  At first:")
print("   a = {}".format(a))

#--------------------------------------------------------
a[0][0] = 42
print("And now see what happens after a[0][0]=42")
print("   a = {}".format(a))

#=========================================================
# (2) Use a 2D List


def make_2d_list(rows, cols):
Exemple #10
0
from IPython.utils.py3compat import xrange

a = [1, 1, 2, 3, 5, 9, 13, 34, 21, 12, 89]
l = []

print(isinstance(a, list))
for i in a:
    if i <= 20:
        l.append(i)
print(l)
''' 
range is used to create the list of numbers dynamically
'''
user_input = int(input("Enter any number for which you want divisors."))
divisors = []
x = xrange(1, 101)

for i in x:
    if (user_input % i) == 0:
        divisors.append(i)

print(divisors)
''' 
List overlap 
this will get the common inputs without duplicates 
in the two lists which are entered by the user
'''
first_list = input("Enter 1st list of values separated by ',' ")
second_list = input("Enter 2nd list of values separated by ',' ")
common_values = []
a = [i for i in first_list.split(sep=',')]