[Tutor] Help- Regarding python
Hi All! If i have data set like this means... 3626,5000,2918,5000,2353,2334,2642,1730,1687,1695,1717,1744,593,502,493,504,449,431,444,444,429,10 438,498,3626,3629,5000,2918,5000,2640,2334,2639,1696,1687,1695,1717,1744,592,502,493,504,449,431,444,441,429,10 439,498,3626,3629,5000,2918,5000,2633,2334,2645,1705,1686,1694,1719,1744,589,502,493,504,446,431,444,444,430,10 440,5000,3627,3628,5000,2919,3028,2346,2330,2638,1727,1684,1692,1714,1745,588,501,492,504,451,433,446,444,432,10 444,5021,3631,3634,5000,2919,5000,2626,2327,2638,1698,1680,1688,1709,1740,595,500,491,503,453,436,448,444,436,10 451,5025,3635,3639,5000,2920,3027,2620,2323,2632,1706,1673,1681,1703,753,595,499,491,502,457,440,453,454,442,20 458,5022,3640,3644,5000,2922,5000,2346,2321,2628,1688,1666,1674,1696,744,590,496. How to do PCA on this data? if it is in array how to do that? and also how to use princomp() in PCA? Shall i use the following code for doing PCA on given input? could you tell me? from numpy import mean,cov,double,cumsum,dot,linalg,array,rank from pylab import plot,subplot,axis,stem,show,figure A = array([ [2.4,0.7,2.9,2.2,3.0,2.7,1.6,1.1,1.6,0.9], [2.5,0.5,2.2,1.9,3.1,2.3,2,1,1.5,1.1] ]) M = (A-mean(A.T,axis=1)).T[latent,coeff] = linalg.eig(cov(M)) score = dot(coeff.T,M) return coeff,score,latent princomp(A): coeff, score, latent = princomp(A.T) figure() subplot(121) m = mean(A,axis=1) plot([0, -coeff[0,0]*2]+m[0], [0, -coeff[0,1]*2]+m[1],'--k') plot([0, coeff[1,0]*2]+m[0], [0, coeff[1,1]*2]+m[1],'--k') plot(A[0,:],A[1,:],'ob') # the data axis('equal') subplot(122) plot(score[0,:],score[1,:],'*g') axis('equal') plt.show() Thanks! Regards, Gayathri. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pickle.dump yielding awkward output
On 03/02/13 19:26, Spyros Charonis wrote: I am experiencing a strange result with the pickle module when using it to write certain results to a separate file. The only strangec results using pickle would be if the uinpickle failed to bring back that which was pickled. Pickle is a storage format not a display format. In short, I have a program that reads a file, finds lines which satisfy some criteria, and extracts those lines, storing them in a list. Extracting them with pickle I hope? That's the only thing that should be used to unpickle a pickled file. The list of extracted lines looks like this: ATOM 1 N GLN A 1 29.872 13.384 54.754 1.00 60.40 N The output stored from the call to the pickle.dump method, however, looks like this: (lp0 S'ATOM 1 N GLN A 1 29.872 13.384 54.754 1.00 60.40 N \r\n' Yep, I'm sure pickle can make sense of it. Does anyone know why the strings lp0, S', aS' are showing up? Because that's what pickle puts in there to help it unpickle it later. Why do you care? You shouldn't be looking at it (unless you want to understand how pickle works). pickle, as the name suggests, is intended for storing python objects for later use. This is often called object persistence in programming parlance. It is not designed for anything else. If you want cleanly formatted data in a file that you can read in a text editor or similar you need to do the formatting yourself or use another recognised format such as CSV or configparser (aka ini file). -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pickle.dump yielding awkward output
On 04/02/13 06:26, Spyros Charonis wrote: The output stored from the call to the pickle.dump method, however, looks like this: [...] Does anyone know why the strings lp0, S', aS' are showing up? Why do you care? Pickle is not a human-readable format. It may use plain text (optionally, there are also binary pickle formats) but it is not intended for humans to read or write. Pickle will write whatever information it needs in order to be able to reconstruct the data that you give it. My guess is that the things you see tell pickle which protocol is being used, and that the data you are writing is a list of strings. Unless you are creating a tool for analyzing pickle files, all you need care is that you can round-trip data into and out of pickle files. f = open('filename', 'wb') pickle.dump(data, f) f.close() f = open('filename', 'rb') newdata = pickle.load(f) f.close() assert data == newdata If you're looking for a storage format that is human-editable, check out the json or plist modules, or the third-party pyyaml module. http://docs.python.org/2/library/json.html http://docs.python.org/2/library/plistlib.html http://pyyaml.org/ -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pickle.dump yielding awkward output
(top-posting and offline response fixed) On Sun, Feb 3, 2013 at 11:07 PM, Dave Angel wrote: On 02/03/2013 02:26 PM, Spyros Charonis wrote: Hello Pythoners, I am experiencing a strange result with the pickle module when using it to write certain results to a separate file. In short, I have a program that reads a file, finds lines which satisfy some criteria, and extracts those lines, storing them in a list. I am trying to write this list to a separate file. The list of extracted lines looks like this: ATOM 1 N GLN A 1 29.872 13.384 54.754 1.00 60.40 N ATOM 2 CA GLN A 1 29.809 11.972 54.274 1.00 58.51 C ATOM 3 C GLN A 1 28.376 11.536 54.029 1.00 55.13 C The output stored from the call to the pickle.dump method, however, looks like this: (lp0 S'ATOM 1 N GLN A 1 29.872 13.384 54.754 1.00 60.40 N \r\n' p1 aS'ATOM 2 CA GLN A 1 29.809 11.972 54.274 1.00 58.51 C \r\n' p2 aS'ATOM 3 C GLN A 1 28.376 11.536 54.029 1.00 55.13 C \r\n' The code I am using to write the output to an external file goes as follows: def export_antibody_chains(): ''' EXPORT LIST OF EXTRACTED CHAINS TO FILE ''' chains_file = open(query + '_Chains', 'wb') pickle.dump(ab_chains, chains_file) # ab_chains is global chains_file.close() return Does anyone know why the strings lp0, S', aS' are showing up? Pickle stores the type of each variable, as well as the value, and stores it in a way as to make it easy to "unpickle" it. On 02/03/2013 06:17 PM, Spyros Charonis wrote: Thank you Dave, Is there any way to circumvent this so that I get the list rendered normally? Many thanks. You'd better define "normally." Pickle's output is normal for pickle. Perhaps you want the values to be human readable instead. One possibility of many: If you know that all the values in the list are strings, and you want to produce a text file, with one such string per line, then try: outfile = open( "filename.txt", 'wt") for line in mylist: outfile.write( line + "\n") outfile.close() There are ways to clean that up, but since you haven't specified your python version, that'll do for a first attempt. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pickle.dump yielding awkward output
On 02/03/2013 02:26 PM, Spyros Charonis wrote: Hello Pythoners, I am experiencing a strange result with the pickle module when using it to write certain results to a separate file. In short, I have a program that reads a file, finds lines which satisfy some criteria, and extracts those lines, storing them in a list. I am trying to write this list to a separate file. The list of extracted lines looks like this: ATOM 1 N GLN A 1 29.872 13.384 54.754 1.00 60.40 N ATOM 2 CA GLN A 1 29.809 11.972 54.274 1.00 58.51 C ATOM 3 C GLN A 1 28.376 11.536 54.029 1.00 55.13 C The output stored from the call to the pickle.dump method, however, looks like this: (lp0 S'ATOM 1 N GLN A 1 29.872 13.384 54.754 1.00 60.40 N \r\n' p1 aS'ATOM 2 CA GLN A 1 29.809 11.972 54.274 1.00 58.51 C \r\n' p2 aS'ATOM 3 C GLN A 1 28.376 11.536 54.029 1.00 55.13 C \r\n' The code I am using to write the output to an external file goes as follows: def export_antibody_chains(): ''' EXPORT LIST OF EXTRACTED CHAINS TO FILE ''' chains_file = open(query + '_Chains', 'wb') pickle.dump(ab_chains, chains_file) # ab_chains is global chains_file.close() return Does anyone know why the strings lp0, S', aS' are showing up? Pickle stores the type of each variable, as well as the value, and stores it in a way as to make it easy to "unpickle" it. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] More Help
On 04/02/13 06:15, Jack Little wrote: So I have gotten responses to my previous email sent 3 days ago, all saying define path1pt1() before simpstart, but I do not know how. Help? You have something like this: ...code... ...more code... path1pt1() ... ... def path1pt1(): definition goes here Select the text starting with "def path1pt1" in your text editor, and ending with the end of the function. Then cut the text (Ctrl-X), move the cursor to the top of the file, and paste it (Ctrl-V). Clean up any extra blank lines needed. Your code should then look like this: def path1pt1(): definition goes here ...code... ...more code... path1pt1() ... ... -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] More Help
On Sun, Feb 3, 2013 at 2:29 PM, Joel Goldstick wrote: > Move the code that defines path1pt1 above the function that calls it. > > Also, don't start of new thread -- you are making it impossible for > someone to know the context of your question. Also, Use a better subject > line > > > On Sun, Feb 3, 2013 at 2:15 PM, Jack Little wrote: > >> So I have gotten responses to my previous email sent 3 days ago, all >> saying define path1pt1() before simpstart, but I do not know how. Help? >> >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> >> I was curious about this post, and so I looked back through your previous posts. They all seem to be about getting this game code to work. I'm guessing that you copied it from somewhere -- or mostly copied it. You don't seem to have a grasp of basic concepts of programming in python. This seems to be a good example of cargo cult programming http://en.wikipedia.org/wiki/Cargo_cult_programming I suggest you set aside this project and go to the python online tutorial, or use Alan's book http://www.alan-g.me.uk/ , or google for Leaning Python the hard way, and get some basic concepts together in your mind. Also, set your mail client to text -- not rich text or html. Since indentation in python is essential to the meaning of the code, using rich text which often mangles indentation makes your examples impossible to decipher. When you've done that you will be able to ask question here that will help you learn more and raise your skill level. > > > -- > Joel Goldstick > http://joelgoldstick.com > -- Joel Goldstick http://joelgoldstick.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] More Help
Move the code that defines path1pt1 above the function that calls it. Also, don't start of new thread -- you are making it impossible for someone to know the context of your question. Also, Use a better subject line On Sun, Feb 3, 2013 at 2:15 PM, Jack Little wrote: > So I have gotten responses to my previous email sent 3 days ago, all > saying define path1pt1() before simpstart, but I do not know how. Help? > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Joel Goldstick http://joelgoldstick.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] pickle.dump yielding awkward output
Hello Pythoners, I am experiencing a strange result with the pickle module when using it to write certain results to a separate file. In short, I have a program that reads a file, finds lines which satisfy some criteria, and extracts those lines, storing them in a list. I am trying to write this list to a separate file. The list of extracted lines looks like this: ATOM 1 N GLN A 1 29.872 13.384 54.754 1.00 60.40 N ATOM 2 CA GLN A 1 29.809 11.972 54.274 1.00 58.51 C ATOM 3 C GLN A 1 28.376 11.536 54.029 1.00 55.13 C The output stored from the call to the pickle.dump method, however, looks like this: (lp0 S'ATOM 1 N GLN A 1 29.872 13.384 54.754 1.00 60.40 N \r\n' p1 aS'ATOM 2 CA GLN A 1 29.809 11.972 54.274 1.00 58.51 C \r\n' p2 aS'ATOM 3 C GLN A 1 28.376 11.536 54.029 1.00 55.13 C \r\n' The code I am using to write the output to an external file goes as follows: def export_antibody_chains(): ''' EXPORT LIST OF EXTRACTED CHAINS TO FILE ''' chains_file = open(query + '_Chains', 'wb') pickle.dump(ab_chains, chains_file) # ab_chains is global chains_file.close() return Does anyone know why the strings lp0, S', aS' are showing up? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] More Help
So I have gotten responses to my previous email sent 3 days ago, all saying define path1pt1() before simpstart, but I do not know how. Help?___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] First Python Test
On 03/02/13 12:20, Shall, Sydney wrote: Dear Alan, I installed Cocoa emacs successfully. But it does not run on OS X 10.6.8. The notes with it say that it was built for 10.4. Sofware built for 10.4 should run fine on 10.6. But I only have 10.4 so can't do any testing... Not sure why its broke, but thee are several variants to choose from, somebody said aquamacs, there are others too. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] First Python Test
--> Shall, Sydney [2013-02-02 12:45:15 +]: > Two free good text editors for the MAC are; > 1. Komodo > 2. Text Wrangler. > hth > Sydney aquamacs is the correct gui version to use. There is also a gvim binary available. Both emacs and vim are installed already on Mac OS X but in text only versions, no GUI. I have never used Komodo or Text Wrangler, or any other GUI editor for that matter so I cannot comment on how good they are. I tend to spend about 90% of my time using the command-line on my Mac, but that's just my preference. Some people prefer GUI editors. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] First Python Test
Thanks Jonatan. Sydney On 03/02/2013 13:13, Jonatán Guadamuz wrote: El 03/02/2013, a las 06:53 a.m., "Shall, Sydney" escribió: Dear Alan, I installed Cocoa emacs successfully. But it does not run on OS X 10.6.8. The notes with it say that it was built for 10.4. Where may I look for an update, please? With many thanks for your help. Sydney Maybe you can look here aquamacs.org -- Professor Sydney Shall, Department of Haematological Medicine, King's College London, Medical School, 123 Coldharbour Lane, LONDON SE5 9NU, Tel & Fax: +44 (0)207 848 5902, E-Mail: sydney.shall, [correspondents outside the College should add; @kcl.ac.uk] www.kcl.ac.uk ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] First Python Test
El 03/02/2013, a las 06:53 a.m., "Shall, Sydney" escribió: > Dear Alan, > I installed Cocoa emacs successfully. > But it does not run on OS X 10.6.8. > The notes with it say that it was built for 10.4. > Where may I look for an update, please? > With many thanks for your help. > Sydney Maybe you can look here aquamacs.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] First Python Test
Dear Alan, I installed Cocoa emacs successfully. But it does not run on OS X 10.6.8. The notes with it say that it was built for 10.4. Where may I look for an update, please? With many thanks for your help. Sydney On 02/02/2013 17:49, Alan Gauld wrote: On 02/02/13 12:57, Shall, Sydney wrote: Dear Aurelien, Would you please explain how one installs GNU Emacs on a MAC using OS X v10.6. Last time I looked it was already installed. Just type emacs at a Terminal prompt. You can also get a Cocoa version that run in a separate Window, try Google for Cocoa emacs... -- Professor Sydney Shall, Department of Haematological Medicine, King's College London, Medical School, 123 Coldharbour Lane, LONDON SE5 9NU, Tel & Fax: +44 (0)207 848 5902, E-Mail: sydney.shall, [correspondents outside the College should add; @kcl.ac.uk] www.kcl.ac.uk ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor