Re: how to simulate the situation in DNA evolution for finding the minimum population needed and minimum samples selected to mating in order to no extinction in any one of original species and new spe
i noticed the faces of human repeated or similar, and would like to prove whether evolution a several generations will return to the original intelligence of ancester On Friday, November 18, 2016 at 1:55:31 PM UTC+8, meInvent bbird wrote: > how to simulate the situation in DNA evolution for finding the minimum > population needed and minimum samples selected to mating in order to no > extinction in any one of original species and new species > > assume mating are randomly selected to become a couple, > how to keep species good which means no extinction in original species > > i use i+j to get new species, > but i do not know whether there is limit in evolution, i assume > limit is 7, then extra evolution will go back to past species and > cycle again > > import matplotlib.pyplot as plt > import random > dict = {} > dist = {} > maxnum = 5 > allowedmax = 7 > for i in range(1,allowedmax+1): > dist[str(i)] = 0 > > rr = range (1,maxnum) > for i in range (1,maxnum): > for j in range (1,maxnum): > if i < j: > print("(" +str(i) + "," + str(j) + ")"); > dict[str(i) + str(j)] = 1; > dist[str(i+j)] = dist[str(i+j)] + 1 > if i+j > max(rr or [0]): > rr = rr + [i+j]; > > original = rr; > for numberofevolutions in range(1,10): > rr2 = [] > samples = random.sample(original, len(original)-2) > print("total rr") > print(str(rr)) > print("samples") > print(str(samples)) > for i in samples: > for j in samples: > if i < j: > print("(" +str(i) + "," + str(j) + ")"); > if i+j > allowedmax: > dict[str(i) + str(j)] = (i+j) % allowedmax; > dist[str((i+j) % allowedmax)] = dist[str((i+j) % > allowedmax)] + 1 > if ((i+j) % allowedmax) > max(rr2 or [0]): > rr2 = rr2 + [((i+j) % allowedmax)]; > else: > dict[str(i) + str(j)] = i+j; > dist[str(i+j)] = dist[str(i+j)] + 1 > if i+j > max(rr2 or [0]): > rr2 = rr2 + [i+j]; > temp = rr > rr = rr2 > rr2 = temp > > plt.bar(range(len(dist)), dist.values(), align='center') > plt.xticks(range(len(dist)), dist.keys()) > plt.show() -- https://mail.python.org/mailman/listinfo/python-list
how to simulate the situation in DNA evolution for finding the minimum population needed and minimum samples selected to mating in order to no extinction in any one of original species and new species
how to simulate the situation in DNA evolution for finding the minimum population needed and minimum samples selected to mating in order to no extinction in any one of original species and new species assume mating are randomly selected to become a couple, how to keep species good which means no extinction in original species i use i+j to get new species, but i do not know whether there is limit in evolution, i assume limit is 7, then extra evolution will go back to past species and cycle again import matplotlib.pyplot as plt import random dict = {} dist = {} maxnum = 5 allowedmax = 7 for i in range(1,allowedmax+1): dist[str(i)] = 0 rr = range (1,maxnum) for i in range (1,maxnum): for j in range (1,maxnum): if i < j: print("(" +str(i) + "," + str(j) + ")"); dict[str(i) + str(j)] = 1; dist[str(i+j)] = dist[str(i+j)] + 1 if i+j > max(rr or [0]): rr = rr + [i+j]; original = rr; for numberofevolutions in range(1,10): rr2 = [] samples = random.sample(original, len(original)-2) print("total rr") print(str(rr)) print("samples") print(str(samples)) for i in samples: for j in samples: if i < j: print("(" +str(i) + "," + str(j) + ")"); if i+j > allowedmax: dict[str(i) + str(j)] = (i+j) % allowedmax; dist[str((i+j) % allowedmax)] = dist[str((i+j) % allowedmax)] + 1 if ((i+j) % allowedmax) > max(rr2 or [0]): rr2 = rr2 + [((i+j) % allowedmax)]; else: dict[str(i) + str(j)] = i+j; dist[str(i+j)] = dist[str(i+j)] + 1 if i+j > max(rr2 or [0]): rr2 = rr2 + [i+j]; temp = rr rr = rr2 rr2 = temp plt.bar(range(len(dist)), dist.values(), align='center') plt.xticks(range(len(dist)), dist.keys()) plt.show() -- https://mail.python.org/mailman/listinfo/python-list
what is the procedure or how to plan how many nodes of dispy need for dsolve differential system in amazon cloud in limited time such as 1 hour, 2 hours.etc
what is the procedure or how to plan how many nodes of dispy need for dsolve differential system in amazon cloud in limited time such as 1 hour, 2 hours.etc ? #For Amazon Linux, the user name is ec2-user. For RHEL5, the user name is either root or ec2-user. #For Ubuntu, the user name is ubuntu. For Fedora, the user name is either fedora or ec2-user. #For SUSE Linux, the user name is either root or ec2-user. #Otherwise, if ec2-user and root don't work, check with your AMI provider. import random, dispy import ast from __future__ import division from sympy import * x, y, z, t = symbols('x y z t') k, m, n = symbols('k m n', integer=True) f, g, h = symbols('f g h', cls=Function) import inspect def compute(n): # executed on nodes import random, time, socket name = socket.gethostname() cur_best = 1 for ii in range(n[0],n[0]): for jj in range(n[1],n[1]): for kk in range(n[2],n[3],100): #assume dsolve with sympy for differential system dispy_provisional_result((name, r)) cur_best = r time.sleep(0.1) # final result return (name, cur_best) def job_callback(job): # executed at the client if job.status == dispy.DispyJob.ProvisionalResult: #if job.result[1] < 0.005: # acceptable result; terminate jobs print('%s computed: %s %s %s %s' % (job.result[0], job.result[1], job.result[2], job.result[3], job.result[4])) # 'jobs' and 'cluster' are created in '__main__' below for j in jobs: if j.status in [dispy.DispyJob.Created, dispy.DispyJob.Running, dispy.DispyJob.ProvisionalResult]: cluster.cancel(j) if __name__ == '__main__': #cluster = dispy.JobCluster(compute, callback=job_callback) cluster = dispy.JobCluster(compute, nodes=['ec2-35-162-137-237.us-west-2.compute.amazonaws.com'], ip_addr='127.0.0.1', port=51347, node_port=51348, callback=job_callback, keyfile=r"C:\Users\hello\datacenterusekey.ppk") jobs = [] prevk = 1 count = 0 for ii in range(1,2): for jj in range(1,2000): for kk in range(1,2000,100): if ii < jj and jj < kk: job = cluster.submit([ii,jj,prevk,kk]) prevk = kk if job is None: print('creating job %s failed!' % n) continue job.id = count count = count + 1 jobs.append(job) cluster.wait() cluster.print_status() cluster.close() -- https://mail.python.org/mailman/listinfo/python-list
Re: how to compile this code
>>> class ChangeAddToMultiply(ast.NodeTransformer, ast2.NodeTransformer): ... """Wraps all integers in a call to Integer()""" ... def visit_BinOp(self, node): ... print(dir(node)) ... print(dir(node.left)) ... if isinstance(node.op, ast.Add): ... ast.Call(Name(id="op2", ctx=ast2.Load()), [node.left, node.right ], []) ... return node ... Traceback (most recent call last): File "", line 1, in NameError: name 'ast2' is not defined >>> >>> code = inspect.getsourcelines(solve) >>> tree = ast.parse(code) Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\ast.py", line 37, in parse return compile(source, filename, mode, PyCF_ONLY_AST) TypeError: expected a readable buffer object >>> tree2 = ast.parse("def op2(a,b): return a*b+a") >>> tree = ChangeAddToMultiply().visit(tree,tree2) Traceback (most recent call last): File "", line 1, in NameError: name 'tree' is not defined >>> ast.fix_missing_locations(tree) Traceback (most recent call last): File "", line 1, in NameError: name 'tree' is not defined >>> co = compile(tree, '', "exec") Traceback (most recent call last): File "", line 1, in NameError: name 'tree' is not defined >>> >>> exec(code) Traceback (most recent call last): File "", line 1, in TypeError: exec: arg 1 must be a string, file, or code object >>> exec(co) * def op2(a,b): return a*b+a class ChangeAddToMultiply(ast.NodeTransformer, ast2.NodeTransformer): """Wraps all integers in a call to Integer()""" def visit_BinOp(self, node): print(dir(node)) print(dir(node.left)) if isinstance(node.op, ast.Add): ast.Call(Name(id="op2", ctx=ast2.Load()), [node.left, node.right], []) return node code = inspect.getsourcelines(solve) tree = ast.parse(code) tree2 = ast.parse("def op2(a,b): return a*b+a") tree = ChangeAddToMultiply().visit(tree,tree2) ast.fix_missing_locations(tree) co = compile(tree, '', "exec") exec(code) exec(co) On Tuesday, November 1, 2016 at 9:04:43 PM UTC+8, Yann Kaiser wrote: > You want to replace the `Add` ast with a `Call` ast rather than just > calling your function. > > Something like: > > if isinstance(node.op, ast.Add): > return ast.Call(some_ast_expression_that_will_evaluate_to_op, > [node.left, node.right], []) > > You'll have to replace some_ast_expression_... to something like > Name(id="op2", ctx=ast.Load()) and inject op2 in the globals when you call > `exec`. > > On Tue, Nov 1, 2016, 06:36 meInvent bbird <jobmatt...@gmail.com> wrote: > > > would like to change Add operator to custom function op2 in solve function > > and then this solve([x*y - 1, x + 2], x, y) > > during solve, the parameters also change Add to custom function op2 > > > > import ast > > from __future__ import division > > from sympy import * > > x, y, z, t = symbols('x y z t') > > k, m, n = symbols('k m n', integer=True) > > f, g, h = symbols('f g h', cls=Function) > > import inspect > > > > def op2(a,b): > > return a*b+a > > > > class ChangeAddToMultiply(ast.NodeTransformer): > > """Wraps all integers in a call to Integer()""" > > def visit_BinOp(self, node): > > print(dir(node)) > > print(dir(node.left)) > > if isinstance(node.op, ast.Add): > > node.op = op2(node.left, node.right) > > return node > > > > code = inspect.getsourcelines(solve) > > tree = ast.parse(code) > > tree = ChangeAddToMultiply().visit(tree) > > ast.fix_missing_locations(tree) > > co = compile(tree, '', "exec") > > > > exec(code) > > exec(co) > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > Yann Kaiser > kaiser.y...@gmail.com > yann.kai...@efrei.net > +33 6 51 64 01 89 > https://github.com/epsy -- https://mail.python.org/mailman/listinfo/python-list
Re: how to debug this distributed program?
i follow documentation and add keyfile to indicate the path of private key but still no response from program, what is the correct way to do? cluster = dispy.JobCluster(compute, nodes=['ec2-35-162-137-237.us-west-2.compute.amazonaws.com'], callback=job_callback, keyfile=r"C:\Users\martlee2\Downloads\datacenterusekey.ppk") On Tuesday, November 1, 2016 at 3:58:24 PM UTC+8, Steve D'Aprano wrote: > On Tue, 1 Nov 2016 06:40 pm, meInvent bbird wrote: > > > how to debug this distributed program? > > > The same way you would debug any other program. > > http://sscce.org/ > > > > > > -- > Steve > “Cheer up,” they said, “things could be worse.” So I cheered up, and sure > enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list
how to debug this distributed program?
https://drive.google.com/open?id=0Bxs_ao6uuBDUSEc5S3U3Nko5ZjA A. i am not sure whether parameter start from 0 or 1 n[0] or n[1] in compute function B. it run a very long time and nothing to see in amazon linux instance there is no python program in top command C. in distributed programming web site, there is no authentication method using private key in python program, how do distributed program access the nodes in amazon cloud when run python program below in window locally? import random, dispy def compute(n): # executed on nodes import random, time, socket name = socket.gethostname() cur_best = 1 for ii in range(n[0],n[0]): for jj in range(n[1],n[1]): for kk in range(n[2],n[3],100): dispy_provisional_result((name, r)) cur_best = r time.sleep(0.1) # final result return (name, cur_best) def job_callback(job): # executed at the client if job.status == dispy.DispyJob.ProvisionalResult: #if job.result[1] < 0.005: # acceptable result; terminate jobs print('%s computed: %s %s %s %s' % (job.result[0], job.result[1], job.result[2], job.result[3], job.result[4])) # 'jobs' and 'cluster' are created in '__main__' below for j in jobs: if j.status in [dispy.DispyJob.Created, dispy.DispyJob.Running, dispy.DispyJob.ProvisionalResult]: cluster.cancel(j) if __name__ == '__main__': #cluster = dispy.JobCluster(compute, callback=job_callback) cluster = dispy.JobCluster(compute, nodes=['ec2-100-162-137-237.us-west-2.compute.amazonaws.com'], callback=job_callback) jobs = [] prevk = 1 count = 0 for ii in range(1,2): for jj in range(1,2000): for kk in range(1,2000,100): if ii < jj and jj < kk: job = cluster.submit([ii,jj,prevk,kk]) prevk = kk if job is None: print('creating job %s failed!' % n) continue job.id = count count = count + 1 jobs.append(job) cluster.wait() cluster.print_status() cluster.close() -- https://mail.python.org/mailman/listinfo/python-list
how to compile this code
would like to change Add operator to custom function op2 in solve function and then this solve([x*y - 1, x + 2], x, y) during solve, the parameters also change Add to custom function op2 import ast from __future__ import division from sympy import * x, y, z, t = symbols('x y z t') k, m, n = symbols('k m n', integer=True) f, g, h = symbols('f g h', cls=Function) import inspect def op2(a,b): return a*b+a class ChangeAddToMultiply(ast.NodeTransformer): """Wraps all integers in a call to Integer()""" def visit_BinOp(self, node): print(dir(node)) print(dir(node.left)) if isinstance(node.op, ast.Add): node.op = op2(node.left, node.right) return node code = inspect.getsourcelines(solve) tree = ast.parse(code) tree = ChangeAddToMultiply().visit(tree) ast.fix_missing_locations(tree) co = compile(tree, '', "exec") exec(code) exec(co) -- https://mail.python.org/mailman/listinfo/python-list
Re: how to evaluate a ast tree and change Add to Multiply ?
Hi Jerry, how about custom function? i change to node.op = ast.op2() import ast def op2(a,b): return a*b+a class ChangeAddToMultiply(ast.NodeTransformer): """Wraps all integers in a call to Integer()""" def visit_BinOp(self, node): if isinstance(node.op, ast.Add): node.op = ast.op2() return node code = 'print(2+5)' tree = ast.parse(code) tree = ChangeAddToMultiply().visit(tree) ast.fix_missing_locations(tree) co = compile(tree, '', "exec") exec(code) exec(co) On Thursday, October 20, 2016 at 12:34:55 AM UTC+8, Jerry Hill wrote: > On Wed, Oct 12, 2016 at 5:55 AM, meInvent bbird <jobmatt...@gmail.com> wrote: > > i just expect to > > rewrite + become multiply > > by edit the example in the link provided > > This seems to work. You need to define visit_BinOp instead of > visit_Num (since you want to mess with the binary operations, not the > numbers). Then,in visit_BinOp, we just replace the ast.Add node with > an ast.Mult node. > > import ast > > class ChangeAddToMultiply(ast.NodeTransformer): > """Wraps all integers in a call to Integer()""" > def visit_BinOp(self, node): > if isinstance(node.op, ast.Add): > node.op = ast.Mult() > return node > > code = 'print(2+5)' > tree = ast.parse(code) > tree = ChangeAddToMultiply().visit(tree) > ast.fix_missing_locations(tree) > co = compile(tree, '', "exec") > > exec(code) > exec(co) > > -- > Jerry -- https://mail.python.org/mailman/listinfo/python-list
is it possible use python to run another main point or function in some range of memory in executable file
is it possible python to run another main point or function in some range of memory in executable file -- https://mail.python.org/mailman/listinfo/python-list
Re: how to send a json of yield list
when not to use queue, it is faster now while True: for ii in getcombinations(): item = ii print(item) sock.send(json.dumps(ii)) On Friday, October 14, 2016 at 5:11:35 PM UTC+8, meInvent bbird wrote: > succeed to run, > > is it the yield return the whole list 2000 * 2000 * 2000 items? > > as i know that yield is return [1,1,1] etc one by one once it get > > if it return 2000*2000*2000 items, why? > > i have to add a queue get this yield in order to succeed > > but i do not understand the situation when > using queue and yield at the same time > > will the speed same as the situation that no yield? > > while True: > #time.sleep(1) > if q.qsize() > 0: > print("here1") > item = q.get() > print("here2") > #item = getcombinations() > sock.send(json.dumps(item)) -- https://mail.python.org/mailman/listinfo/python-list
Re: how to send a json of yield list
succeed to run, is it the yield return the whole list 2000 * 2000 * 2000 items? as i know that yield is return [1,1,1] etc one by one once it get if it return 2000*2000*2000 items, why? i have to add a queue get this yield in order to succeed but i do not understand the situation when using queue and yield at the same time will the speed same as the situation that no yield? while True: #time.sleep(1) if q.qsize() > 0: print("here1") item = q.get() print("here2") #item = getcombinations() sock.send(json.dumps(item)) -- https://mail.python.org/mailman/listinfo/python-list
Re: how to use pycallgraph in ubuntu and window?
succeed to draw graph, thanks originally i think pip install graphviz is enough then search again there is an win32 executable file graphviz need to be install On Friday, October 14, 2016 at 2:58:48 PM UTC+8, dieter wrote: > meInvent bbird <jobmatt...@gmail.com> writes: > > > i install in ubunbu 14 > > > > pip install graphviz > > pip install pycallgraph > > > > martin@ubuntu:~/Downloads$ pycallgraph graphviz -- ./pusher.py > > Traceback (most recent call last): > > ... > > pycallgraph.exceptions.PyCallGraphException: The command "dot" is required > > to be in your path. > > This tells you that a required (operating system level) utility > (named "dot") is not available. > > Carefully read the installation instructions, especially any > remark about dependencies. This should tell you where "dot" is supposed > to come from. Install all operating system level dependencies. > > If "dot" should have come from "graphviz", then maybe a > "hash" is necessary to let your shell see new commands. -- https://mail.python.org/mailman/listinfo/python-list
Can't pickle : attribute lookup __builtin__.gen erator failed
Traceback (most recent call last): File "C:\Python27\lib\multiprocessing\queues.py", line 262, in _feed send(obj) PicklingError: Can't pickle : attribute lookup __builtin__.gen erator failed #python pusher.py tcp://*:8080 import sys import time import zmq from multiprocessing import Queue import threading import json from json import dumps, loads, JSONEncoder, JSONDecoder import pickle from pycallgraph import PyCallGraph from pycallgraph.output import GraphvizOutput class PythonObjectEncoder(JSONEncoder): def default(self, obj): if isinstance(obj, (list, dict, str, unicode, int, float, bool, type(None))): return JSONEncoder.default(self, obj) return {'_python_object': pickle.dumps(obj)} def as_python_object(dct): if '_python_object' in dct: return pickle.loads(str(dct['_python_object'])) return dct context = zmq.Context() sock = context.socket(zmq.PUSH) sock.bind(sys.argv[1]) def getcombinations(): for ii in range(1,2000): for jj in range(1,2000): for kk in range(1,2000): yield [ii,jj,kk] class StreamArray(list): def __iter__(self): return getcombinations() # according to the comment below def __len__(self): return 1 def worker(): while True: if q.qsize() < 1000: q.put(getcombinations()) q = Queue(maxsize=1000) t = threading.Thread(target=worker, args = ()) t.daemon = True t.start() while True: time.sleep(1) #sock.send(sys.argv[1] + ':' + time.ctime()) combobject = getcombinations() #sock.send(json.dumps(combobject, cls=PythonObjectEncoder)) if q.qsize() > 0: item = q.get() sock.send(json.dumps(item)) #sock.send(json.dumps(combobject, cls=PythonObjectEncoder)) -- https://mail.python.org/mailman/listinfo/python-list
how to use pycallgraph in ubuntu and window?
i install in ubunbu 14 pip install graphviz pip install pycallgraph martin@ubuntu:~/Downloads$ pycallgraph graphviz -- ./pusher.py Traceback (most recent call last): File "/usr/local/bin/pycallgraph", line 25, in with __pycallgraph.PyCallGraph(config=__config): File "/usr/local/lib/python2.7/dist-packages/pycallgraph/pycallgraph.py", line 32, in __init__ self.reset() File "/usr/local/lib/python2.7/dist-packages/pycallgraph/pycallgraph.py", line 53, in reset self.prepare_output(output) File "/usr/local/lib/python2.7/dist-packages/pycallgraph/pycallgraph.py", line 97, in prepare_output output.sanity_check() File "/usr/local/lib/python2.7/dist-packages/pycallgraph/output/graphviz.py", line 63, in sanity_check self.ensure_binary(self.tool) File "/usr/local/lib/python2.7/dist-packages/pycallgraph/output/output.py", line 96, in ensure_binary 'The command "{}" is required to be in your path.'.format(cmd)) pycallgraph.exceptions.PyCallGraphException: The command "dot" is required to be in your path. in window i had already added path C:\Python27\Lib\site-packages\graphviz;C:\Python27\Lib\site-packages\pycallgraph to environment variable path but in cmd 'pycallgraph' is not recognized as an internal or external command, operable program or batch file. then i use full path >python "C:\Python27\Lib\site-packages\pycallgraph\py callgraph.py" -- "C:\Users\hello\Downloads\pusher.py" Traceback (most recent call last): File "C:\Python27\Lib\site-packages\pycallgraph\pycallgraph.py", line 3, in from .output import Output ValueError: Attempted relative import in non-package -- https://mail.python.org/mailman/listinfo/python-list
how to send a json of yield list
after google a several solutions, First method i searched has memory error sock.send(json.dumps(StreamArray())) Traceback (most recent call last): File "pusher.py", line 43, in sock.send(json.dumps(StreamArray())) File "C:\Python27\lib\json\__init__.py", line 243, in dumps return _default_encoder.encode(obj) File "C:\Python27\lib\json\encoder.py", line 207, in encode chunks = self.iterencode(o, _one_shot=True) File "C:\Python27\lib\json\encoder.py", line 270, in iterencode return _iterencode(o, 0) MemoryError if use this solution, got another error combobject = getcombinations() sock.send(json.dumps(combobject, cls=PythonObjectEncoder)) C:\Users\martlee2\Downloads>python pusher.py tcp://*:8080 Traceback (most recent call last): File "pusher.py", line 42, in sock.send(json.dumps(combobject, cls=PythonObjectEncoder)) File "C:\Python27\lib\json\__init__.py", line 250, in dumps sort_keys=sort_keys, **kw).encode(obj) File "C:\Python27\lib\json\encoder.py", line 207, in encode chunks = self.iterencode(o, _one_shot=True) File "C:\Python27\lib\json\encoder.py", line 270, in iterencode return _iterencode(o, 0) File "pusher.py", line 13, in default return {'_python_object': pickle.dumps(obj)} File "C:\Python27\lib\pickle.py", line 1374, in dumps Pickler(file, protocol).dump(obj) File "C:\Python27\lib\pickle.py", line 224, in dump self.save(obj) File "C:\Python27\lib\pickle.py", line 306, in save rv = reduce(self.proto) File "C:\Python27\lib\copy_reg.py", line 70, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle generator objects #python pusher.py tcp://*:8080 import sys import time import zmq import json from json import dumps, loads, JSONEncoder, JSONDecoder import pickle class PythonObjectEncoder(JSONEncoder): def default(self, obj): if isinstance(obj, (list, dict, str, unicode, int, float, bool, type(None))): return JSONEncoder.default(self, obj) return {'_python_object': pickle.dumps(obj)} def as_python_object(dct): if '_python_object' in dct: return pickle.loads(str(dct['_python_object'])) return dct context = zmq.Context() sock = context.socket(zmq.PUSH) sock.bind(sys.argv[1]) def getcombinations(): for ii in range(1,2000): for jj in range(1,2000): for kk in range(1,2000): yield [ii,jj,kk] class StreamArray(list): def __iter__(self): return getcombinations() # according to the comment below def __len__(self): return 1 while True: time.sleep(1) #sock.send(sys.argv[1] + ':' + time.ctime()) combobject = getcombinations() sock.send(json.dumps(combobject, cls=PythonObjectEncoder)) puller.py #python puller.py tcp://localhost:8080 import sys import zmq import json context = zmq.Context() sock = context.socket(zmq.PULL) for arg in sys.argv[1:]: sock.connect(arg) while True: message = sock.recv() combinations = json.loads(message) print(str(combinations)) -- https://mail.python.org/mailman/listinfo/python-list
Re: how to read linux kernel source with pycparser
is it possible to git pull a part of directory such as sched and compile this subdirectory and pycparser it? i got error when run gcc -E git submodule add he...@github.com:hello/repo.git kernel/sched cd kernel/sched git pull martin@ubuntu:~/Downloads/kernel/sched$ gcc -E -std=c99 *.c # 1 "auto_group.c" # 1 "" # 1 "" # 1 "auto_group.c" # 1 "sched.h" 1 # 1 "/usr/include/linux/sched.h" 1 3 4 # 2 "sched.h" 2 In file included from auto_group.c:1:0: sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory compilation terminated. # 1 "clock.c" # 1 "" # 1 "" # 1 "clock.c" clock.c:55:28: fatal error: linux/spinlock.h: No such file or directory compilation terminated. # 1 "completion.c" # 1 "" # 1 "" # 1 "completion.c" # 14 "completion.c" # 1 "/usr/include/linux/sched.h" 1 3 4 # 15 "completion.c" 2 completion.c:15:30: fatal error: linux/completion.h: No such file or directory compilation terminated. # 1 "core.c" # 1 "" # 1 "" # 1 "core.c" core.c:29:25: fatal error: linux/kasan.h: No such file or directory compilation terminated. # 1 "cpuacct.c" # 1 "" # 1 "" # 1 "cpuacct.c" cpuacct.c:1:26: fatal error: linux/cgroup.h: No such file or directory compilation terminated. # 1 "cpudeadline.c" # 1 "" # 1 "" # 1 "cpudeadline.c" cpudeadline.c:14:23: fatal error: linux/gfp.h: No such file or directory compilation terminated. # 1 "cpufreq.c" # 1 "" # 1 "" # 1 "cpufreq.c" # 12 "cpufreq.c" # 1 "sched.h" 1 # 1 "/usr/include/linux/sched.h" 1 3 4 # 2 "sched.h" 2 In file included from cpufreq.c:12:0: sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory compilation terminated. # 1 "cpufreq_schedutil.c" # 1 "" # 1 "" # 1 "cpufreq_schedutil.c" cpufreq_schedutil.c:14:27: fatal error: linux/cpufreq.h: No such file or directory compilation terminated. # 1 "cpupri.c" # 1 "" # 1 "" # 1 "cpupri.c" cpupri.c:30:23: fatal error: linux/gfp.h: No such file or directory compilation terminated. # 1 "cputime.c" # 1 "" # 1 "" # 1 "cputime.c" cputime.c:1:26: fatal error: linux/export.h: No such file or directory compilation terminated. # 1 "deadline.c" # 1 "" # 1 "" # 1 "deadline.c" # 17 "deadline.c" # 1 "sched.h" 1 # 1 "/usr/include/linux/sched.h" 1 3 4 # 2 "sched.h" 2 In file included from deadline.c:17:0: sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory compilation terminated. # 1 "debug.c" # 1 "" # 1 "" # 1 "debug.c" debug.c:13:27: fatal error: linux/proc_fs.h: No such file or directory compilation terminated. # 1 "fair.c" # 1 "" # 1 "" # 1 "fair.c" # 23 "fair.c" # 1 "/usr/include/linux/sched.h" 1 3 4 # 24 "fair.c" 2 fair.c:24:30: fatal error: linux/latencytop.h: No such file or directory compilation terminated. # 1 "idle.c" # 1 "" # 1 "" # 1 "idle.c" # 1 "/usr/include/linux/sched.h" 1 3 4 # 5 "idle.c" 2 idle.c:5:23: fatal error: linux/cpu.h: No such file or directory compilation terminated. # 1 "idle_task.c" # 1 "" # 1 "" # 1 "idle_task.c" # 1 "sched.h" 1 # 1 "/usr/include/linux/sched.h" 1 3 4 # 2 "sched.h" 2 In file included from idle_task.c:1:0: sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory compilation terminated. # 1 "loadavg.c" # 1 "" # 1 "" # 1 "loadavg.c" loadavg.c:9:26: fatal error: linux/export.h: No such file or directory compilation terminated. # 1 "rt.c" # 1 "" # 1 "" # 1 "rt.c" # 1 "sched.h" 1 # 1 "/usr/include/linux/sched.h" 1 3 4 # 2 "sched.h" 2 In file included from rt.c:6:0: sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory compilation terminated. # 1 "stats.c" # 1 "" # 1 "" # 1 "stats.c" stats.c:1:24: fatal error: linux/slab.h: No such file or directory compilation terminated. # 1 "stop_task.c" # 1 "" # 1 "" # 1 "stop_task.c" # 1 "sched.h" 1 # 1 "/usr/include/linux/sched.h" 1 3 4 # 2 "sched.h" 2 In file included from stop_task.c:1:0: sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory compilation terminated. # 1 "swait.c" # 1 "" # 1 &q
Re: how to evaluate a ast tree and change Add to Multiply ?
i just expect to rewrite + become multiply by edit the example in the link provided but search no examples about this, feel unknown about args and keywords etc, do not know how to write this ast.Call(func=ast.Name(id='Add', ctx=ast.Load()), args=[node], keywords=[]) On Wednesday, October 12, 2016 at 5:53:42 PM UTC+8, meInvent bbird wrote: > i use example here > > http://greentreesnakes.readthedocs.io/en/latest/examples.html > > > > > On Wednesday, October 12, 2016 at 5:47:12 PM UTC+8, Chris Angelico wrote: > > On Wed, Oct 12, 2016 at 8:32 PM, meInvent bbird <jobmatt...@gmail.com> > > wrote: > > > class ChangeAddtoMultiply(ast.NodeTransformer): > > > """Wraps all integers in a call to Integer()""" > > > def visit_Num(self, node): > > > if isinstance(node.n, int): > > > return ast.Call(func=ast.Name(id='Add', ctx=ast.Load()), > > > args=[node], keywords=[]) > > > return node > > > > > > > > > > Your class name, docstring, and functionality are all different, and > > you have given no explanation of what you want us to do. I can't read > > minds quite that well. > > > > ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: how to evaluate a ast tree and change Add to Multiply ?
i use example here http://greentreesnakes.readthedocs.io/en/latest/examples.html On Wednesday, October 12, 2016 at 5:47:12 PM UTC+8, Chris Angelico wrote: > On Wed, Oct 12, 2016 at 8:32 PM, meInvent bbird <jobmatt...@gmail.com> wrote: > > class ChangeAddtoMultiply(ast.NodeTransformer): > > """Wraps all integers in a call to Integer()""" > > def visit_Num(self, node): > > if isinstance(node.n, int): > > return ast.Call(func=ast.Name(id='Add', ctx=ast.Load()), > > args=[node], keywords=[]) > > return node > > > > > > Your class name, docstring, and functionality are all different, and > you have given no explanation of what you want us to do. I can't read > minds quite that well. > > ChrisA -- https://mail.python.org/mailman/listinfo/python-list
how to faster to know which ast name or id we want to change?
how to faster to know which ast name or id we want to change? because i use ast.walk to print all nodes then i know the name + is Add if using cparser to parse linux kernel, it will be a very large -- https://mail.python.org/mailman/listinfo/python-list
how to evaluate a ast tree and change Add to Multiply ?
import sys import parser import ast from collections import deque class ChangeAddtoMultiply(ast.NodeTransformer): """Wraps all integers in a call to Integer()""" def visit_Num(self, node): if isinstance(node.n, int): return ast.Call(func=ast.Name(id='Add', ctx=ast.Load()), args=[node], keywords=[]) return node tree = ast.parse('2+5') for node in ast.walk(tree): print(str(node)) eval(tree) -- https://mail.python.org/mailman/listinfo/python-list
why solveset and dsolve do not have _fields for ast.walk?
Traceback (most recent call last): File "astgraphforsympy.py", line 86, in print get_func_calls(tree) File "astgraphforsympy.py", line 48, in get_func_calls for node in ast.walk(tree): File "C:\Python27\lib\ast.py", line 213, in walk todo.extend(iter_child_nodes(node)) File "C:\Python27\lib\ast.py", line 178, in iter_child_nodes for name, field in iter_fields(node): File "C:\Python27\lib\ast.py", line 166, in iter_fields for field in node._fields: AttributeError: Module instance has no attribute '_fields' -- https://mail.python.org/mailman/listinfo/python-list
Re: how to refactor nested for loop into smaller for loop assume each of them independent?
https://social.msdn.microsoft.com/Forums/vstudio/en-US/5f0a9a51-a256-4671-a5fc-e213949e7204/how-to-refactor-3-nested-for-loop-into-smaller-for-loop-assume-each-of-them-independent?forum=csharpgeneral since when i dsolve a differential ideal used near 5GB memory for one ideal , i feel that i need to use amazon instance, i do not know whether sympy use same amount of memory i prepared to split a for loop which for combination if use i < j and j < k so 84 Billion /2 = 42 Billions combinations each script for doing 100 combinations range, it generate around 4XX files if read the final file it generated, is for ii from 1925 to 2025 do for jj from 2040 to 2040 do for kk from 2040 to 2040 do it seems missed 2026 to 2040 this range in the final file i feel that my crafted algorithm is not full combinations I wrote a algorithm to split for loop to generate maplesoft code for limited memory Assume I convert this algorithm into Python script and use sympy to do dsolve How to distribute to hundreds of Amazon instance to run each smaller for loop i am not familiar with using Amazon, such as how to create hundreds of EC2 instances i guess use python script to ssh all remote instance run a python script with bash command which in python script On Monday, October 10, 2016 at 6:49:12 AM UTC+8, Chris Angelico wrote: > On Mon, Oct 10, 2016 at 9:40 AM, Marko Rauhamaawrote: > > Chris Angelico : > >> Yeah, if it's just for progress status. Of course, that does assume > >> that the run() function doesn't have anything particularly costly in > >> it. If it does, well, dis gonna take a while > > > > Dealing with multigigabyte data streams is not over the top nowadays. > > This is true, but ultimately, it all comes down to the run() function. > With no further posts since the drive-by at the beginning, we have > nothing solid to discuss this on. > > ChrisA -- https://mail.python.org/mailman/listinfo/python-list
how to refactor nested for loop into smaller for loop assume each of them independent?
how to refactor nested for loop into smaller for loop assume each of them independent? because memory is not enough for ii in range(1,2000): for jj in range(1,2000): for kk in range(1,2000): print run(ii,jj,kk) -- https://mail.python.org/mailman/listinfo/python-list
Re: 'str' object has no attribute 'intersection' and unhashable set
after change to frozenset , it seems can classify into 7 repeated group but, in real data this consecutive lines can be also a group but i can not find this, actually i do not understand how the function works is there any algorithm tutorials or books or external library that can have a better result for finding repeated lines as group in grouping application 1,[(1, 0, 1)] 1,[(1, 0, 1)] 1,[(1, 0, 1)] 1,[(1, 0, 1)] real data 1,[(1, 0, 1)] 1,[] 1,[(-1, 1, -2), (2, -1/2, 1)] 0,[(1, 0, 0)] 1,[(1, 0, 1)] 1,[] 1,[] 0,[{a: 0}, {b: -1/c, a: 0}, {c: 1, b: -1, a: 0}, {c: -1, b: 1, a: 0}] 0,[(1/2 + sqrt(5)/2, -sqrt(5)/2 + 1/2, -1/2 + sqrt(5)/2), (-sqrt(5)/2 + 1/2, 1/2 + sqrt(5)/2, -sqrt(5)/2 - 1/2)] 0,[(1, 0, 0)] 1,[(1, 0, 1)] 1,[(1, 0, 1)] 1,[(1, 0, 1)] 1,[(1, 0, 1)] 1,[] 1,[] 0,[(1/2 + sqrt(5)/2, -sqrt(5)/2 + 1/2, -1/2 + sqrt(5)/2), (-sqrt(5)/2 + 1/2, 1/2 + sqrt(5)/2, -sqrt(5)/2 - 1/2)] 0,[(1, 0, 0)] 1,[] 1,[(-1, 1, -2), (2, -1/2, 1)] 0,[(1, 0, 0)] 1,[(1, 0, 1)] 1,[(1, 0, 1)] 1,[] 1,[(-1, 1, -2), (2, -1/2, 1)] 0,[(-1, -1, 1), (1, 1, -1)] 1,[] 0,[(1/2 + sqrt(5)/2, -sqrt(5)/2 + 1/2, -1/2 + sqrt(5)/2), (-sqrt(5)/2 + 1/2, 1/2 + sqrt(5)/2, -sqrt(5)/2 - 1/2)] 0,[(-1, -1, 1), (1, 1, -1)] 1,[] 0,[(1/2 + sqrt(5)/2, -sqrt(5)/2 + 1/2, -1/2 + sqrt(5)/2), (-sqrt(5)/2 + 1/2, 1/2 + sqrt(5)/2, -sqrt(5)/2 - 1/2)] 0,[(-1, -1, 1), (1, 1, -1)] 1,[(-1, 1, -2), (2, -1/2, 1)] 0,[(-1, -1, 1), (1, 1, -1)] 1,[(-1, 1, -2), (2, -1/2, 1)] 0,[(1, 0, 0)] 1,[] 1,[(-1, 1, -2), (2, -1/2, 1)] 0,[(-1, -1, 1), (1, 1, -1)] 1,[] 0,[(1/2 + sqrt(5)/2, -sqrt(5)/2 + 1/2, -1/2 + sqrt(5)/2), (-sqrt(5)/2 + 1/2, 1/2 + sqrt(5)/2, -sqrt(5)/2 - 1/2)] 0,[(1, 0, 0)] 1,[(1, 0, 1)] 1,[] def consolidate(sets): # http://rosettacode.org/wiki/Set_consolidation#Python:_Iterative setlist = [s for s in sets if s] for i, s1 in enumerate(setlist): if s1: for s2 in setlist[i+1:]: intersection = s1.intersection(s2) if intersection: s2.update(s1) s1.clear() s1 = s2 return [s for s in setlist if s] def wrapper(seqs): consolidated = consolidate(map(set, seqs)) groupmap = {x: i for i,seq in enumerate(consolidated) for x in seq} output = {} for seq in seqs: target = output.setdefault(groupmap[seq[0]], []) target.append(seq) return list(output.values()) with open("testing1.txt", "r") as myfile: content = myfile.readlines() gr = [['']] for ii in range(0,500): try: gr = [[frozenset(content[ii].split())]] + gr except: print "error" + str(content[ii]) groups = wrapper(gr) for i, group in enumerate(wrapper(gr)): print('g{}:'.format(i), group) print("\n") On Wednesday, October 5, 2016 at 3:40:25 PM UTC+8, dieter wrote: > meInvent bbird <jobmatt...@gmail.com> writes: > ... not looking at the details ... > > "'str' object has not attribute 'intersection'": apparently, > something is really a string (an 'str') while you expect it to be a set. > > "unhashable set": maybe, you try to put a set into another set (or a dict; > or somewhere else where hashability is necessary). A "set" itself is > unhashable (like many mutable standard data types); you may consider to use > "frozenset" in those cases (of course, a "frozenset" is immutable, i.e. > cannot be changed after creation). -- https://mail.python.org/mailman/listinfo/python-list
Re: how to read linux kernel source with pycparser (Reposting On Python-List Prohibited)
yes, i searched in google between 2011 and 2012 descending for loop is faster than ascending for loop On Wednesday, October 5, 2016 at 9:48:41 AM UTC+8, Chris Angelico wrote: > On Wed, Oct 5, 2016 at 12:41 PM, meInvent bbird <jobmatt...@gmail.com> wrote: > > so far i do not know which bug i search for > > > > i would like to change style of for loop > > > > form ascending to descending style > > > > for(int i=0; i<3; ++i) > > > > to > > > > for(int i=3; i>=0; --i) > > > > or > > > > most crazy to change if else if else into mealy machine > > Are you aware that those loops are significantly different? > > ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: how to read linux kernel source with pycparser (Reposting On Python-List Prohibited)
On Wednesday, October 5, 2016 at 2:34:49 AM UTC+8, Lawrence D’Oliveiro wrote: > On Tuesday, October 4, 2016 at 10:38:14 PM UTC+13, meInvent bbird wrote: > > how to customize pycparser to search what we want such as bug > > What kind of bug do you want to search for? so far i do not know which bug i search for i would like to change style of for loop form ascending to descending style for(int i=0; i<3; ++i) to for(int i=3; i>=0; --i) or most crazy to change if else if else into mealy machine -- https://mail.python.org/mailman/listinfo/python-list
'str' object has no attribute 'intersection' and unhashable set
def consolidate(sets): # http://rosettacode.org/wiki/Set_consolidation#Python:_Iterative setlist = [s for s in sets if s] for i, s1 in enumerate(setlist): if s1: for s2 in setlist[i+1:]: intersection = s1.intersection(s2) if intersection: s2.update(s1) s1.clear() s1 = s2 return [s for s in setlist if s] def wrapper(seqs): consolidated = consolidate(map(set, seqs)) groupmap = {x: i for i,seq in enumerate(consolidated) for x in seq} output = {} for seq in seqs: target = output.setdefault(groupmap[seq[0]], []) target.append(seq) return list(output.values()) with open("testing1.txt", "r") as myfile: content = myfile.readlines() gr = [['']] for ii in range(0,500): try: gr = [[content[ii]]] + gr except: print "error" + str(content[ii]) #groups = wrapper(content) for i, group in enumerate(wrapper(gr)): print('g{}:'.format(i), group) print("\n") Traceback (most recent call last): File "", line 10, in File "", line 2, in wrapper File "", line 7, in consolidate AttributeError: 'str' object has no attribute 'intersection' >>> content[1] '1,[(-1, 1, -2), (2, -1/2, 1)]\n' >>> content[2] '0,[(1, 0, 0)]\n' >>> content[3] '1,[(1, 0, 1)]\n' >>> content[4] '1,[]\n' >>> content[5] '1,[]\n' then i try to edit to gr = [[set(content[ii])]] + gr it return unhashable type 'set' just would like to search all repeatable pattern for a group of lines -- https://mail.python.org/mailman/listinfo/python-list
how to read linux kernel source with pycparser
i expect to use pycparser to read linux kernel source and get a AST tree, but there are so many directory, how to read linux kernel source with pycparser? how to customize pycparser to search what we want such as bug or fix to make a linux patch for linux kernel source with python? -- https://mail.python.org/mailman/listinfo/python-list
Re: how to automate java application in window using python
Hi Matt Wheeler, can it contorl Maplesoft's maple which is a java executable file? On Sunday, September 18, 2016 at 5:02:15 PM UTC+8, Matt Wheeler wrote: > On Thu, 15 Sep 2016, 08:12 meInvent bbird, <jobmatt...@gmail.com> wrote: > > > how to automate java application in window using python > > > > 1. scroll up or down of scroll bar > > 2. click button > > 3. type text in textbox > > > > I would recommend having a look at pywinauto > https://github.com/pywinauto/pywinauto > > It presents a very nice pythonic interface to Windows and the controls > within them, allowing statements such as (copied from the Readme): > > app.UntitledNotepad.MenuSelect("Help->About Notepad") > app.AboutNotepad.OK.Click() > app.UntitledNotepad.Edit.TypeKeys ("pywinauto Works!", with_spaces = True) > > (I found it already quite stable when I first used it a couple of years > ago, and looking at the Readme now it's clearly still an active project, > the optional image capture feature using pillow is new) > > > -- https://mail.python.org/mailman/listinfo/python-list
Re: is it possible to adjust convex hull to draw blue line instead of green line?
On Saturday, September 17, 2016 at 2:31:59 PM UTC+8, meInvent bbird wrote: > On Saturday, September 17, 2016 at 9:35:35 AM UTC+8, Steve D'Aprano wrote: > > On Sat, 17 Sep 2016 10:20 am, meInvent bbird wrote: > > > > > i succeed to use code to draw green line, but green line not draw the > > > large area, expect second uploaded picture, the blue line connect > > > the bottom of red line graph > > > > > > Please don't waste our time with dead code that has been commented out or > > that doesn't do anything. > > > > Here is your code with the commented out dead code removed. You should do > > this, don't expect us to do it: > > > > > > im = img.copy() > > cntcounter = 0 > > for cnt in contours: > > print("approx=" + str(approx)) > > cntcounter = cntcounter + 1 > > print("here1") > > hull = cv2.convexHull(cnt,returnPoints = True) > > print("here2") > > while im is None: > > # WARNING: THIS IS AN INFINITE LOOP > > time.sleep(1) > > if im is not None: > > print("here3") > > previousx = 0 > > previousy = 0 > > for c in hull: > > if (previousx != 0 and previousy != 0 and c[0][0] != 0 > > and c[0][1] != 0 and abs(previousy - c[0][1]) > 10 > > and abs(c[0][0] - previousx) > 1 > > ): > > while im is None: > > # WARNING: THIS IS AN INFINITE LOOP > > time.sleep(1) > > cv2.line(im, (previousx, previousy), > > (c[0][0], c[0][1]), (0, 255, 0), 2) > > print("") > > previousx = c[0][0] > > previousy = c[0][1] > > > > > > > > > > Now it is much easier to read without the noise. > > > > Problems: > > > > (1) img is not defined; > > > > (2) approx is not defined; > > > > (3) contours is not defined; > > > > (4) cv2 is not defined; > > > > (5) you have TWO possible infinite loops in your code; > > > > (6) time is not defined, but this at least I can guess is the > > standard time module; > > > > (7) c is not defined. > > > > > > As given to us, we cannot run your code or understand it, because too many > > things are undefined. > > > > My **guess** is that cv2.line() will take an argument to set the line > > colour. You should read the documentation for cv2.line(). > > > > > > Before asking any more questions, please read this: > > > > http://sscce.org/ > > > > > > > > > > > > > > -- > > Steve > > “Cheer up,” they said, “things could be worse.” So I cheered up, and sure > > enough, things got worse. > > sorry for assuming all have experience in this kind of application > > here is my code > > https://gist.github.com/hoyeunglee/0165b24b10de0baf8538e8866e2dcd60 > > Please. this time, i try to run more times for contour and convex hull but not blue line expected diagram, is it possible to adjust the method to draw lines for the bottom of red line https://gist.github.com/hoyeunglee/9c97fdef1cc32fefde0a454a24a2c2c1 -- https://mail.python.org/mailman/listinfo/python-list
Re: is it possible to adjust convex hull to draw blue line instead of green line?
On Saturday, September 17, 2016 at 9:35:35 AM UTC+8, Steve D'Aprano wrote: > On Sat, 17 Sep 2016 10:20 am, meInvent bbird wrote: > > > i succeed to use code to draw green line, but green line not draw the > > large area, expect second uploaded picture, the blue line connect > > the bottom of red line graph > > > Please don't waste our time with dead code that has been commented out or > that doesn't do anything. > > Here is your code with the commented out dead code removed. You should do > this, don't expect us to do it: > > > im = img.copy() > cntcounter = 0 > for cnt in contours: > print("approx=" + str(approx)) > cntcounter = cntcounter + 1 > print("here1") > hull = cv2.convexHull(cnt,returnPoints = True) > print("here2") > while im is None: > # WARNING: THIS IS AN INFINITE LOOP > time.sleep(1) > if im is not None: > print("here3") > previousx = 0 > previousy = 0 > for c in hull: > if (previousx != 0 and previousy != 0 and c[0][0] != 0 > and c[0][1] != 0 and abs(previousy - c[0][1]) > 10 > and abs(c[0][0] - previousx) > 1 > ): > while im is None: > # WARNING: THIS IS AN INFINITE LOOP > time.sleep(1) > cv2.line(im, (previousx, previousy), > (c[0][0], c[0][1]), (0, 255, 0), 2) > print("") > previousx = c[0][0] > previousy = c[0][1] > > > > > Now it is much easier to read without the noise. > > Problems: > > (1) img is not defined; > > (2) approx is not defined; > > (3) contours is not defined; > > (4) cv2 is not defined; > > (5) you have TWO possible infinite loops in your code; > > (6) time is not defined, but this at least I can guess is the > standard time module; > > (7) c is not defined. > > > As given to us, we cannot run your code or understand it, because too many > things are undefined. > > My **guess** is that cv2.line() will take an argument to set the line > colour. You should read the documentation for cv2.line(). > > > Before asking any more questions, please read this: > > http://sscce.org/ > > > > > > > -- > Steve > “Cheer up,” they said, “things could be worse.” So I cheered up, and sure > enough, things got worse. sorry for assuming all have experience in this kind of application here is my code https://gist.github.com/hoyeunglee/0165b24b10de0baf8538e8866e2dcd60 Please. -- https://mail.python.org/mailman/listinfo/python-list
is it possible to adjust convex hull to draw blue line instead of green line?
i succeed to use code to draw green line, but green line not draw the large area, expect second uploaded picture, the blue line connect the bottom of red line graph im = img.copy() cntcounter = 0 for cnt in contours: #epsilon = 0.1*cv2.arcLength(cnt,True) #approx = cv2.approxPolyDP(cnt,epsilon,True) #peri = cv2.arcLength(cnt, True) #approx = cv2.approxPolyDP(cnt, 0.15 * peri, True) #print("len(approx)="+str(len(approx))) #if len(approx) == 2: print("approx=" + str(approx)) cntcounter = cntcounter + 1 print("here1") #x,y,w,h = cv2.boundingRect(cnt) hull = cv2.convexHull(cnt,returnPoints = True) print("here2") while im is None: time.sleep(1) if im is not None: print("here3") #cv2.rectangle(im, (x,y), (x+w, y+h), (0,255,0), 2) #cv2.imwrite("C:\\Users\\tester\\Documents\\masda"+str(cntcounter)+".png",imi) #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) previousx = 0 previousy = 0 for c in hull: if previousx != 0 and previousy != 0 and c[0][0] != 0 and c[0][1] != 0 and abs(previousy - c[0][1]) > 10 and abs(c[0][0] - previousx) > 1: while im is None: time.sleep(1) cv2.line(im,(previousx,previousy),(c[0][0],c[0][1]),(0,255,0),2) print("") #print("previousx=" + str(previousx)) #print("previousy=" + str(previousy)) #print("c[0][0]=" + str(c[0][0])) #print("c[0][1]=" + str(c[0][1])) previousx = c[0][0] previousy = c[0][1] https://drive.google.com/file/d/0Bxs_ao6uuBDUWVBFZzVIVGotRlk/view?usp=sharing expected is https://drive.google.com/file/d/0Bxs_ao6uuBDUNGZFS2F3WnJERzA/view?usp=sharing -- https://mail.python.org/mailman/listinfo/python-list
Re: why this code loop forever after a draw a rectangle
after succeed to draw lines in graph, however, https://drive.google.com/file/d/0Bxs_ao6uuBDUWVBFZzVIVGotRlk/view?usp=sharing expected the blue line connect the bottom of red line graph https://drive.google.com/file/d/0Bxs_ao6uuBDUNGZFS2F3WnJERzA/view?usp=sharing how can convex hull be adjusted to do like second graph of sky blue line On Saturday, September 17, 2016 at 7:48:46 AM UTC+8, meInvent bbird wrote: > img is the image > > im is a new memory of image using img.copy() > > > On Saturday, September 17, 2016 at 7:46:42 AM UTC+8, meInvent bbird wrote: > > thank you very much, > > it out of the loop now. > > because drawLine function return things > > > > i just change drawLine to rectangle, > > have not thought that rectangle not return thing, just edit the parameter > > > > > > > > On Saturday, September 17, 2016 at 5:26:53 AM UTC+8, MRAB wrote: > > > On 2016-09-16 20:14, Gary Herron wrote: > > > > On 09/16/2016 04:24 AM, meInvent bbird wrote: > > > >> im = img.copy() > > > >> cntcounter = 0 > > > >> for cnt in contours: > > > >> epsilon = 0.1*cv2.arcLength(cnt,True) > > > >> approx = cv2.approxPolyDP(cnt,epsilon,True) > > > >> #peri = cv2.arcLength(cnt, True) > > > >> #approx = cv2.approxPolyDP(c, 0.5 * peri, True) > > > >> #print("len(approx)="+str(len(approx))) > > > >> if len(approx) == 4: > > > >> print("approx=" + str(approx)) > > > >> cntcounter = cntcounter + 1 > > > >> print("here1") > > > >> x,y,w,h = cv2.boundingRect(cnt) > > > >> print("here2") > > > >> while im is None: > > > >> time.sleep(1) > > > >> if im is not None: > > > >> print("here3") > > > >> im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), > > > >> (0,255,0), 2) > > > >> #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) > > > >> #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) > > > >> #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) > > > >> #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) > > > >> > > > >> > > > >> cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im) > > > > > > > > > > > > These two lines: > > > > > > > >while im is None: > > > > time.sleep(1) > > > > > > > > are an infinite loop if im is None; > > > > > > > > > > > > Since you haven't told us what im (or img, contours, cv2) are, I can't > > > > tell how im might become None, but it does look like you (confusingly) > > > > use im for two different things: an img.copy() and a cv2.rectangle, > > > > whatever those may be. > > > > > > > > Pure guesswork: if cv2.rectangle draws a rectangle, what does it > > > > return? If it doesn't return anything, the line > > > > im = cv2.rectangle(...) > > > > is how im gets the value of None. > > > > > > > It looks like the OP is using OpenCV. > > > > > > You're right about cv2.rectangle; it does return None. > > > > > > The line: > > > > > > im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) > > > > > > makes a copy of the image im, draws a rectangle on it, and then binds > > > None to im. > > > > > > The copied rectangle is discarded because there's no reference to it, so > > > the entire line in pointless. > > > > > > It basically does the same thing as: > > > > > > im = None > > > > > > only slower! -- https://mail.python.org/mailman/listinfo/python-list
Re: why this code loop forever after a draw a rectangle
img is the image im is a new memory of image using img.copy() On Saturday, September 17, 2016 at 7:46:42 AM UTC+8, meInvent bbird wrote: > thank you very much, > it out of the loop now. > because drawLine function return things > > i just change drawLine to rectangle, > have not thought that rectangle not return thing, just edit the parameter > > > > On Saturday, September 17, 2016 at 5:26:53 AM UTC+8, MRAB wrote: > > On 2016-09-16 20:14, Gary Herron wrote: > > > On 09/16/2016 04:24 AM, meInvent bbird wrote: > > >> im = img.copy() > > >> cntcounter = 0 > > >> for cnt in contours: > > >> epsilon = 0.1*cv2.arcLength(cnt,True) > > >> approx = cv2.approxPolyDP(cnt,epsilon,True) > > >> #peri = cv2.arcLength(cnt, True) > > >> #approx = cv2.approxPolyDP(c, 0.5 * peri, True) > > >> #print("len(approx)="+str(len(approx))) > > >> if len(approx) == 4: > > >> print("approx=" + str(approx)) > > >> cntcounter = cntcounter + 1 > > >> print("here1") > > >> x,y,w,h = cv2.boundingRect(cnt) > > >> print("here2") > > >> while im is None: > > >> time.sleep(1) > > >> if im is not None: > > >> print("here3") > > >> im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), > > >> (0,255,0), 2) > > >> #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) > > >> #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) > > >> #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) > > >> #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) > > >> > > >> > > >> cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im) > > > > > > > > > These two lines: > > > > > >while im is None: > > > time.sleep(1) > > > > > > are an infinite loop if im is None; > > > > > > > > > Since you haven't told us what im (or img, contours, cv2) are, I can't > > > tell how im might become None, but it does look like you (confusingly) > > > use im for two different things: an img.copy() and a cv2.rectangle, > > > whatever those may be. > > > > > > Pure guesswork: if cv2.rectangle draws a rectangle, what does it > > > return? If it doesn't return anything, the line > > > im = cv2.rectangle(...) > > > is how im gets the value of None. > > > > > It looks like the OP is using OpenCV. > > > > You're right about cv2.rectangle; it does return None. > > > > The line: > > > > im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) > > > > makes a copy of the image im, draws a rectangle on it, and then binds > > None to im. > > > > The copied rectangle is discarded because there's no reference to it, so > > the entire line in pointless. > > > > It basically does the same thing as: > > > > im = None > > > > only slower! -- https://mail.python.org/mailman/listinfo/python-list
Re: why this code loop forever after a draw a rectangle
thank you very much, it out of the loop now. because drawLine function return things i just change drawLine to rectangle, have not thought that rectangle not return thing, just edit the parameter On Saturday, September 17, 2016 at 5:26:53 AM UTC+8, MRAB wrote: > On 2016-09-16 20:14, Gary Herron wrote: > > On 09/16/2016 04:24 AM, meInvent bbird wrote: > >> im = img.copy() > >> cntcounter = 0 > >> for cnt in contours: > >> epsilon = 0.1*cv2.arcLength(cnt,True) > >> approx = cv2.approxPolyDP(cnt,epsilon,True) > >> #peri = cv2.arcLength(cnt, True) > >> #approx = cv2.approxPolyDP(c, 0.5 * peri, True) > >> #print("len(approx)="+str(len(approx))) > >> if len(approx) == 4: > >> print("approx=" + str(approx)) > >> cntcounter = cntcounter + 1 > >> print("here1") > >> x,y,w,h = cv2.boundingRect(cnt) > >> print("here2") > >> while im is None: > >> time.sleep(1) > >> if im is not None: > >> print("here3") > >> im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), > >> (0,255,0), 2) > >> #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) > >> #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) > >> #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) > >> #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) > >> > >> > >> cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im) > > > > > > These two lines: > > > >while im is None: > > time.sleep(1) > > > > are an infinite loop if im is None; > > > > > > Since you haven't told us what im (or img, contours, cv2) are, I can't > > tell how im might become None, but it does look like you (confusingly) > > use im for two different things: an img.copy() and a cv2.rectangle, > > whatever those may be. > > > > Pure guesswork: if cv2.rectangle draws a rectangle, what does it > > return? If it doesn't return anything, the line > > im = cv2.rectangle(...) > > is how im gets the value of None. > > > It looks like the OP is using OpenCV. > > You're right about cv2.rectangle; it does return None. > > The line: > > im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) > > makes a copy of the image im, draws a rectangle on it, and then binds > None to im. > > The copied rectangle is discarded because there's no reference to it, so > the entire line in pointless. > > It basically does the same thing as: > > im = None > > only slower! -- https://mail.python.org/mailman/listinfo/python-list
Re: how to automate java application in window using python
you are right, english is not my first language i just talk as simple as i can, i do not know previous talking is mean On Friday, September 16, 2016 at 6:22:34 PM UTC+8, Christian Gollwitzer wrote: > Am 16.09.16 um 09:01 schrieb Lawrence D’Oliveiro: > > On Friday, September 16, 2016 at 6:55:07 PM UTC+12, meInvent bbird > > wrote: > >> On Thursday, September 15, 2016 at 3:52:41 PM UTC+8, Lawrence > >> D’Oliveiro wrote: > >>> On Thursday, September 15, 2016 at 7:13:05 PM UTC+12, meInvent > >>> bbird wrote: > >>>> how to automate java application in window using python > >>>> > >>>> 1. scroll up or down of scroll bar 2. click button 3. type text > >>>> in textbox > >>> > >>> Well, don’t leave us in suspense! Give us the link to your blog > >>> post! > >> > >> i do not have blog post, > > > > Oh, now you make us sad. I thought you were promoting a blog post > > where you tell us “how to automate java application in window using > > python” using just 3 steps! But it turns out you have nothing. You > > are an empty promiser. > > You are being mean. It is quite evident that English is not his first > language, and highly probable that this was actually the question "How > do I automate a Java application using Python?" > > I don't have a real answer myself, but maybe using Jython one can get > access to the Java objects underlying the application (and then, of > course, execute methods of the GUI objects). This depends on the GUI > toolkit (Swing/SWT) and knowledge of the applications' structure, of > course. Another (less robust) way of desktop automation is Sikuli > http://www.sikuli.org/ (Windows only, I think) > > Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: why this code loop forever after a draw a rectangle
i follow this post to give some time it to operate, wait a long time still looping http://answers.opencv.org/question/60094/libpng-warning-image-width-is-zero-in-ihdr/ i can not stand this Ninja coding life any more, i have to open my code for ask this error import cv2 import numpy as np #from matplotlib import pyplot as plt import time #print("1=" + str(int(sys.argv[1]))) #print("2=" + str(int(sys.argv[2]))) #print("3=" + str(int(sys.argv[3]))) img_rgb = cv2.imread(r'C:\Users\martin\Documents\scree2.png') img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) template = cv2.imread(r'C:\Users\martin\Documents\dragob.png',0) w, h = template.shape[::-1] res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED) threshold = 0.64 loc = np.where( res >= threshold) pt = [(0,0)] while not zip(*loc[::-1]): threshold = threshold - 0.02 loc = np.where( res >= threshold) counter = 1 print("threshold="+str(threshold)) for pt2 in zip(*loc[::-1]): cv2.rectangle(img_rgb, pt2, (pt2[0] + w, pt2[1] + h), (0,0,255), 2) pt = pt2 crop_img = img_rgb[pt[1]:(pt[1]+h), pt[0]:(pt[0]+w)] counter = counter + 1 cv2.imwrite("C:\\Users\\tester\\Documents\\res.png",crop_img) #import cv2 #winName = "Movement Indicator" #cv2.namedWindow(winName, cv2.WINDOW_NORMAL) img = cv2.imread(r'C:\Users\tester\Documents\res.png',1) gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) height, width = gray.shape edges = cv2.Canny(gray,height,width,apertureSize = 3) #edges = cv2.Canny(gray,30,200) #gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) #ret,thresh = cv2.threshold(edges.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE,0) ret,thresh = cv2.threshold(edges,250,150,0) contours,hierarchy = cv2.findContours(thresh, 1, 2) #contours = sorted(contours, key = cv2.contourArea, reverse = True)[:10] im = img.copy() cntcounter = 0 for cnt in contours: epsilon = 0.1*cv2.arcLength(cnt,True) approx = cv2.approxPolyDP(cnt,epsilon,True) #peri = cv2.arcLength(cnt, True) #approx = cv2.approxPolyDP(c, 0.5 * peri, True) #print("len(approx)="+str(len(approx))) if len(approx) == 4: print("approx=" + str(approx)) cntcounter = cntcounter + 1 print("here1") x,y,w,h = cv2.boundingRect(cnt) print("here2") #im = img.copy() while im is None: time.sleep(1) if im is not None: print("here3") im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) #cv2.imwrite("C:\\Users\\martin\\Documents\\masda"+str(cntcounter)+".png",imi) #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) On Friday, September 16, 2016 at 7:34:04 PM UTC+8, Waffle wrote: > On 16 September 2016 at 14:24, meInvent bbird <jobmatt...@gmail.com> wrote: > > im = img.copy() > > cntcounter = 0 > > for cnt in contours: > > epsilon = 0.1*cv2.arcLength(cnt,True) > > approx = cv2.approxPolyDP(cnt,epsilon,True) > > #peri = cv2.arcLength(cnt, True) > > #approx = cv2.approxPolyDP(c, 0.5 * peri, True) > > #print("len(approx)="+str(len(approx))) > > if len(approx) == 4: > > print("approx=" + str(approx)) > > cntcounter = cntcounter + 1 > > print("here1") > > x,y,w,h = cv2.boundingRect(cnt) > > print("here2") > > while im is None: > > time.sleep(1) > > if im is not None: > > print("here3") > > im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), > > 2) > > #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) > > #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) > > #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) > > #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) > > > > > > cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im) > > -- > > https://mail.python.org/mailman/listinfo/python-list > > not sure but.. this bit reads really suspicious: > > while im is None: > time.sleep(1) > > if im is ever None then how will it ever become not None? unless there > is some other thread at work i can't really see this happening. > and if there is some other thread at work then there is probably some > better solution than sleep() -- https://mail.python.org/mailman/listinfo/python-list
why this code loop forever after a draw a rectangle
im = img.copy() cntcounter = 0 for cnt in contours: epsilon = 0.1*cv2.arcLength(cnt,True) approx = cv2.approxPolyDP(cnt,epsilon,True) #peri = cv2.arcLength(cnt, True) #approx = cv2.approxPolyDP(c, 0.5 * peri, True) #print("len(approx)="+str(len(approx))) if len(approx) == 4: print("approx=" + str(approx)) cntcounter = cntcounter + 1 print("here1") x,y,w,h = cv2.boundingRect(cnt) print("here2") while im is None: time.sleep(1) if im is not None: print("here3") im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im) -- https://mail.python.org/mailman/listinfo/python-list
Re: how to automate java application in window using python
On Friday, September 16, 2016 at 2:26:47 AM UTC+8, bream...@gmail.com wrote: > On Thursday, September 15, 2016 at 8:13:05 AM UTC+1, meInvent bbird wrote: > > how to automate java application in window using python > > > > 1. scroll up or down of scroll bar > > 2. click button > > 3. type text in textbox > > Please read this http://www.catb.org/esr/faqs/smart-questions.html and then > this http://sscce.org/ and then rephrase your post. > > Kindest regards. > > Mark Lawrence. i find this, but it is not python, it is a product http://sqa.stackexchange.com/questions/18134/python-based-test-automation-tools-for-desktop-applications -- https://mail.python.org/mailman/listinfo/python-list
Re: how to automate java application in window using python
On Thursday, September 15, 2016 at 3:52:41 PM UTC+8, Lawrence D’Oliveiro wrote: > On Thursday, September 15, 2016 at 7:13:05 PM UTC+12, meInvent bbird wrote: > > how to automate java application in window using python > > > > 1. scroll up or down of scroll bar > > 2. click button > > 3. type text in textbox > > Well, don’t leave us in suspense! Give us the link to your blog post! i do not have blog post, search nothing about this in google, is it possible to automate java application with python? -- https://mail.python.org/mailman/listinfo/python-list
how to robot recognize basic geometric object in window or ubuntu window
i am doing a robot to automate window itself with python i give some basic png diagram such as square, circle, triangle and hope it recognize all kinds of square like things in window such as textbox of notepad etc how a robot recognize basic geometric object in window or ubuntu window i use cv2 template matching method and then draw black square or rectangle as a template however, it can recognize the size of template only and recognize not a square diagram from capture screen then i try a black ground and white line of square, it recognize a File in menu i feel that it need to try all kinds of color, and size in order to recognize similar object in screen capture diagram how do a robot recognize many color and size in seconds? -- https://mail.python.org/mailman/listinfo/python-list
how to automate java application in window using python
how to automate java application in window using python 1. scroll up or down of scroll bar 2. click button 3. type text in textbox -- https://mail.python.org/mailman/listinfo/python-list
unexpected rerun program itself when using cv2 and selenium
unexpected rerun program itself when using cv2 and selenium when a script, it is expected to run once and stop but it start a new browser again when using selenium and cv2 d, bbox, filename) File "C:\Python27\lib\site-packages\pyscreenshot\procutil.py", line 28, in run _in_childprocess p.start() File "C:\Python27\lib\multiprocessing\process.py", line 130, in start self._popen = Popen(self) File "C:\Python27\lib\multiprocessing\forking.py", line 258, in __init__ cmd = get_command_line() + [rhandle] File "C:\Python27\lib\multiprocessing\forking.py", line 358, in get_command_li ne is not going to be frozen to produce a Windows executable.''') RuntimeError: Attempt to start a new process before the current process has finished its bootstrapping phase. This probably means that you are on Windows and you have forgotten to use the proper idiom in the main module: if __name__ == '__main__': freeze_support() ... The "freeze_support()" line can be omitted if the program is not going to be frozen to produce a Windows executable. -- https://mail.python.org/mailman/listinfo/python-list
how to set paramiko to use ssh version 1?
how to set paramiko to use ssh version 1? -- https://mail.python.org/mailman/listinfo/python-list
Re: type lookuperror
On Friday, August 19, 2016 at 5:37:32 AM UTC+8, Lawrence D’Oliveiro wrote: > On Friday, August 19, 2016 at 3:10:26 AM UTC+12, Chris Angelico wrote: > > What the OP was looking for was "I want my program to be able to debug > > itself". That means the program has to be smart enough to figure out > > its own problems. > > Maybe it is, it just doesn’t agree with you on what those problems are. ;) a company which write siri in iphone, has already wrote a program which can write program itself after the program talks with users it seems possible, i find many default function when using dir(function) to see so i guess that these default functions in openstack have its existence reason which i guess for program itself. how to append a function or code in runtime in python? -- https://mail.python.org/mailman/listinfo/python-list
Re: type lookuperror
actually i would like to remove try except code in all function and i feel that try except code for a large block code can not show which function name , which line number error, if use try except for specified code block to show where it has error it will have many ugly try except code and need many human force to craft the code, i hope that code write once for program to program itself in future. actually this method i ask is not good enough since it will need to add many function wrapper. On Thursday, August 18, 2016 at 3:49:04 PM UTC+8, Chris Angelico wrote: > On Thu, Aug 18, 2016 at 5:44 PM, meInvent bbird <jobmatt...@gmail.com> wrote: > > if i use > > > > result = "" > > before try > > and return result at the end > > > > as return of function can be any type > > > > there will be type mismatch > > > > how to return the result of func ? > > If it raises an exception, it *does not have* a return value. That's > why I let the exception continue to bubble. But fundamentally, you > can't just carry on regardless. I recommend a complete rethink of what > you're trying to do here. > > ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: type lookuperror
if i use result = "" before try and return result at the end as return of function can be any type there will be type mismatch how to return the result of func ? On Thursday, August 18, 2016 at 3:18:31 PM UTC+8, Chris Angelico wrote: > On Thu, Aug 18, 2016 at 5:14 PM, Peter Otten <__pete...@web.de> wrote: > > meInvent bbird wrote: > > > >> when try keystone_client.tenants.get > >> got error, > >> > >> isn't this method for all kinds of function? > >> > >>>>> m = "4c9a0da00b904422a23341e35be7f8d7" > >>>>> ten = checkexception(keystone_client.tenants.get, > >>>>> tenant_id=checkexception(m.encode,encoding='ascii',errors='ignore')) > >> Unexpected error: > >> None > > > > That's because your and Chris' version of checkexception() have no explicit > > return statement and thus always return None. There doesn't seeem to be a > > tenant_id=None... > > Hmm. Yes, that's another bug I should have fixed as I was rewriting. > "return result" at the end. > > ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: type lookuperror
when try keystone_client.tenants.get got error, isn't this method for all kinds of function? >>> m = "4c9a0da00b904422a23341e35be7f8d7" >>> ten = checkexception(keystone_client.tenants.get, >>> tenant_id=checkexception(m.encode,encoding='ascii',errors='ignore')) Unexpected error: None On Thursday, August 18, 2016 at 10:22:43 AM UTC+8, Chris Angelico wrote: > On Thu, Aug 18, 2016 at 12:13 PM, meInvent bbird <jobmatt...@gmail.com> wrote: > > would like to check errors for every function i run, > > got error type lookuperror > > > > def checkexception(func, **kwargs): > > try: > > result = func(*tuple(value for _, value in kwargs.iteritems())) > > except: > > print "Unexpected error:", sys.exc_info()[0] > > try: > > print(func.__doc__) > > except: > > print("no doc error") > > > > I'm going to be brutally honest, and simply say that this is terrible > code. I'm not even going to _try_ to fix it. Instead, here's a > completely rewritten form: > > def checkexception(func, *args, **kwargs): > try: > result = func(*args, **kwargs) > except BaseException as e: > print("Exception raised: %s" % e) > try: print(func.__doc__) > except AttributeError: pass > raise # Let the exception keep happening. > > But really, there are even better ways to do this. Just let the > exception happen, and then use something like ipython to help you > analyze the traceback. > > ChrisA -- https://mail.python.org/mailman/listinfo/python-list
type lookuperror
would like to check errors for every function i run, got error type lookuperror def checkexception(func, **kwargs): try: result = func(*tuple(value for _, value in kwargs.iteritems())) except: print "Unexpected error:", sys.exc_info()[0] try: print(func.__doc__) except: print("no doc error") >>> mm =checkexception("".encode,encoding='ascii',errors='ignore') Unexpected error: S.encode([encoding[,errors]]) -> object Encodes S using the codec registered for encoding. encoding defaults to the default encoding. errors may be given to set a different error handling scheme. Default is 'strict' meaning that encoding errors raise a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and 'xmlcharrefreplace' as well as any other name registered with codecs.register_error that is able to handle UnicodeEncodeErrors. for p in val_list: for k, v in p.items(): if k == "tenant_id": print(v) m = v ten = checkexception(keystone_client.tenants.get, checkexception(m.encode,encoding='ascii',errors'ignore')) print(ten.name) -- https://mail.python.org/mailman/listinfo/python-list
how to python to use virtual memory?
after set resource hard and soft both out of real memory 70GB to 100GB and expecting the extra memory setting using virtual memory which is hard disk, the program still wrongly be killed itself after running in background side -- https://mail.python.org/mailman/listinfo/python-list
program return killed after run a very long time
i suspect it use so much memory, however i have already assign 30GB memory in openstack cloud is there any command to allow python to use more memory? currently program return killed after run a very long time -- https://mail.python.org/mailman/listinfo/python-list
Re: is there a concurrent list for append in parallel programming in python? how to pass parameter in this parallel program with pool?
how can list be synchronized when multiprocessor working in it? will one thread updating non-updated version, but another processor updating the version? On Thursday, June 16, 2016 at 4:30:33 PM UTC+8, Steven D'Aprano wrote: > On Thursday 16 June 2016 17:28, meInvent bbird wrote: > > > is there like c# have concurrent list ? > > What is a concurrent list? > > Can you link to the C# documentation for this? > > To me, "concurrent" describes a style of execution flow, and "list" describes > a > data structure. I am struggling to understand what "concurrent list" means. > > > i find something these, but how can it pass an initlist list variable > > initlist = ['a', 'b', 'c'] > result = comb(n, initlist) # pass initlist > > > > is it doing the same function as itertools.combinations ? > > It is calling itertools.combinations. So, yes, it is doing the same function > as > itertools.combinations. > > > > def comb(n, initlist): # the argument n is the number of items to select > > res = list(itertools.combinations(initlist, n)) # create a list from the > > # iterator > > return res > > This does not generate the combinations in parallel. It generates them one at > a > time, and then creates a list of them. > > This is an interesting question. Somebody could probably write a parallel > version of combinations. But I don't know that it would be very useful -- the > limiting factor on combinations is more likely to be memory, not time. > > Suppose you generate combinations of 100 items, taken 10 at a time. If I > remember the formula for combinations correctly, the total number of > combinations is: > > 100!/(10! * 90!) = 17310309456440 > > combinations in total. If each generated combination took just *one* byte of > memory, that would require over 17 TB of RAM. > > > > -- > Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: is there a concurrent list for append in parallel programming in python? how to pass parameter in this parallel program with pool?
the name in c# is not called concurrent list, it is called blockingcollection dictionary called concurrent dictionary thread safe these kind of things https://msdn.microsoft.com/en-us/library/dd267312(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/dd997369(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/dd997305(v=vs.110).aspx On Thursday, June 16, 2016 at 4:30:33 PM UTC+8, Steven D'Aprano wrote: > On Thursday 16 June 2016 17:28, meInvent bbird wrote: > > > is there like c# have concurrent list ? > > What is a concurrent list? > > Can you link to the C# documentation for this? > > To me, "concurrent" describes a style of execution flow, and "list" describes > a > data structure. I am struggling to understand what "concurrent list" means. > > > i find something these, but how can it pass an initlist list variable > > initlist = ['a', 'b', 'c'] > result = comb(n, initlist) # pass initlist > > > > is it doing the same function as itertools.combinations ? > > It is calling itertools.combinations. So, yes, it is doing the same function > as > itertools.combinations. > > > > def comb(n, initlist): # the argument n is the number of items to select > > res = list(itertools.combinations(initlist, n)) # create a list from the > > # iterator > > return res > > This does not generate the combinations in parallel. It generates them one at > a > time, and then creates a list of them. > > This is an interesting question. Somebody could probably write a parallel > version of combinations. But I don't know that it would be very useful -- the > limiting factor on combinations is more likely to be memory, not time. > > Suppose you generate combinations of 100 items, taken 10 at a time. If I > remember the formula for combinations correctly, the total number of > combinations is: > > 100!/(10! * 90!) = 17310309456440 > > combinations in total. If each generated combination took just *one* byte of > memory, that would require over 17 TB of RAM. > > > > -- > Steve -- https://mail.python.org/mailman/listinfo/python-list
is there a concurrent list for append in parallel programming in python? how to pass parameter in this parallel program with pool?
is there like c# have concurrent list ? i find something these, but how can it pass an initlist list variable is it doing the same function as itertools.combinations ? def comb(n, initlist): # the argument n is the number of items to select res = list(itertools.combinations(initlist, n)) # create a list from the iterator return res #p = Pool(8) #times = range(0, len(initlist)+1) #values = p.map(comb, times) # pass the range as the sequence of arguments! #p.close() #p.join() -- https://mail.python.org/mailman/listinfo/python-list
Re: how to for loop append a list [] when using parallel programming
is there like c# have concurrent list ? i find something these, but how can it pass an initlist list variable is it doing the same function as itertools.combinations ? def comb(n, initlist): # the argument n is the number of items to select res = list(itertools.combinations(initlist, n)) # create a list from the iterator return res #p = Pool(8) #times = range(0, len(initlist)+1) #values = p.map(comb, times) # pass the range as the sequence of arguments! #p.close() #p.join() On Thursday, June 16, 2016 at 11:17:47 AM UTC+8, John Gordon wrote: > In <fabcecae-04ae-433c-aad8-43993a21e...@googlegroups.com> meInvent bbird > <jobmatt...@gmail.com> writes: > > > how to for loop append a list [] when using parallel programming > > items = [] > for item in parallelized_object_factory(): > items.append(item) > > If you want a more specific answer, ask a more specific question. > > -- > John Gordon A is for Amy, who fell down the stairs > gor...@panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" -- https://mail.python.org/mailman/listinfo/python-list
how to for loop append a list [] when using parallel programming
how to for loop append a list [] when using parallel programming -- https://mail.python.org/mailman/listinfo/python-list
how to change itertools.combinations(initlist, 2) to parallel for running in multiprocessor environment?
how to change itertools.combinations(initlist, 2) to parallel for running in multiprocessor environment? -- https://mail.python.org/mailman/listinfo/python-list
how to search item in list of list
once a nested list have a word "node" then true else false def search(current_item): if isinstance(current_item, list): if len(current_item)==4: if [item for item in current_item if item[4] == "node"] != []: return True if True in [search(item) for item in current_item]: return True else: return False search(mresult) but it return false mresult = [[(2, {'11': 1, '10': 1, '00': 0, '01': 1}, ['000', '001', '010', '011', '100', '101', '110', '111'], 'xy', 'start')], [(2, {'11': 1, '10': 1, '00': 0, '01': 1} , ['000', '001', '010', '011', '100', '101', '110', '111'], 'yz', 'start')], [(2 , {'11': 1, '10': 1, '00': 0, '01': 1}, ['000', '001', '010', '011', '100', '101 ', '110', '111'], 'xz', 'start')], [(2, {'11': 1, '10': 0, '00': 0, '01': 0}, [' 000', '001', '010', '011', '100', '101', '110', '111'], 'xy', 'start')], [(2, {' 11': 1, '10': 0, '00': 0, '01': 0}, ['000', '001', '010', '011', '100', '101', ' 110', '111'], 'yz', 'start')], [(2, {'11': 1, '10': 0, '00': 0, '01': 0}, ['000' , '001', '010', '011', '100', '101', '110', '111'], 'xz', 'start')], [(2, {'11': 1, '10': 0, '00': 1, '01': 1}, ['000', '001', '010', '011', '100', '101', '110' , '111'], 'xy', 'start')], [(2, {'11': 1, '10': 0, '00': 1, '01': 1}, ['000', '0 01', '010', '011', '100', '101', '110', '111'], 'yz', 'start')], [(2, {'11': 1, '10': 0, '00': 1, '01': 1}, ['000', '001', '010', '011', '100', '101', '110', '1 11'], 'xz', 'start')], [(1, {'11': 1, '10': 1, '00': 0, '01': 1}, ['00', '01', ' 11', '11', '10', '11', '11', '11'], 'xy', 'node')], [(1, {'11': 1, '10': 1, '00' : 0, '01': 1}, ['00', '01', '10', '11', '11', '11', '11', '11'], 'xy', 'node')], [(1, {'11': 1, '10': 1, '00': 0, '01': 1}, ['00', '00', '10', '10', '10', '10', '11', '11'], 'xy', 'node')], [(1, {'11': 1, '10': 1, '00': 0, '01': 1}, ['00', '00', '10', '11', '10', '10', '10', '11'], 'xy', 'node')], [(1, {'11': 1, '10': 1, '00': 0, '01': 1}, ['00', '00', '10', '10', '10', '11', '10', '11'], 'xy', 'n ode')]] -- https://mail.python.org/mailman/listinfo/python-list
yatel install error
sudo apt-get install python-dev libatlas-base-dev gfortran pip install yatel Cleaning up... Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_martin/yatel/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-HwGsHy-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_martin/yatel Traceback (most recent call last): File "/usr/bin/pip", line 9, in load_entry_point('pip==1.5.4', 'console_scripts', 'pip')() File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 235, in main return command.main(cmd_args) File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 161, in main text = '\n'.join(complete_log) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 72: ordinal not in range(128) -- https://mail.python.org/mailman/listinfo/python-list
how to use yatel with redis?
my code is https://gist.github.com/hoyeunglee/58df4c41a63a2f37e153cbdbc03c16bf would like to apply itertools.combinations to use redis to use hard disk as memory rather than using ram(real memory) as memory def edge_gen(self): # we combine haplotypes by two for hap0, hap1 in itertools.combinations(self.haplotypes_cache.values(), 2): w = weight.weight("hamming", hap0, hap1) haps_id = hap0.hap_id, hap1.hap_id yield dom.Edge(w, haps_id) -- https://mail.python.org/mailman/listinfo/python-list
Re: how to record path in well format and easy to read?
i forget why i do combination of 2 operators now i change not to use combination of 2 operators https://gist.github.com/hoyeunglee/58df4c41a63a2f37e153cbdbc03c16bf i run mresult = DFS(b, 2, 2, mylist, path) it do not have deep 2 and deep 1 in the path they only separated in the list however, i had already assigned in this format path.append([caseA,path2]) before return path, what's wrong with it? On Sunday, June 12, 2016 at 12:55:17 PM UTC+8, meInvent bbird wrote: > https://gist.github.com/hoyeunglee/350ac2dd496f7c1c95a428f847e6f2b1 > > then can not run deep 3 in python sagecloud > > >>> mresult = DFS(b, 3, 3, mylist, path) > ('deep=', 3) > ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 0, '01': 0}) > ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 1, '01': 1}) > ({'11': 1, '10': 0, '00': 0, '01': 0}, {'11': 1, '10': 0, '00': 1, '01': 1}) > initlist= > 18 > path= > 18 > here is caseA > ('deep=', 2) > ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 0, '01': 0}) > ) > ... retu({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': > 1, '01': 1}) > ({'11': 1, '10': 0, '00': 0, '01': 0}, {'11': 1, '10': 0, '00': 1, '01': 1}) > initlist= > 790 > path= > 936 > ('deep=', 1) > ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 0, '01': 0}) > ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 1, '01': 1}) > ({'11': 1, '10': 0, '00': 0, '01': 0}, {'11': 1, '10': 0, '00': 1, '01': 1}) > initlist= > 1549682 > path= > 1870866 > Killed > > > On Sunday, June 12, 2016 at 9:38:51 AM UTC+8, meInvent bbird wrote: > > https://gist.github.com/hoyeunglee/3fea29ed4aadb5dbc11c41f9a36070dc > > > > i discover my code can not record the path > > > > because i do recursive call at the end of function > > however, i want to do full combination at the end of function before calling > > recursive call, > > > > for seeing the result path, choose call recursive call in each else > > statement > > which means when it is not found yet, it will continue recursive call > > > > this time, i use binary for simple case, > > > > but final result show only 4 records, first two do not have ok, > > > > third and fourth can not see ok, it become [...] > > > > how to show this [...] ? > > > > is there any method to record the path in well format and easy to read ? > > > > because in 3 valued case, i do not know name of operators, i can only > > record the full column -- https://mail.python.org/mailman/listinfo/python-list
Re: how to record path in well format and easy to read?
https://gist.github.com/hoyeunglee/350ac2dd496f7c1c95a428f847e6f2b1 then can not run deep 3 in python sagecloud >>> mresult = DFS(b, 3, 3, mylist, path) ('deep=', 3) ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 0, '01': 0}) ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 1, '01': 1}) ({'11': 1, '10': 0, '00': 0, '01': 0}, {'11': 1, '10': 0, '00': 1, '01': 1}) initlist= 18 path= 18 here is caseA ('deep=', 2) ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 0, '01': 0}) ) ... retu({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 1, '01': 1}) ({'11': 1, '10': 0, '00': 0, '01': 0}, {'11': 1, '10': 0, '00': 1, '01': 1}) initlist= 790 path= 936 ('deep=', 1) ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 0, '01': 0}) ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 1, '01': 1}) ({'11': 1, '10': 0, '00': 0, '01': 0}, {'11': 1, '10': 0, '00': 1, '01': 1}) initlist= 1549682 path= 1870866 Killed On Sunday, June 12, 2016 at 9:38:51 AM UTC+8, meInvent bbird wrote: > https://gist.github.com/hoyeunglee/3fea29ed4aadb5dbc11c41f9a36070dc > > i discover my code can not record the path > > because i do recursive call at the end of function > however, i want to do full combination at the end of function before calling > recursive call, > > for seeing the result path, choose call recursive call in each else statement > which means when it is not found yet, it will continue recursive call > > this time, i use binary for simple case, > > but final result show only 4 records, first two do not have ok, > > third and fourth can not see ok, it become [...] > > how to show this [...] ? > > is there any method to record the path in well format and easy to read ? > > because in 3 valued case, i do not know name of operators, i can only record > the full column -- https://mail.python.org/mailman/listinfo/python-list
how to record path in well format and easy to read?
https://gist.github.com/hoyeunglee/3fea29ed4aadb5dbc11c41f9a36070dc i discover my code can not record the path because i do recursive call at the end of function however, i want to do full combination at the end of function before calling recursive call, for seeing the result path, choose call recursive call in each else statement which means when it is not found yet, it will continue recursive call this time, i use binary for simple case, but final result show only 4 records, first two do not have ok, third and fourth can not see ok, it become [...] how to show this [...] ? is there any method to record the path in well format and easy to read ? because in 3 valued case, i do not know name of operators, i can only record the full column -- https://mail.python.org/mailman/listinfo/python-list
Re: which library has map reduce and how to use it for this case
there are six operator, and a logic table initial in b variable aa[b[j][i]] [aa[b[i][0:1]+b[i][2:3] are just like vlookup to find output of each operator acting on first column and second column, second column and third column , first column and third column and searching a output columns which is result sum is 27*2 and record the path if succeed, it record the path and output any path which has result is 27*2 described before op1(op2(op3(op1(op2(),),op1(op2(),))), op1(op2(),)) there are two cases, first cases b are logic table later case are for six operators acting on the result column from previous result before recursive call def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, b, "xy")]) else: initlist.append(op1xy) if sum(op1yz) == 54: path.append([(deep, aa, b, "yz")]) else: initlist.append(op1yz) if sum(op1xz) == 54: path.append([(deep, aa, b, "xz")]) else: initlist.append(op1xz) if sum(op2xy) == 54: path.append([(deep, bb, b, "xy")]) else: initlist.append(op2xy) if sum(op2yz) == 54: path.append([(deep, bb, b, "yz")]) else: initlist.append(op2yz) if sum(op2xz) == 54: path.append([(deep, bb, b, "xz")]) else: initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, b[j], "xy")]) else: initlist.append(op1xy) if sum(op2xy) == 54: path.append([(deep, bb, b[j], "xy")]) else: initlist.append(op2xy) level.extend([op1xy, op2xy]) if deep == maxx: b = [] print("initlist=") print(len(initlist)) for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) if deep > 0: path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) return path path = [] mresult = DFS(b, 2, 2, mylist, path) On Friday, June 10, 2016 at 10:04:09 PM UTC+8, Michael Selik wrote: > On Thu, Jun 9, 2016, 9:11 PM Ho Yeung Leewrote: > > > input are these six operators, output is finding full column of 27 > > elements add together is 54 > > > > i got memory error when searching this, > > > > i have difficulty in understanding map reduce and transforming my program > > into map reduce problem > > > > Why do you think you need map-reduce? > > You'll need to explain the problem in more detail. Instead of talking about > operators and columns, what is the actual, real-world problem? > > > -- https://mail.python.org/mailman/listinfo/python-list
Re: how to solve memory
i use sage cloud to run, it killed my program i checked total memory is large, how much memory it need, 8GB*10, 80GB? top - 05:55:16 up 10:05, 1 user, load average: 0.35, 0.63, 0.56 Tasks: 13 total, 1 running, 12 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.5 us, 0.4 sy, 0.0 ni, 99.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem: 26755056 total, 6317696 used, 20437360 free, 611836 buffers KiB Swap: 67108860 total, 468688 used, 66640172 free. 1223512 cached Mem def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, b, "xy")]) else: initlist.append(op1xy) if sum(op1yz) == 54: path.append([(deep, aa, b, "yz")]) else: initlist.append(op1yz) if sum(op1xz) == 54: path.append([(deep, aa, b, "xz")]) else: initlist.append(op1xz) if sum(op2xy) == 54: path.append([(deep, bb, b, "xy")]) else: initlist.append(op2xy) if sum(op2yz) == 54: path.append([(deep, bb, b, "yz")]) else: initlist.append(op2yz) if sum(op2xz) == 54: path.append([(deep, bb, b, "xz")]) else: initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, b[j], "xy")]) else: initlist.append(op1xy) if sum(op2xy) == 54: path.append([(deep, bb, b[j], "xy")]) else: initlist.append(op2xy) level.extend([op1xy, op2xy]) if deep == maxx: b = [] print("initlist=") print(len(initlist)) for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) if deep > 0: path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) return path path = [] mresult = DFS(b, 2, 2, mylist, path) On Saturday, June 11, 2016 at 8:34:16 AM UTC+8, MRAB wrote: > On 2016-06-11 00:31, meInvent bbird wrote: > > it is quite ridiculous, > > this time i am sure that i put correct indentation > > and add a else statement to make sure recursive call inside the > > if statement , it still memory error, > > > > where is the memory error? > > > > is itertools.combinations so big for the list? > > > [snip] > > How long is initlist? > > When I ran the code, it said over 100_000 items. > > How many combinations would there be? > > Over 10_000_000_000. > > That's how long the list 'b' would be. > > You'll need 10s of gigabytes of memory and a lot of patience! -- https://mail.python.org/mailman/listinfo/python-list
Re: how to solve memory
i use a version having better indentation, and then remove redundant which if sum column == 54 , do not add this column into initlist and add deep > 0 before recursive call and print number of initlist is 118,XXX but it is still running, where it run , and why run a very long time def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) else: initlist.append(op1xy) if sum(op1yz) == 54: path.append([(deep, aa, "yz")]) else: initlist.append(op1yz) if sum(op1xz) == 54: path.append([(deep, aa, "xz")]) else: initlist.append(op1xz) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) else: initlist.append(op2xy) if sum(op2yz) == 54: path.append([(deep, bb, "yz")]) else: initlist.append(op2yz) if sum(op2xz) == 54: path.append([(deep, bb, "xz")]) else: initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) else: initlist.append(op1xy) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) else: initlist.append(op2xy) level.extend([op1xy, op2xy]) if deep == maxx: b = [] print("initlist=") print(len(initlist)) for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) if deep > 0: path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) return path path = [] mresult = DFS(b, 2, 2, mylist, path) On Saturday, June 11, 2016 at 8:34:16 AM UTC+8, MRAB wrote: > On 2016-06-11 00:31, meInvent bbird wrote: > > it is quite ridiculous, > > this time i am sure that i put correct indentation > > and add a else statement to make sure recursive call inside the > > if statement , it still memory error, > > > > where is the memory error? > > > > is itertools.combinations so big for the list? > > > [snip] > > How long is initlist? > > When I ran the code, it said over 100_000 items. > > How many combinations would there be? > > Over 10_000_000_000. > > That's how long the list 'b' would be. > > You'll need 10s of gigabytes of memory and a lot of patience! -- https://mail.python.org/mailman/listinfo/python-list
Re: how to solve memory
this time i remove redundant which not add full column sum already has beeb 27*2 but it always has syntax error, indentation error, where is wrong? def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, b, "xy")]) else: initlist.append(op1xy) if sum(op1yz) == 54: path.append([(deep, aa, b, "yz")]) else: initlist.append(op1yz) if sum(op1xz) == 54: path.append([(deep, aa, b, "xz")]) else: initlist.append(op1xz) if sum(op2xy) == 54: path.append([(deep, bb, b, "xy")]) else: initlist.append(op2xy) if sum(op2yz) == 54: path.append([(deep, bb, b, "yz")]) else: initlist.append(op2yz) if sum(op2xz) == 54: path.append([(deep, bb, b, "xz")]) else: initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, b[j], "xy")]) else: initlist.append(op1xy) if sum(op2xy) == 54: path.append([(deep, bb, b[j], "xy")]) else: initlist.append(op2xy) level.append(op1xy) level.append(op2xy) print("initlist=") print(len(initlist) if deep == maxx: if deep > 0: b = [] for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) else: print("") print("path=") print(len(path)) else: if deep > 0: for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) else: print("") print("path=") print(len(path)) return path On Saturday, June 11, 2016 at 8:34:16 AM UTC+8, MRAB wrote: > On 2016-06-11 00:31, meInvent bbird wrote: > > it is quite ridiculous, > > this time i am sure that i put correct indentation > > and add a else statement to make sure recursive call inside the > > if statement , it still memory error, > > > > where is the memory error? > > > > is itertools.combinations so big for the list? > > > [snip] > > How long is initlist? > > When I ran the code, it said over 100_000 items. > > How many combinations would there be? > > Over 10_000_000_000. > > That's how long the list 'b' would be. > > You'll need 10s of gigabytes of memory and a lot of patience! -- https://mail.python.org/mailman/listinfo/python-list
Re: how to solve memory
it is quite ridiculous, this time i am sure that i put correct indentation and add a else statement to make sure recursive call inside the if statement , it still memory error, where is the memory error? is itertools.combinations so big for the list? if deep == maxx: if deep > 0: b = [] for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) else: print "" else: if deep > 0: for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) else: print "" return path On Saturday, June 11, 2016 at 12:26:55 AM UTC+8, John Gordon wrote: > In <8a1c372e-bd6c-4923-8ae1-8f129ec74...@googlegroups.com> meInvent bbird > <jobmatt...@gmail.com> writes: > > > > I already responded to your earlier post about this program. Did you > > > read it? > > > sorry i missed your reply post, > > i find post by me and search your name, no this name > > is your name changed in previous post? > > My comment was that the recursive calls weren't indented in the > "if deep > 0" block, therefore DFS was being called infinitely with smaller > and smaller values of deep. But it appears you have fixed that issue. > > -- > John Gordon A is for Amy, who fell down the stairs > gor...@panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" -- https://mail.python.org/mailman/listinfo/python-list
Re: how to solve memory
i put final part of code inside one more space and add constraint deep > 0 but still memory error and print the deep number to see, it do not run infinity again V6 is just my superstitution, because V is disable 6 is separation i run your version directly, it has key = '0' error M1 = {} M2 = {} M3 = {} M4 = {} M5 = {} V6 = {} M1['00']=0 M1['01']=1 M1['02']=1 M1['10']=2 M1['11']=2 M1['12']=1 M1['20']=1 M1['21']=1 M1['22']=1 M2['00']=0 M2['01']=1 M2['02']=1 M2['10']=1 M2['11']=2 M2['12']=2 M2['20']=1 M2['21']=1 M2['22']=1 M3['00']=0 M3['01']=1 M3['02']=1 M3['10']=0 M3['11']=1 M3['12']=2 M3['20']=0 M3['21']=2 M3['22']=2 M4['00']=0 M4['01']=1 M4['02']=0 M4['10']=1 M4['11']=2 M4['12']=2 M4['20']=0 M4['21']=1 M4['22']=1 M5['00']=0 M5['01']=1 M5['02']=1 M5['10']=2 M5['11']=1 M5['12']=2 M5['20']=0 M5['21']=2 M5['22']=1 V6['00']=1 V6['01']=1 V6['02']=2 V6['10']=1 V6['11']=1 V6['12']=1 V6['20']=2 V6['21']=2 V6['22']=2 MM = {} MM[0] = M1 MM[1] = M2 MM[2] = M3 MM[3] = M4 MM[4] = M5 MM[5] = V6 m = 3 b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] import itertools deep = 3 final = [] mylist = [MM[i] for i in range(0,7-1)] b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op1yz) == 54: path.append([(deep, aa, "yz")]) if sum(op1xz) == 54: path.append([(deep, aa, "xz")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) if sum(op2yz) == 54: path.append([(deep, bb, "yz")]) if sum(op2xz) == 54: path.append([(deep, bb, "xz")]) initlist.append(op1xy) initlist.append(op1yz) initlist.append(op1xz) initlist.append(op2xy) initlist.append(op2yz) initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) level.append(op1xy) level.append(op2xy) initlist.append(op1xy) initlist.append(op2xy) if deep == maxx: if deep > 0: b = [] for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) else: if deep > 0: for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) return path path = [] mresult = DFS(b, 2, 2, mylist, path) On Friday, June 10, 2016 at 10:08:44 PM UTC+8, Steven D'Aprano wrote: > On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote: > > [snip unreadable code] > > I just ran your code, and it almost crashed my computer. I think it is quite > rude to post code without an explanation of what the problem is. > > > I'm afraid that your code is virtually unreadable to me. It is too verbose, > the indentation is awful (single space indents is impossible for me to > track by eye) and it makes too much work out of simple operations. And none > of the variable names mean anything. > > I've started to simplify and clean the code, and got to the following, which > I hope you will agree is easier to read and more compact: > > > > import itertools > M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1, > '12': 1, '20': 1, '21': 1, '22': 2} > M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1, > '12': 1, '20': 1, '21': 1, '22': 1} > M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2, > '12': 1, '20': 0, '21': 1, '22': 2} > M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2, > '12': 2, '20': 0, '21': 1, '22': 2} > M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2, > '12': 1, '20': 0, '21': 1, '22': 1} > # Why V instead of M? > V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2, > '12': 1, '20': 1, '21': 2, '22': 2} > > MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6} &
Re: how to solve memory
On Friday, June 10, 2016 at 10:08:44 PM UTC+8, Steven D'Aprano wrote: > On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote: > > [snip unreadable code] > > I just ran your code, and it almost crashed my computer. I think it is quite > rude to post code without an explanation of what the problem is. > > > I'm afraid that your code is virtually unreadable to me. It is too verbose, > the indentation is awful (single space indents is impossible for me to > track by eye) and it makes too much work out of simple operations. And none > of the variable names mean anything. > > I've started to simplify and clean the code, and got to the following, which > I hope you will agree is easier to read and more compact: > > > > import itertools > M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1, > '12': 1, '20': 1, '21': 1, '22': 2} > M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1, > '12': 1, '20': 1, '21': 1, '22': 1} > M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2, > '12': 1, '20': 0, '21': 1, '22': 2} > M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2, > '12': 2, '20': 0, '21': 1, '22': 2} > M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2, > '12': 1, '20': 0, '21': 1, '22': 1} > # Why V instead of M? > V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2, > '12': 1, '20': 1, '21': 2, '22': 2} > > MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6} > m = 3 > b = [str(i)+str(j)+str(k) for i in range(m) > for j in range(m) for k in range(m)] > mylist = [MM[i] for i in range(6)] > > def DFS(b, deep, maxx, sourceoperators, path): > initlist = [] > if deep > 0: > print("deep=", deep) > for aa,bb in itertools.combinations(sourceoperators, 2): > print(aa,bb) > if deep == maxx: > finalresult = [] > op1xy = [aa[b[i][0:1]] for i in range(len(b))] > op1yz = [aa[b[i][1:2]] for i in range(len(b))] > op1xz = [aa[b[i][0]+b[i][2]] for i in range(len(b))] > op2xy = [bb[b[i][0:1]] for i in range(len(b))] > op2yz = [bb[b[i][1:2]] for i in range(len(b))] > op2xz = [bb[b[i][0]+b[i][2]] for i in range(len(b))] > if sum(op1xy) == 54: > path.append([(deep, aa, "xy")]) > if sum(op1yz) == 54: > path.append([(deep, aa, "yz")]) > if sum(op1xz) == 54: > path.append([(deep, aa, "xz")]) > if sum(op2xy) == 54: > path.append([(deep, bb, "xy")]) > if sum(op2yz) == 54: > path.append([(deep, bb, "yz")]) > if sum(op2xz) == 54: > path.append([(deep, bb, "xz")]) > initlist.extend([op1xy, op1yz, op1xz, op2xy, op2yz, op2xz]) > else: > level = [] > for j in range(len(b)): > op1xy = [aa[b[j][i]] for i in range(len(b[j]))] > op2xy = [bb[b[j][i]] for i in range(len(b[j]))] > if sum(op1xy) == 54: > path.append([(deep, aa, "xy")]) > if sum(op2xy) == 54: > path.append([(deep, bb, "xy")]) > level.extend([op1xy, op2xy]) > initlist.extend([op1xy, op2xy]) > if deep == maxx: > b = [] > for aaa,bbb in itertools.combinations(initlist, 2): > b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) > path = DFS(b, deep-1, maxx, sourceoperators, path) > return path > > path = [] > mresult = DFS(b, 2, 2, mylist, path) > > > > Unfortunate, in cleaning up your code, I have changed something, because my > version and your version do not do the same thing. > > After nearly crashing my computer running your version, I am not going to > spend the time trying to debug this. If you want our help, I suggest that > you clean up the code. Currently it is an incomprehensible mess to me. Even > after the cleanup, I have no idea what this piece of code is supposed to do > or what it is calculating. > > Can you explain the purpose of the code? What is it calculating? Can you > show the expected results? What does "DFS" mean? Why do you have M1 - M5 > but then a mysterious V6? > > I can see you are calculating *something* to do with permutations of 0 1 2, > but I don't understand what. > > I think I can see one problem: DFS is a recursive function, but it never > ends the recursion. It ALW
Re: how to solve memory
On Friday, June 10, 2016 at 10:46:43 PM UTC+8, John Gordon wrote: > In <4f853aa2-cc00-480b-9fd7-79b05cbd4...@googlegroups.com> meInvent bbird > <jobmatt...@gmail.com> writes: > > > https://drive.google.com/file/d/0Bxs_ao6uuBDULVNsRjZSVjdPYlE/view?usp=sharing > > I already responded to your earlier post about this program. Did you > read it? > > -- > John Gordon A is for Amy, who fell down the stairs > gor...@panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" sorry i missed your reply post, i find post by me and search your name, no this name is your name changed in previous post? could you post the link here? is it an email or google group post? -- https://mail.python.org/mailman/listinfo/python-list
Re: how to solve memory
i put final part of code inside one more space and add constraint deep > 0 but still memory error and print the deep number to see, it do not run infinity again V6 is just my superstitution, because V is disable 6 is separation i run your version directly, it has key = '0' error M1 = {} M2 = {} M3 = {} M4 = {} M5 = {} V6 = {} M1['00']=0 M1['01']=1 M1['02']=2 M1['10']=1 M1['11']=1 M1['12']=2 M1['20']=2 M1['21']=2 M1['22']=2 M2['00']=0 M2['01']=0 M2['02']=2 M2['10']=0 M2['11']=1 M2['12']=2 M2['20']=2 M2['21']=2 M2['22']=2 M3['00']=0 M3['01']=0 M3['02']=0 M3['10']=0 M3['11']=1 M3['12']=2 M3['20']=0 M3['21']=2 M3['22']=2 M4['00']=0 M4['01']=1 M4['02']=0 M4['10']=1 M4['11']=1 M4['12']=1 M4['20']=0 M4['21']=1 M4['22']=2 M5['00']=0 M5['01']=0 M5['02']=0 M5['10']=0 M5['11']=1 M5['12']=2 M5['20']=0 M5['21']=2 M5['22']=2 V6['00']=2 V6['01']=2 V6['02']=2 V6['10']=1 V6['11']=2 V6['12']=2 V6['20']=0 V6['21']=1 V6['22']=2 MM = {} MM[0] = M1 MM[1] = M2 MM[2] = M3 MM[3] = M4 MM[4] = M5 MM[5] = V6 m = 3 b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] import itertools deep = 3 final = [] mylist = [MM[i] for i in range(0,7-1)] b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op1yz) == 54: path.append([(deep, aa, "yz")]) if sum(op1xz) == 54: path.append([(deep, aa, "xz")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) if sum(op2yz) == 54: path.append([(deep, bb, "yz")]) if sum(op2xz) == 54: path.append([(deep, bb, "xz")]) initlist.append(op1xy) initlist.append(op1yz) initlist.append(op1xz) initlist.append(op2xy) initlist.append(op2yz) initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) level.append(op1xy) level.append(op2xy) initlist.append(op1xy) initlist.append(op2xy) if deep == maxx: if deep > 0: b = [] for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path = DFS(b, deep-1, maxx, sourceoperators, path) else: if deep > 0: for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path = DFS(b, deep-1, maxx, sourceoperators, path) return path path = [] mresult = DFS(b, 2, 2, mylist, path) On Friday, June 10, 2016 at 10:08:44 PM UTC+8, Steven D'Aprano wrote: > On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote: > > [snip unreadable code] > > I just ran your code, and it almost crashed my computer. I think it is quite > rude to post code without an explanation of what the problem is. > > > I'm afraid that your code is virtually unreadable to me. It is too verbose, > the indentation is awful (single space indents is impossible for me to > track by eye) and it makes too much work out of simple operations. And none > of the variable names mean anything. > > I've started to simplify and clean the code, and got to the following, which > I hope you will agree is easier to read and more compact: > > > > import itertools > M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1, > '12': 1, '20': 1, '21': 1, '22': 2} > M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1, > '12': 1, '20': 1, '21': 1, '22': 1} > M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2, > '12': 1, '20': 0, '21': 1, '22': 2} > M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2, > '12': 2, '20': 0, '21': 1, '22': 2} > M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2, > '12': 1, '20': 0, '21': 1, '22': 1} > # Why V instead of M? > V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2, > '12': 1, '20': 1, '21': 2, '22': 2} > > MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6} > m = 3 > b = [str(i)+str(j)+str(k) for i in ra
Re: run code error with numpy and scipy
On Thursday, June 9, 2016 at 9:52:43 PM UTC+8, MRAB wrote: > On 2016-06-09 07:02, meInvent bbird wrote: > > when i run code in window has an error not a valid win32 dll > > > > then i install scipy first in this site, then install numpy-mkl > > all python 2.7 and win32 > > > > http://www.lfd.uci.edu/~gohlke/pythonlibs/ > > > > then i run code below, got error , and captured screen in this link > > > > https://drive.google.com/file/d/0Bxs_ao6uuBDUQXROd2VqSURGa00/view?usp=sharing > > > [snip] > You're entering it at the interactive Python prompt. > > When it sees the blank line, it thinks you've finished entering the > function, so it complains when the next line is indented. (Things are > slightly different when working interactively than when running from a > file.) > > You should put the code into a file and then run that. thank you i will try it. -- https://mail.python.org/mailman/listinfo/python-list
Re: how to solve memory
On Friday, June 10, 2016 at 9:13:13 AM UTC+8, Michael Torrie wrote: > On 06/09/2016 06:58 PM, meInvent bbird wrote: > > > > Do you have a question for the list? If so, please state what it is, and > describe what you are doing and what isn't working. If you can boil it > down to a dozen lines of run-able, self-contained code that illustrates > the problem, that is helpful too. there are six operator, and a logic table initial in b variable aa[b[j][i]] [aa[b[i][0:1]+b[i][2:3] are just like vlookup to find output of each operator acting on first column and second column, second column and third column , first column and third column and searching a output columns which is result sum is 27*2 and record the path if succeed, it record the path and output any path which has result is 27*2 described before op1(op2(op3(op1(op2(),),op1(op2(),))), op1(op2(),)) there are two cases, first cases b are logic table later case are for six operators acting on the result column from previous result before recursive call -- https://mail.python.org/mailman/listinfo/python-list
how to solve memory
https://drive.google.com/file/d/0Bxs_ao6uuBDULVNsRjZSVjdPYlE/view?usp=sharing M1 = {} M2 = {} M3 = {} M4 = {} M5 = {} V6 = {} M1['00']=0 M1['01']=2 M1['02']=1 M1['10']=1 M1['11']=1 M1['12']=1 M1['20']=1 M1['21']=1 M1['22']=2 M2['00']=0 M2['01']=1 M2['02']=1 M2['10']=1 M2['11']=1 M2['12']=1 M2['20']=1 M2['21']=1 M2['22']=1 M3['00']=2 M3['01']=2 M3['02']=2 M3['10']=0 M3['11']=2 M3['12']=1 M3['20']=0 M3['21']=1 M3['22']=2 M4['00']=1 M4['01']=2 M4['02']=1 M4['10']=2 M4['11']=2 M4['12']=2 M4['20']=0 M4['21']=1 M4['22']=2 M5['00']=0 M5['01']=1 M5['02']=1 M5['10']=0 M5['11']=2 M5['12']=1 M5['20']=0 M5['21']=1 M5['22']=1 V6['00']=1 V6['01']=1 V6['02']=2 V6['10']=1 V6['11']=2 V6['12']=1 V6['20']=1 V6['21']=2 V6['22']=2 MM = {} MM[0] = M1 MM[1] = M2 MM[2] = M3 MM[3] = M4 MM[4] = M5 MM[5] = V6 m = 3 b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] import itertools deep = 3 final = [] mylist = [MM[i] for i in range(0,7-1)] b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op1yz) == 54: path.append([(deep, aa, "yz")]) if sum(op1xz) == 54: path.append([(deep, aa, "xz")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) if sum(op2yz) == 54: path.append([(deep, bb, "yz")]) if sum(op2xz) == 54: path.append([(deep, bb, "xz")]) initlist.append(op1xy) initlist.append(op1yz) initlist.append(op1xz) initlist.append(op2xy) initlist.append(op2yz) initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) level.append(op1xy) level.append(op2xy) initlist.append(op1xy) initlist.append(op2xy) if deep == maxx: b = [] #print(len(list(itertools.combinations(initlist, 2 for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) path = DFS(b, deep-1, maxx, sourceoperators, path) else: #print(len(list(itertools.combinations(initlist, 2 for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) path = DFS(b, deep-1, maxx, sourceoperators, path) return path path = [] mresult = DFS(b, 2, 2, mylist, path) -- https://mail.python.org/mailman/listinfo/python-list
run code error with numpy and scipy
when i run code in window has an error not a valid win32 dll then i install scipy first in this site, then install numpy-mkl all python 2.7 and win32 http://www.lfd.uci.edu/~gohlke/pythonlibs/ then i run code below, got error , and captured screen in this link https://drive.google.com/file/d/0Bxs_ao6uuBDUQXROd2VqSURGa00/view?usp=sharing import numpy as np from scipy.sparse.linalg import svds from functools import partial from scipy.sparse import csr_matrix def emsvd(Y, k=None, tol=1E-3, maxiter=None): if k is None: svdmethod = partial(np.linalg.svd, full_matrices=False) else: svdmethod = partial(svds, k=k) if maxiter is None: maxiter = np.inf muhat = np.nanmean(Y, axis=0, keepdims=1) valid = np.isfinite(Y) Y_hat = np.where(valid, Y, muhat) halt = False ii = 1 v_prev = 0 while not halt: U, s, Vt = svdmethod(Y_hat - muhat) Y_hat[~valid] = (U.dot(np.diag(s)).dot(Vt) + muhat)[~valid] muhat = Y_hat.mean(axis=0, keepdims=1) v = s.sum() if ii >= maxiter or ((v - v_prev) / v_prev) < tol: halt = True ii += 1 v_prev = v return Y_hat, muhat, U, s, Vt A = csr_matrix([[1, 2, 0], [0, 0, 3], [4, 0, 5]]) emsvd(A) np.nanmean(A, axis=0, keepdims=1) -- https://mail.python.org/mailman/listinfo/python-list
Re: how to extract a variable as parameter which has index using by a for loop?
just extract b[i][0:1] and b[i][1:2] out of for loop but i depend on for loop def node(mmm, A, B): H2 = [MM[mmm][A+B] for i in range(len(b))] return H2 node(5, b[i][0:1], b[i][1:2]) it is not convenient to disclose in detail just expect to discuss from the view of programming On Wednesday, June 8, 2016 at 4:56:56 PM UTC+8, Steven D'Aprano wrote: > On Wednesday 08 June 2016 17:31, meInvent bbird wrote: > > > b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in > > range(m)] > > b[21][0:1]+b[21][1:2] > > b[21][1:2]+b[21][2:3] > > b[21][0:1]+b[21][2:3] > > > > > > originally, > > > > mmm = 5 > > H2 = [MM[mmm][b[i][0:1]+b[i][1:2]] for i in range(len(b))] > > This is a mess. I don't understand what you are trying to do. You have these > variable names that don't mean anything, like "b" and "H2", and others which > aren't defined, like MM. I don't understand what you are trying to > accomplish, > or the purpose of your code. > > > > how to extract b[i][0:1] and b[i][1:2] as parameters? > > I don't understand the question. > > > > def node(mmm, b[i][0:1], b[i][1:2]): > > H2 = [MM[mmm][A+B] for i in range(len(b))] > > return H2 > > > > node(5, b[i][0:1], b[i][1:2]) > > Explain what node() is supposed to do, in English. Don't write any code yet. > What is its purpose? What does it return? What arguments does it need to take > in order to perform its purpose? > > > -- > Steve -- https://mail.python.org/mailman/listinfo/python-list
how to extract a variable as parameter which has index using by a for loop?
b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] b[21][0:1]+b[21][1:2] b[21][1:2]+b[21][2:3] b[21][0:1]+b[21][2:3] originally, mmm = 5 H2 = [MM[mmm][b[i][0:1]+b[i][1:2]] for i in range(len(b))] how to extract b[i][0:1] and b[i][1:2] as parameters? def node(mmm, b[i][0:1], b[i][1:2]): H2 = [MM[mmm][A+B] for i in range(len(b))] return H2 node(5, b[i][0:1], b[i][1:2]) -- https://mail.python.org/mailman/listinfo/python-list
Re: why for loop print only once after add if statement
when read my code again, i discover this error i fixed before but forget to do for another branch of if statement now fixed On Saturday, May 28, 2016 at 6:19:23 PM UTC+8, meInvent bbird wrote: > for item, i in enumerate(aa) > print item > > this writing, it can print all values > > for item, i in enumerate(aa) > if item == findit: > print item > > this only print the first value, means it only print once then not print > again, > > where is wrong? -- https://mail.python.org/mailman/listinfo/python-list
Re: why for loop print only once after add if statement
thanks, i discover that i misunderstand i and item, they should be swapped On Saturday, May 28, 2016 at 6:19:23 PM UTC+8, meInvent bbird wrote: > for item, i in enumerate(aa) > print item > > this writing, it can print all values > > for item, i in enumerate(aa) > if item == findit: > print item > > this only print the first value, means it only print once then not print > again, > > where is wrong? -- https://mail.python.org/mailman/listinfo/python-list
how to write code generator for Isabelle by using pygments?
how to write code generator for Isabelle by using pygments? i am thinking to write a machine learning code to generate code by learning example from Isabelle code however, after google, not much information about this. -- https://mail.python.org/mailman/listinfo/python-list