Re: [Tutor] Multiprocessing with many input input parameters
Thanks Mike, But I am still not clear. do I write: def f([x,y,z]) ? How exactly do one write the function and how does one ensure that each positional argument is accounted for. Dr. Sydney Shall Department of Haematological Medicine King's College London 123 Coldharbour Lane London SE5 9NU ENGLAND E-Mail: sydney.shall (Correspondents outside the College should add @KCL.AC.UK) TEL: +44 (0)208 48 59 01 From: Mike Barnett Sent: 11 July 2019 16:40 To: Shall, Sydney Cc: tutor@python.org Subject: RE: [Tutor] Multiprocessing with many input input parameters If you're passing parameters as a list, then you need a "," at the end of the items. Otherwise if you have something like a string as the only item, the list will be the string. list_with_one_item = ['item one',] @mike -Original Message- From: Shall, Sydney Sent: Wednesday, July 10, 2019 11:44 AM To: tutor@python.org Subject: [Tutor] Multiprocessing with many input input parameters I am using MAC OS X 10.14.5 on a MAC iBook I use Python 3.7.0 from Anaconda, with Spyder 3.3.3 I am a relative beginner. My program models cell reproduction. I have written a program that models this and it works. Now I want to model a tissue with several types of cells. I did this by simply rerunning the program with different inputs (cell characteristics). But now I want to send and receive signals between the cells in each population. This requires some sort of concurrent processing with halts at appropriate points to pass and receive signals. I thought to use multiprocessing. I have read the documentation and reproduced the models in the docs. But I cannot figure out how to feed in the data for multiple parameters. I have tried using Pool and it works fine, but I can only get it to accept 1 input parameter, although multiple data inputs with one parameter works nicely. So, my questions are; 1. Is multiprocessing the suitable choice. 2. if yes, how does one write a function with multiple input parameters. Thank s in advance. Sydney Prodessor. Sydney Shall Department of Haematological Medicine King's College London 123 Coldharbour Lane London SE5 9NU ENGLAND E-Mail: sydney.shall (Correspondents outside the College should add @KCL.AC.UK) TEL: +44 (0)208 48 59 01 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Multiprocessing with many input input parameters
I am using MAC OS X 10.14.5 on a MAC iBook I use Python 3.7.0 from Anaconda, with Spyder 3.3.3 I am a relative beginner. My program models cell reproduction. I have written a program that models this and it works. Now I want to model a tissue with several types of cells. I did this by simply rerunning the program with different inputs (cell characteristics). But now I want to send and receive signals between the cells in each population. This requires some sort of concurrent processing with halts at appropriate points to pass and receive signals. I thought to use multiprocessing. I have read the documentation and reproduced the models in the docs. But I cannot figure out how to feed in the data for multiple parameters. I have tried using Pool and it works fine, but I can only get it to accept 1 input parameter, although multiple data inputs with one parameter works nicely. So, my questions are; 1. Is multiprocessing the suitable choice. 2. if yes, how does one write a function with multiple input parameters. Thank s in advance. Sydney Prodessor. Sydney Shall Department of Haematological Medicine King's College London 123 Coldharbour Lane London SE5 9NU ENGLAND E-Mail: sydney.shall (Correspondents outside the College should add @KCL.AC.UK) TEL: +44 (0)208 48 59 01 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble Downloading To MacOS Mojave 10.14.3 released mid 2014
On 13/03/2019 14:11, Paul McCombs wrote: > On Wed, Mar 13, 2019, 5:05 AM Robert Landers wrote: > >> Hello Tutor, >> >> I am having trouble finding a python 3.7.2 download for my MacOS Mojave >> 10.14.3 released mid 2014. >> I would like to use Xcode to learn python. >> >> Is my OS too old? >> >> Please provide guidance. >> >> Thanks. >> ___ >> > > MacOS Mojave 10.14.3 was released in December 2018. > > Python 3.7.2 is available for MacOS versions as early as 10.6, which came > out in 2009. > > Can you clarify what you mean? > > Paul McCombs > > https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.python.org%2Fdownloads%2Frelease%2Fpython-372%2Fdata=01%7C01%7Csydney.shall%40kcl.ac.uk%7C6d5116a86151497caefd08d6a7d23e37%7C8370cf1416f34c16b83c724071654356%7C0sdata=XM0%2FLvaSE7wYpSfvZWuaKBYARoUGKCkBS9XWD2bZbzE%3Dreserved=0 > > macOS users > > - For Python 3.7 releases, we provide two binary installer options for > download. The default variant is 64-bit-only and works on macOS 10.9 > (Mavericks) and later systems. We also continue to provide a 64-bit/32-bit > variant that works on all versions of macOS from 10.6 (Snow Leopard) on. > Both variants now come with batteries- > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutordata=01%7C01%7Csydney.shall%40kcl.ac.uk%7C6d5116a86151497caefd08d6a7d23e37%7C8370cf1416f34c16b83c724071654356%7C0sdata=8vKb0Mzx6M3QldhtDKDcnNNUXsuSFAvKGyX3lmwAXOU%3Dreserved=0 > I meant to add that I use Spyder 3.3.2 and that works fine too. -- _ Professor Sydney Shall Department of Haematology/Oncology Phone: +(0)2078489200 E-Mail: sydney.shall [Correspondents outside the College should add @kcl.ac.uk] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble Downloading To MacOS Mojave 10.14.3 released mid 2014
On 13/03/2019 14:11, Paul McCombs wrote: > On Wed, Mar 13, 2019, 5:05 AM Robert Landers wrote: > >> Hello Tutor, >> >> I am having trouble finding a python 3.7.2 download for my MacOS Mojave >> 10.14.3 released mid 2014. >> I would like to use Xcode to learn python. >> >> Is my OS too old? >> >> Please provide guidance. >> >> Thanks. >> ___ >> > > MacOS Mojave 10.14.3 was released in December 2018. > > Python 3.7.2 is available for MacOS versions as early as 10.6, which came > out in 2009. > > Can you clarify what you mean? > > Paul McCombs > > https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.python.org%2Fdownloads%2Frelease%2Fpython-372%2Fdata=01%7C01%7Csydney.shall%40kcl.ac.uk%7C6d5116a86151497caefd08d6a7d23e37%7C8370cf1416f34c16b83c724071654356%7C0sdata=XM0%2FLvaSE7wYpSfvZWuaKBYARoUGKCkBS9XWD2bZbzE%3Dreserved=0 > > macOS users > > - For Python 3.7 releases, we provide two binary installer options for > download. The default variant is 64-bit-only and works on macOS 10.9 > (Mavericks) and later systems. We also continue to provide a 64-bit/32-bit > variant that works on all versions of macOS from 10.6 (Snow Leopard) on. > Both variants now come with batteries- > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutordata=01%7C01%7Csydney.shall%40kcl.ac.uk%7C6d5116a86151497caefd08d6a7d23e37%7C8370cf1416f34c16b83c724071654356%7C0sdata=8vKb0Mzx6M3QldhtDKDcnNNUXsuSFAvKGyX3lmwAXOU%3Dreserved=0 > I am using MacOS Mojave 10.4.3. I am also using Python 3.7.0 supplied by Anaconda. It works fine. Sydney -- _ Professor Sydney Shall Department of Haematology/Oncology Phone: +(0)2078489200 E-Mail: sydney.shall [Correspondents outside the College should add @kcl.ac.uk] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] problem with creating paths
On 17/10/2018 18:18, Mats Wichmann wrote: On 10/17/2018 10:07 AM, Shall, Sydney via Tutor wrote: Firstly, I would like to thank Steven for reminding me of the assert statement. I should have remembered this. It allowed me to isolate the problem, which predictably (for me) was very elementary. I am too embarrassed to say how simple the error was. However, my original problem was not solved by correcting this error. So, I will now try and narrow down the location of the problem and then if I cannot solve it, I shall return for more good advice. Many thanks to Steven and to Peter. I'll weigh in with a mini- (and unasked-for-) lecture here: this is often the point at which someone says "boy, I wish Python were strongly typed, so things didn't change types in flight". But in fact, the list didn't change types, it's still a list. In fact we even know where that list is: it's the first element of that tuple you ended up with. The _name_ you gave to that list carries no typing meaning, however (although you can give it type hints that an external tool could use to warn you that you are changing something). So you have somewhere given that name to a completely different object, a tuple which contains your list and another element. So clearly what you're looking for is the place that happens. So here's a sketch of how you might use type hinting to find this, to bring it back to something practical: === types.py: from typing import List, Tuple a: List[str] = [ '/a/path', '/b/path', ] print(type(a)) print(a) a = (a, '/c/path') print(type(a)) print(a) === this works just fine: $ python3 types.py ['/a/path', '/b/path'] (['/a/path', '/b/path'], '/c/path') === but a hinting tool can see a possible issue: $ mypy types.py types.py:10: error: Incompatible types in assignment (expression has type "Tuple[List[str], str]", variable has type "List[str]") Thanks for this. Most helpful. Sydney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutordata=01%7C01%7Csydney.shall%40kcl.ac.uk%7Ca58896d72c374cda3c1508d63454b783%7C8370cf1416f34c16b83c724071654356%7C0sdata=OHZtedYdy0UHKDagLO1TI%2BUIjEJuzRjZjD4HRdSQmNI%3Dreserved=0 -- _ Professor Sydney Shall Department of Haematology/Oncology Phone: +(0)2078489200 E-Mail: sydney.shall [Correspondents outside the College should add @kcl.ac.uk] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] problem with creating paths
Firstly, I would like to thank Steven for reminding me of the assert statement. I should have remembered this. It allowed me to isolate the problem, which predictably (for me) was very elementary. I am too embarrassed to say how simple the error was. However, my original problem was not solved by correcting this error. So, I will now try and narrow down the location of the problem and then if I cannot solve it, I shall return for more good advice. Many thanks to Steven and to Peter. Sydney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] problem with creating paths
I can now add to my previous email the following observation. If I do not delete the output file and redo the test I get the following as the 'extra' entry in paths: '/Users/sydney/AnacondaProjects/capital_reproduction/Current_Version/Results/20181017D/B_Cycle_Zero/Text_Files') If however, I delete the output file and then redo the test I get the following as the 'extra' entry in paths: '/Users/sydney/.Trash/20181017D/B_Cycle_Zero/Text_Files') This seems to be consistent. The upper incorrect entry is item path19 in the list part of paths. I have studied every example of 'path19' in the program and I cannot find an explanation. help! Sydney _ Professor Sydney Shall Department of Haematology/Oncology Phone: +(0)2078489200 E-Mail: sydney.shall [Correspondents outside the College should add @kcl.ac.uk] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] problem with creating paths
I am a novice (at programming). I use MAC OS 10.13.6 Anaconda. Python 3.5.4 Spyder 3.5.6 I have just re-written a moderately complex program (a Class) on the advice of Alan and Steven. The rewriting proved to be very useful. The working program uses instances of the Class with User chosen parameters. The output data seems correct to me. So I then began redoing all the tests. The first Methods tested gave OK. But I have just started testing a new Method and I get a Universal error in my tests. It says that the output file is already present. These files (paths) are correctly deleted by the 'teardown' Method, when only the earlier portion of the program is tested. But are not deleted with the last method tested. After searching I have found this unexpected output illustrated in the copy-paste below. test The type of the paths is: The values of the paths are : ( [ '/Users/sydney/AnacondaProjects/reproduction/Current_Version/Results/', '/Users/sydney/AnacondaProjects/reproduction/Current_Version/Results/20181017D', '/Users/sydney/AnacondaProjects/reproduction/Current_Version/Results/20181017D/A_POCI_Input_Data', . . . . '/Users/sydney/AnacondaProjects/reproduction/Current_Version /Results/20181017D/B_Cycle_Zero/Text_Files', . . . '/Users/sydney/AnacondaProjects/reproduction/Current_Version/Results/20181017D/C_Final_Results/Plots/Population_Data/Ratios'], '/Users/sydney/.Trash/20181017D/B_Cycle_Zero/Text_Files') There are two items that are 'wrong' in this output. 1. The property 'paths' is defined in the program as a list and the items are added using paths.append(), yet the test says that when tested it is a tuple. 2. The tuple arises by the addition of the last entry in the file, AFTER the closing bracket of the list which is the first item in the tuple. When I test the length of 'paths' I get a value of 2! I apologise for the lengthy explanation, but I am at a loss. I have looked for an error that might have added an item as a + and I find nothing. The character of the final item is also puzzling to me. I would much appreciate any guidance as to how I should search for the fault or error. Sydney _ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Spyder - How to determine files that appear at start-up
My question concerns Spyder. I know that this is a Python list, but I also see that some people here also use Spyder. So, please forgive me. My problem is simple. I cannot find out how I can determine the set of files that open at start-up. I am annoyed by the fact that I must manually load my set of working files each time that I start Spyder. Thanks. Sydney _ Professor Sydney Shall Department of Haematology/Oncology Phone: +(0)2078489200 E-Mail: sydney.shall [Correspondents outside the College should add @kcl.ac.uk] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: How to roughly associate the values of two numpy arrays, or python lists if necessary
On 23/09/2018 13:04, Peter Otten wrote: Peter Otten wrote: Maybe you could sort the already-sorted property_b again, with some random offset: import itertools def wiggled(items, sigma): ... counter = itertools.count() ... def key(item): return random.gauss(next(counter), sigma) ... return sorted(items, key=key) ... One more example: s = """\ ... But my actual scientific problem requires that the correlation should be ... only approximate and I do not know how close to to a perfect correlation ... it should be. So, I need to introduce some lack of good correlation when ... I set up the correlation. How to do that is my problem. ... """ print(textwrap.fill(" ".join(wiggled(s.split(), 2 But actual my scientific the requires that problem should only correlation approximate be and not do I know how close to a perfect to correlation should it So, be. I to lack need some introduce correlation I of good when set correlation. up How to the that do problem. is my :) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutordata=01%7C01%7Csydney.shall%40kcl.ac.uk%7C185332cee28f49ed465108d6214ce8ab%7C8370cf1416f34c16b83c724071654356%7C0sdata=GBAb%2FdY2zrBqSwOl33ejT%2BzzknQx5RYNXsNEqZQXCX4%3Dreserved=0 Thanks. Most useful. Sydney -- _ Professor Sydney Shall Department of Haematology/Oncology Phone: +(0)2078489200 E-Mail: sydney.shall [Correspondents outside the College should add @kcl.ac.uk] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: How to roughly associate the values of two numpy arrays, or python lists if necessary
On 23/09/2018 10:42, Peter Otten wrote: Shall, Sydney via Tutor wrote: What I want is the following. I have: property_a = [1, 6, 2, 4] property_b = [62, 73, 31 102] Result should approximately be: property_b = [31, 102, 62, 73] That is both lists change in value in exactly the same order. Now, this is easy to achieve. I could simply sort both lists is ascending order and I would then have an exact alignment of values is ascending order. The correlation would be a perfect linear relationship, I suppose. But my actual scientific problem requires that the correlation should be only approximate and I do not know how close to to a perfect correlation it should be. So, I need to introduce some lack of good correlation when I set up the correlation. How to do that is my problem. I hope this helps to clarify what my problem is. Maybe you could sort the already-sorted property_b again, with some random offset: import itertools def wiggled(items, sigma): ... counter = itertools.count() ... def key(item): return random.gauss(next(counter), sigma) ... return sorted(items, key=key) ... wiggled(range(20), 3) [0, 5, 2, 4, 1, 6, 7, 8, 3, 9, 11, 10, 13, 14, 16, 12, 18, 17, 19, 15] wiggled([31, 102, 62, 73], .8) [102, 31, 62, 73] wiggled([31, 102, 62, 73], .8) [31, 102, 62, 73] wiggled([31, 102, 62, 73], .8) [31, 102, 62, 73] wiggled([31, 102, 62, 73], .8) [31, 62, 102, 73] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutordata=01%7C01%7Csydney.shall%40kcl.ac.uk%7Cb9cbdce8c20e45dd3ff508d621390143%7C8370cf1416f34c16b83c724071654356%7C0sdata=yNo7hMVl7dYmH6d74MBaab5e5g6bPoWoqkza5TS1bXY%3Dreserved=0 Thanks to Oscar and to Pater for their help. They have set me on the correct path. The crucial advice to was to look at the randomisation procedures. I have used a procedure similar to that suggested by Peter and it works well. Cheers, Sydney _ Professor Sydney Shall Department of Haematology/Oncology Phone: +(0)2078489200 E-Mail: sydney.shall [Correspondents outside the College should add @kcl.ac.uk] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: How to roughly associate the values of two numpy arrays, or python lists if necessary
On 21/09/2018 00:01, Oscar Benjamin wrote: Sydney wrote and Alan forwarded: I have, I suspect, an elementary problem that I am too inexperienced to resolve. I have two numpy arrays, each representing the values of a specific property of a set of cells. Now, I want to associate the two values for each cell, that is for each index of the numpy array. But I want to associate them ROUGHLY, that means, APPROXIMATELY, so that there is a weak, linear correlation between the values representing one property and the values representing the second property of each individual cell. Up to now I have used the following procedure. I have divided each population of values into four segments based on the value of the standard deviation thus. 1. values > mean + 1 std (sigma) 2. values > mean but < mean + 1 std (sigma) 3. values < mean but > mean + 1 std (sigma) 4. values < mean + 1 std (sigma). Then I randomly select a value from group 1 for the first property and I associate it with a randomly selected sample of the second property from its group 1. And so on through the total population. This gave me a very rough linear association between the two properties, but I am wondering whether I can do it in a simpler and better way. Hi Sydney, I feel like I would definitely be able to solve your problem if I understood what you're talking about (I'm sure others here could as well). Please don't be put off by this but I don't think you've explained it very well. Perhaps if you give an example of what the input and output of this operation is supposed to look like then you would get a response. The example might look like: I have these arrays as input: property_a = [1, 6, 2, 4] property_b = [6, 3, 4, 6] Then I want a function that gives me this output associated_values = myfunction(a, b) associated_values [1, 3, 5, 2] Some explanation why you want this, how you know that's the output you want, and what any of it means would likely help... If you already have something that does what you want then it would make sense to show it but if your code is complicated then please try to simplify it and use only a small amount of data when showing it here. There is some advice for posting this kind of thing to a mailing list here: https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fsscce.org%2Fdata=01%7C01%7Csydney.shall%40kcl.ac.uk%7C77fe09364c79190308d61f4d4112%7C8370cf1416f34c16b83c724071654356%7C0sdata=DAhLxDli1vM%2BBcRXKemRo0sa%2BVJErJPZ%2Bwy5UHvUR4s%3Dreserved=0 -- Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutordata=01%7C01%7Csydney.shall%40kcl.ac.uk%7C77fe09364c79190308d61f4d4112%7C8370cf1416f34c16b83c724071654356%7C0sdata=Benb%2BsxqZr1Rhdj8jG81KRurndfNVnBGx0%2B3z9VXd54%3Dreserved=0 Thank you Oscar. Fair comment. What I want is the following. I have: > property_a = [1, 6, 2, 4] > property_b = [62, 73, 31 102] Result should approximately be: > property_b = [31, 102, 62, 73] That is both lists change in value in exactly the same order. Now, this is easy to achieve. I could simply sort both lists is ascending order and I would then have an exact alignment of values is ascending order. The correlation would be a perfect linear relationship, I suppose. But my actual scientific problem requires that the correlation should be only approximate and I do not know how close to to a perfect correlation it should be. So, I need to introduce some lack of good correlation when I set up the correlation. How to do that is my problem. I hope this helps to clarify what my problem is. Sydney -- _ Professor Sydney Shall Department of Haematology/Oncology Phone: +(0)2078489200 E-Mail: sydney.shall [Correspondents outside the College should add @kcl.ac.uk] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor