Re: [Tutor] Importing sub modules
On 3/31/2011 1:07 PM, Prasad, Ramit wrote: This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase& Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase& Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. I hope your lawyers are happy with the above text. I personally find it annoying. I certainly would not be bothered to wonder whether i "received this transmission in error" or to contact the sender or destroy the material! "STRICTLY PROHIBITED" oh I am so scared! So there! -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Importing sub modules
Prasad, Ramit wrote: In any event, you shouldn't be worrying about something like overhead until after your base prorgram is written. Base programs are written. I was just looking into insight about the mechanics behind importing :) For instance, do these libraries normally lazy load? If you have mod1.mod2 and mod1.mod3 and import mod1 does it usually also internally load mod2/3? import mod1.mod2 (or do from mod1 import mod2) does it avoid any loading of mod3 or does it do that as part of loading mod1? That depends on the module. In the case of os, it has code like the following: if 'posix' in _names: name = 'posix' linesep = '\n' from posix import * try: from posix import _exit except ImportError: pass import posixpath as path import posix __all__.extend(_get_exports_list(posix)) del posix elif 'nt' in _names: # ... similar code elif 'os2' in _names: # ... elif 'mac' in _names: # ... elif 'ce' in _names: # ... elif 'riscos' in _names: # ... else: # raise exception So in the case of os, no, it does not lazily load path only when needed, and os.path is available as soon as you import os, without any further imports. However, if the module is a more modern package, the situation *may* be different. A package uses a directory with sub-modules, plus an __init__.py file. In this case, the behaviour is entirely up to the author. Here's an example from one of my own Python 3 libraries: I have a package that (currently) looks something like this: stats/ +-- __init__.py +-- co.py +-- order.py +-- utils.py +-- _tests/ +-- test_co.py ... etc. (greatly simplified). When you call "import stats", Python reads the file stats/__init__.py, compiles it and creates a module from it. __init__.py in turn includes a line "from . import utils". (This is Python 3 syntax, so it doesn't work with Python 2.) That line imports the stats/utils.py submodule and makes it available from within stats as stats.utils. However the sub-modules co.py and order.py are *not* imported by the main module. They are only loaded on demand, when you say "import stats.co" or "from stats.order import median" or similar. So it depends on the module. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Importing sub modules
Prasad, Ramit wrote: The joins are really just random calls. I was just curious if importing os.path could avoid any reading/overhead that might occur by importing os. No. Python has no way of knowing what os.path is until it has imported os and can do an attribute lookup on os.path. This is determined at runtime by the os module, and depends on your operating system: >>> import os.path >>> os >>> os.path DO NOT try importing posixpath (or equivalent for other OSes) directly, always use os.path. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Importing sub modules
>> In any event, you shouldn't be worrying about something like overhead until >> after your base prorgram is written. Base programs are written. I was just looking into insight about the mechanics behind importing :) For instance, do these libraries normally lazy load? If you have mod1.mod2 and mod1.mod3 and import mod1 does it usually also internally load mod2/3? import mod1.mod2 (or do from mod1 import mod2) does it avoid any loading of mod3 or does it do that as part of loading mod1? I suppose this mailing list may not be the correct place to be asking this question since it is geared towards beginner questions. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Importing sub modules
You could just use from os import path and use it like path.xxx I don't know know if it saves on overhead or not. In any event, you shouldn't be worrying about something like overhead until after your base prorgram is written. Generally if all I use is path, for example, I use from import. If not I just import the enchilada Sent from my Verizon Wireless BlackBerry -Original Message- From: "Prasad, Ramit" Sender: tutor-bounces+eire1130=gmail@python.org Date: Thu, 31 Mar 2011 17:11:50 To: 'Emile van Sebille'; 'tutor@python.org' Subject: Re: [Tutor] Importing sub modules The joins are really just random calls. I was just curious if importing os.path could avoid any reading/overhead that might occur by importing os. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -Original Message- From: tutor-bounces+ramit.prasad=jpmchase@python.org [mailto:tutor-bounces+ramit.prasad=jpmchase@python.org] On Behalf Of Emile van Sebille Sent: Thursday, March 31, 2011 3:17 PM To: tutor@python.org Subject: Re: [Tutor] Importing sub modules On 3/31/2011 11:07 AM Prasad, Ramit said... > Hi everyone, > I was wondering if there is a difference in > import os os.path.join(string1,string2) > AND import os.path os.path.join(string1,string2) > > A quick test shows they're the same: ActivePython 2.6.6.15 (ActiveState Software Inc.) based on Python 2.6.6 (r266:84292, Aug 24 2010, 16:01:11) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os as os1 >>> import os.path >>> os1.path is os.path True >>> Although I'm not sure what to make of the joins What are you trying to do? Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Importing sub modules
The joins are really just random calls. I was just curious if importing os.path could avoid any reading/overhead that might occur by importing os. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -Original Message- From: tutor-bounces+ramit.prasad=jpmchase@python.org [mailto:tutor-bounces+ramit.prasad=jpmchase@python.org] On Behalf Of Emile van Sebille Sent: Thursday, March 31, 2011 3:17 PM To: tutor@python.org Subject: Re: [Tutor] Importing sub modules On 3/31/2011 11:07 AM Prasad, Ramit said... > Hi everyone, > I was wondering if there is a difference in > import os os.path.join(string1,string2) > AND import os.path os.path.join(string1,string2) > > A quick test shows they're the same: ActivePython 2.6.6.15 (ActiveState Software Inc.) based on Python 2.6.6 (r266:84292, Aug 24 2010, 16:01:11) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os as os1 >>> import os.path >>> os1.path is os.path True >>> Although I'm not sure what to make of the joins What are you trying to do? Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
http%3A%2F%2Fwww%2Eeasy%2Dsofa%2Epl%2F%2Fimages%2Ffriends%2Ehtml ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Importing sub modules
On 3/31/2011 11:07 AM Prasad, Ramit said... Hi everyone, I was wondering if there is a difference in import os os.path.join(string1,string2) AND import os.path os.path.join(string1,string2) A quick test shows they're the same: ActivePython 2.6.6.15 (ActiveState Software Inc.) based on Python 2.6.6 (r266:84292, Aug 24 2010, 16:01:11) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os as os1 >>> import os.path >>> os1.path is os.path True >>> Although I'm not sure what to make of the joins What are you trying to do? Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Importing sub modules
Hi everyone, I was wondering if there is a difference in >>>import os >>>os.path.join(string1,string2) AND >>>import os.path >>>os.path.join(string1,string2) The only difference that I could think of is if the os module does not get loaded on the second example. I am not sure if it does. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Data frame packages
I appreciate all the responses and apologize for not being more detailed. An R data frame is a tightly grouped array of vectors of the same length. Each vector is all the same datatype, I believe, but you can read all types of data into the same variable. The benefit is being able to quickly subset, stack and such (or 'melt' and 'cast' in R vernacular) according to any of your qualitative variables (or 'factors'). As someone pretty familiar with R and quite a newbie to python, I'm wary of insulting anybody's intelligence by describing what to me is effectively the default data format my most familiar language. The following is some brief R code if you're curious about how it works. d <- read.csv(filename, header = TRUE, sep = ',') #this reads the table. '<-' is the assignment operator d[ , 'column.name'] # this references a column name. This same syntax can be used to reference all rows (index is put left of the comma) and columns in any order. The data frame then allows you to quickly declare new fields as functions of other fields. newVar <- d[ ,'column.name'] + d[ ,'another.column'] d$newVar <- newVar # attaches newVar to the rightmost column of 'd' At any rate, I finally got pydataframe to work, but had to go from Python 2.6 to 2.5. pydataframe has a bug for Windows that the author points out. Line 127 in 'parsers.py' should be changed from: columns = list(itertools.izip_longest(*split_lines ,fillvalue = na_text)) to: columns = list(itertools.izip_longest(list(*split_lines),fillvalue = na_text)) I don't know exactly what I did, but the module would not load until I did that. I know itertools.izip_longest requires 2 arguments before fillvalue, so I guess that did it. It's a handy way to handle alpha-numeric data. My problem with the csv module was that it interpreted all numbers as strings. Thanks again. On Thu, Mar 31, 2011 at 8:17 AM, James Reynolds wrote: > > > On Thu, Mar 31, 2011 at 11:10 AM, Blockheads Oi Oi < > breamore...@yahoo.co.uk> wrote: > >> On 31/03/2011 09:38, Ben Hunter wrote: >> >>> Is anybody out there familiar with data frame modules for python that >>> will allow me to read a CSV in a similar way that R does? pydataframe >>> and DataFrame have both befuddled me. One requires a special stripe of R >>> that I don't think is available on windows and the other is either very >>> buggy or I've put it in the wrong directory / installed incorrectly. >>> Sorry for the vague question - just taking the pulse. I haven't seen any >>> chatter about this on this mailing list. >>> >>> >>> >> What are you trying to achieve? Can you simply read the data with the >> standard library csv module and manipulate it to your needs?What makes >> you say that the code is buggy, have you examples of what you tried and >> where it was wrong? Did you install with easy_install or run setup.py? >> >> >> >>> ___ >>> Tutor maillist - Tutor@python.org >>> To unsubscribe or change subscription options: >>> http://mail.python.org/mailman/listinfo/tutor >>> >> >> Regards. >> >> Mark L. >> >> >> >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> > > > > > > > > > > > > > > > I'm not familiar with it, but what about http://rpy.sourceforge.net/ > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] String formatting question.
On 31-Mar-11 09:46, bob gailer wrote: IMHO % formatting is the easiest to use and understand. I am sorry that it has been slated for removal. I had the same reaction, but I think it was mostly because of my long background as a C programmer, since it's essentially the equivalent of printf() formatting. Just heavily ingrained in my brain. However, since the more recent Python 2 versions have supported str.format(), and anticipating their removal from Python 3, I have started gravitating more to them, and I have to admit they're more powerful and probably a good evolutionary step to take. Especially so if your formats are configurable or generated by code which may want to reorder the values. -- Steve Willoughby / st...@alchemy.com "A ship in harbor is safe, but that is not what ships are built for." PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] String formatting question.
IMHO % formatting is the easiest to use and understand. I am sorry that it has been slated for removal. -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] String formatting question.
Wayne Werner wrote: On Tue, Mar 29, 2011 at 2:41 PM, Prasad, Ramit wrote: Is there a difference (or preference) between using the following? "%s %d" % (var,num) VERSUS "{0} {1}".format(var,num) Practically there's no difference. In reality (and under the hood) there are more differences, some of which are subtle. On the contrary, the two code snippets *explicitly* do different things, about as different as: str(var) + str(int(num)) vs. str(var) + str(num) The first example expects an arbitrary object and a number on the right hand side of the % operator. The second example expects two arbitrary objects. Now, I see from your next comment that you realise this: For instance, in the first example, var = 3, num = 'hi' will error, while with .format, it won't. but you don't make it clear that that's because the two pieces of code ask for two different things, not because of a difference between % and format(). To be consistent, you would compare: "%s %s" % (var,num) vs. "{0} {1}".format(var,num) or possibly: "%s %d" % (var,num) "{0} {1:d}".format(var,num) # I think, I'm stuck here with Python 2.4 # and can't check it. Any other differences? Yes, plenty. % formatting and .format() don't just have different syntax, they have different capabilities. format() has more power, but that power comes at the cost of being slightly slower and being more verbose to write. My personal preference is to use .format() as it (usually) feels more elegant: ("{0} "*8+"{1}").format("na", "batman") vs: "%s %s" % ("na" * 8, "batman") They do different things. The first repeats "na" separated by spaces; the second has "nananana" without spaces. In any case, we differ in our opinion of elegant, because I feel the two solutions are equally elegant. And named arguments: "Name: {name}\nAddress: {address}".format(name="Bob", address="123 Castle Auuurrggh") vs "Name: %(name)\nAddress: %(address)" % {"name": "Bob", "address", "123 Castle Auurgh") The second example will not work, because you have forgotten the type code. That's an advantage of % formatting: if you forget the type code, you get an error instead of a default, likely incorrect, type. My recommendation would be to use what feels most natural to you. I think I read somewhere that % formatting is so ingrained that even though the .format() method is intended to replace it, it's probably going to stick around for a while. I should think so... there are plenty of ex-C programmers whose attitude is "You can have my % format strings when you pry them from my cold, dead fingers." I'm not a C programmer, and I agree with them. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Data frame packages
On Thu, Mar 31, 2011 at 11:10 AM, Blockheads Oi Oi wrote: > On 31/03/2011 09:38, Ben Hunter wrote: > >> Is anybody out there familiar with data frame modules for python that >> will allow me to read a CSV in a similar way that R does? pydataframe >> and DataFrame have both befuddled me. One requires a special stripe of R >> that I don't think is available on windows and the other is either very >> buggy or I've put it in the wrong directory / installed incorrectly. >> Sorry for the vague question - just taking the pulse. I haven't seen any >> chatter about this on this mailing list. >> >> >> > What are you trying to achieve? Can you simply read the data with the > standard library csv module and manipulate it to your needs?What makes > you say that the code is buggy, have you examples of what you tried and > where it was wrong? Did you install with easy_install or run setup.py? > > > >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> > > Regards. > > Mark L. > > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > I'm not familiar with it, but what about http://rpy.sourceforge.net/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Data frame packages
On 31/03/2011 09:38, Ben Hunter wrote: Is anybody out there familiar with data frame modules for python that will allow me to read a CSV in a similar way that R does? pydataframe and DataFrame have both befuddled me. One requires a special stripe of R that I don't think is available on windows and the other is either very buggy or I've put it in the wrong directory / installed incorrectly. Sorry for the vague question - just taking the pulse. I haven't seen any chatter about this on this mailing list. What are you trying to achieve? Can you simply read the data with the standard library csv module and manipulate it to your needs?What makes you say that the code is buggy, have you examples of what you tried and where it was wrong? Did you install with easy_install or run setup.py? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Regards. Mark L. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Converting a numpy matrix to a numpy array
David Crisp wrote: > Hello, > > I have a very simple question / problem I need answered. The problem > is imnot entirely sure of the correct terminology and langauge to use > to describe it. (One of the reasons im using this miling list) > > I have a 2d matrix representing the X the Y and the Z value of a > point. I wish to convert that matrix to an array.What is a good > way of doing so? > > Eg: > Matrix > 012345 > 0xo > 1xo > 2ox > 3oo > 4ox > 5ox > > > I want to convert that to a 2d array which looks like: > 0,0,x > 0,1,o > 0,2,o > 0,3,o > 0,4,o > 0,5,o > ... > 5,4,o > 5,5,o > > I am pretty sure it is simple. I'm just having a brain fade. Using basic numpy: >>> import numpy as np >>> a = np.array(list("xoo" ... "oxx" ... "oxo")).reshape(3,3) >>> a array([['x', 'o', 'o'], ['o', 'x', 'x'], ['o', 'x', 'o']], dtype='|S1') >>> np.array([np.arange(9)//3, np.arange(9)%3, a.flatten()]).transpose() array([['0', '0', 'x'], ['0', '1', 'o'], ['0', '2', 'o'], ['1', '0', 'o'], ['1', '1', 'x'], ['1', '2', 'x'], ['2', '0', 'o'], ['2', '1', 'x'], ['2', '2', 'o']], dtype='|S8') >>> np.array([np.arange(9)//3, np.arange(9)%3, (a=="x").flatten()]).transpose() array([[0, 0, 1], [0, 1, 0], [0, 2, 0], [1, 0, 0], [1, 1, 1], [1, 2, 1], [2, 0, 0], [2, 1, 1], [2, 2, 0]]) >>> np.array([np.arange(9)//3, np.arange(9)%3, a.flatten()], dtype=object).transpose() array([[0, 0, x], [0, 1, o], [0, 2, o], [1, 0, o], [1, 1, x], [1, 2, x], [2, 0, o], [2, 1, x], [2, 2, o]], dtype=object) If that's not good enough you may also ask on the numpy mailing list. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Data frame packages
Ben Hunter wrote: Is anybody out there familiar with data frame modules for python that will allow me to read a CSV in a similar way that R does? pydataframe and DataFrame have both befuddled me. One requires a special stripe of R that I don't think is available on windows and the other is either very buggy or I've put it in the wrong directory / installed incorrectly. Sorry for the vague question - just taking the pulse. I haven't seen any chatter about this on this mailing list. Perhaps if you give an example of what R does with CSV files, and explain what "data frame" means in this context, we may be able to help. Otherwise, have you tried googling "Python data frame"? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Converting a numpy matrix to a numpy array
David Crisp wrote: I have a 2d matrix representing the X the Y and the Z value of a point. I wish to convert that matrix to an array.What is a good way of doing so? Eg: Matrix 012345 0xo 1xo 2ox 3oo 4ox 5ox It's not clear what this matrix actually is. Is this from a text file? What are the X's and O's (letter o)? Are they meant to be place-holders for something else, or literally letter X and letter O? If placeholders, what are they placeholders for? And if literally X and O, what are you expecting to do with them in numpy, which expects numeric data? I want to convert that to a 2d array which looks like: 0,0,x 0,1,o 0,2,o 0,3,o 0,4,o 0,5,o ... 5,4,o 5,5,o What you are describing is not a two dimensional array. It is a one-dimensional list, each item of which includes 2D coordinates as explicit data. You almost certainly do not want that! Working with numpy, you want to use a numpy two dimensional array that looks something like this: [ [ x o o o o o ] [ x o o o o o ] [ o x x x x x ] [ o o o o o o ] [ o o o o o x ] [ o o o o o x ] ] where the coordinates are implied. I have borrowed Python list syntax [] for the array. Each row is a [...] and the columns are read down the rows. Unfortunately, I'm not using my usual computer, so I don't have access to numpy at the moment. More detail will have to follow later. Regards, -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Data frame packages
Is anybody out there familiar with data frame modules for python that will allow me to read a CSV in a similar way that R does? pydataframe and DataFrame have both befuddled me. One requires a special stripe of R that I don't think is available on windows and the other is either very buggy or I've put it in the wrong directory / installed incorrectly. Sorry for the vague question - just taking the pulse. I haven't seen any chatter about this on this mailing list. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor