Re: [Tutor] Help- Regarding python

2013-02-04 Thread Alan Gauld

On 04/02/13 06:24, Gayathri S wrote:

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

...

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?


No idea. I don't know what pca or princomp are.
It looks like they might be numpy or pylab functions in which case you 
probably will get better results posting on a forum for those modules.

This list is for learning the core language and standard library.

Having said that it looks like you could use some time learning the 
basics before delving into numpy etc. comments below...



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


You have a return that is not inside a function. That makes no sense
and in fact I get a syntax error so presumably you haven't actually 
tried running this code.



princomp(A):


This calls princomp() but does nothing with the return values


coeff, score, latent = princomp(A.T)


This calls princomp() and stores 3 return values.
Its unusual for a function to have such different semantics.
Which is correct?


figure()
subplot(121)


Again calling functions without storing values. It may be valid
but looks unlikely...


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()


Here you use plt but plt is not defined anywhere in your program.

I think you need to go back to Python basics and learn
how to write basic code before trying to use the more
exotic modules.

--
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

2013-02-04 Thread Spyros Charonis
Thank you Alan, Steven,

I don't care about the characters from the pickle operation per se, I just
want the list to be stored in its native format.

What I am trying to do is basically the Unix shell equivalent of: "Unix
command" > newfile.txt

I am trying to store the list that I get from my code in a separate file,
in human-readable format.


On Mon, Feb 4, 2013 at 1:03 AM, Alan Gauld wrote:

> 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
>
___
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

2013-02-04 Thread Alan Gauld

On 04/02/13 11:12, Spyros Charonis wrote:


What I am trying to do is basically the Unix shell equivalent of: "Unix
command" > newfile.txt


That works just fine with Python too. Just print to stdout in whatever 
format you want and redirect the output to a file



$ python myscript.py > myfile.txt

That will work from a command line in Windows, Linux and MacOS...


I am trying to store the list that I get from my code in a separate
file, in human-readable format.


Then print it in the format you want using string formatting to control 
spacing, justification etc.



--
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

2013-02-04 Thread Steven D'Aprano

On 04/02/13 22:12, Spyros Charonis wrote:

Thank you Alan, Steven,

I don't care about the characters from the pickle operation per se, I just
want the list to be stored in its native format.


That's an in-memory binary format. There is no way to get access to that from
pure Python code. You may be able to do it using the ctypes module, which is
an interface to the underlying C implementation. But keep in mind that this
is only in the CPython implementation, and will not work in IronPython, PyPy
or Jython.



What I am trying to do is basically the Unix shell equivalent of: "Unix
command">  newfile.txt


In Unix commands, virtually everything is text. Python is not like that --
everything is a binary object.

But you can get a text representation of Python objects, e.g. a list, with:

print repr(mylist)



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help- Regarding python

2013-02-04 Thread Steven D'Aprano

On 04/02/13 17:24, Gayathri S wrote:

Hi All!
 If i have data set like this means...

3626,5000,2918,5000,2353,2334,2642,[...],496.


No need to dump your entire data set on us. Just a few representative
values will do.



How to do PCA on this data? if it is in array how to do that? and also how
to use princomp() in PCA?


What's PCA? What's princomp?



Shall i use the following code for doing PCA on given input? could you tell
me?


Have you tried it? What happens?

This is a list for people learning Python the programming language. We are not
experts on numpy, which is a specialist package for scientific use. We are not
statisticians either. You can probably assume that most of us know what
"standard deviation" is. Anything more complicated than that, you should ask
on a specialist numpy mailing list.

Good luck!



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First Python Test

2013-02-04 Thread David Rock
* Shall, Sydney  [2013-02-03 16:47]:
> 
> 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

The first hit I get googling for "cocoa emacs" returns:
http://emacsformacosx.com/

Perhaps that will work for you.  I've tested that it works on my system,
at least ("works" = it ran).

-- 
David Rock
da...@graniteweb.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] nose, git, post-commit hook

2013-02-04 Thread Albert-Jan Roskam
Hi,

I am using git VCS and I read about the possibility to use post-commit hooks 
for nose tests. That sounds pretty cool, but does this also have disadvantages?
It would be very annoying if I couldn't check in code, safely tucked away on 
some server, that is not yet working. Is there also a way to by-pass the 
'mandatory' tests?

 
Regards,
Albert-Jan


~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a 
fresh water system, and public health, what have the Romans ever done for us?
~~ 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First Python Test

2013-02-04 Thread Shall, Sydney

Dear David,
Many thanks for this information.
It was exactly what I needed.
It anyone wants Emacs editor for MAC OS X 10.6, this is the place to 
find it.


I would also like to say that I am deeply impressed with the knowledge 
and generosity of the people on this list.

Thanks.
Sydney




On 04/02/2013 14:58, David Rock wrote:

* Shall, Sydney  [2013-02-03 16:47]:

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

The first hit I get googling for "cocoa emacs" returns:
http://emacsformacosx.com/

Perhaps that will work for you.  I've tested that it works on my system,
at least ("works" = it ran).




--
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


[Tutor] Iterating a dict with an iteration counter? How would *you* do it?

2013-02-04 Thread Modulok
List,

Simple question: Is there a common pattern for iterating a dict, but also
providing access to an iteration counter? Here's what I usually do (below). I'm
just wondering if there are other, more clever ways::

data = {'a': "apple", 'b': "banana", 'c': "cherry"}
i = 0
for k,v in data.items():
print("i: %s, k: %s, v: %s" % (i,k,v))
i += 1

Another variant, same idea::

data = {'a': "apple", 'b': "banana", 'c': "cherry"}
for i,k,v in zip(range(len(data)), data.keys(), data.values()):
print("i: %s, k: %s, v: %s" % (i,k,v))


How would you do it?
-Modulok-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating a dict with an iteration counter? How would *you* do it?

2013-02-04 Thread Dave Angel

On 02/04/2013 12:13 PM, Modulok wrote:

List,

Simple question: Is there a common pattern for iterating a dict, but also
providing access to an iteration counter? Here's what I usually do (below). I'm
just wondering if there are other, more clever ways::

 data = {'a': "apple", 'b': "banana", 'c': "cherry"}
 i = 0
 for k,v in data.items():
 print("i: %s, k: %s, v: %s" % (i,k,v))
 i += 1

Another variant, same idea::

 data = {'a': "apple", 'b': "banana", 'c': "cherry"}
 for i,k,v in zip(range(len(data)), data.keys(), data.values()):
 print("i: %s, k: %s, v: %s" % (i,k,v))


How would you do it?
-Modulok-


enumerate()


for i, (k, v) in enumerate(data.items()):

--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] nose, git, post-commit hook

2013-02-04 Thread Rob Day
On 4 February 2013 15:32, Albert-Jan Roskam  wrote:
> I am using git VCS and I read about the possibility to use post-commit hooks 
> for nose tests. That sounds pretty cool, but does this also have 
> disadvantages?
> It would be very annoying if I couldn't check in code, safely tucked away on 
> some server, that is not yet working. Is there also a way to by-pass the 
> 'mandatory' tests?

This isn't really a Python question, but if you use pre-commit hooks,
you can bypass them with the "--no-verify" option to "git commit". See
http://git-scm.com/book/en/Customizing-Git-Git-Hooks.


--
Robert K. Day
robert@merton.oxon.org
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2013-02-04 Thread Ghadir Ghasemi
hi guys, this is the first bit of my program converting from binary to decimal 
without use of built in functions.

binnum = input("Please enter a binary number:  ")
decnum = 0
rank = 1

for i in reversed(binnum):
decnum += rank * int(i)
rank *= 2
print(decnum).

When I first tested the program, It printed the answer in a weird way. you can 
see the print screen of first tirst in the attachment. I wanted to know how I 
could adjust the program so that
it only prints the real answer. e.g If user enters , then program 
should only print 255.
thank you.<>___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating a dict with an iteration counter? How would *you* do it?

2013-02-04 Thread Modulok
Hmm.. no kidding. Well, at least I knew I was over-complicating it.

Cheers!
-Modulok-


On 2/4/13, Dave Angel  wrote:
> On 02/04/2013 12:13 PM, Modulok wrote:
>> List,
>>
>> Simple question: Is there a common pattern for iterating a dict, but also
>> providing access to an iteration counter? Here's what I usually do
>> (below). I'm
>> just wondering if there are other, more clever ways::
>>
>>  data = {'a': "apple", 'b': "banana", 'c': "cherry"}
>>  i = 0
>>  for k,v in data.items():
>>  print("i: %s, k: %s, v: %s" % (i,k,v))
>>  i += 1
>>
>> Another variant, same idea::
>>
>>  data = {'a': "apple", 'b': "banana", 'c': "cherry"}
>>  for i,k,v in zip(range(len(data)), data.keys(), data.values()):
>>  print("i: %s, k: %s, v: %s" % (i,k,v))
>>
>>
>> How would you do it?
>> -Modulok-
>
> enumerate()
>
>
> for i, (k, v) in enumerate(data.items()):
>
> --
> DaveA
> ___
> 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] (no subject)

2013-02-04 Thread Kwpolska
On Mon, Feb 4, 2013 at 6:52 PM, Ghadir Ghasemi
 wrote:
> hi guys, this is the first bit of my program converting from binary to 
> decimal without use of built in functions.
>
> binnum = input("Please enter a binary number:  ")
> decnum = 0
> rank = 1
>
> for i in reversed(binnum):
> decnum += rank * int(i)
> rank *= 2
> print(decnum).
>
> When I first tested the program, It printed the answer in a weird way. you 
> can see the print screen of first tirst in the attachment. I wanted to know 
> how I could adjust the program so that
> it only prints the real answer. e.g If user enters , then program 
> should only print 255.
> thank you.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Move the print out of the loop.  Also, do not post screenshots, use
copy-paste.  So, this becomes:

binnum = input("Please enter a binary number: ")
decnum = 0
rank = 1

for i in reversed(binnum):
decnum += rank * int(i)
rank *= 2

print(decnum)

-- 
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help- Regarding python

2013-02-04 Thread Danny Yoo
> How to do PCA on this data? if it is in array how to do that? and also how
> to use princomp() in PCA?


Principal component analysis,

http://en.wikipedia.org/wiki/Principal_component_analysis

may not be "built in".  Do you know for sure that it is?  According to
this blog entry, you can do it in numpy by coding the algorithm:


http://glowingpython.blogspot.com/2011/07/principal-component-analysis-with-numpy.html

If you use Google and search for the term "Principal component
analysis Python", you should see several implementations of modules
that provide that algorithm.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating a dict with an iteration counter? How would *you* do it?

2013-02-04 Thread Dave Angel

On 02/04/2013 12:58 PM, Modulok wrote:

Hmm.. no kidding. Well, at least I knew I was over-complicating it.

Cheers!
-Modulok-



Please don't top-post.

Another point.  I don't currently have Python 3.x installed, but I seem 
to remember that in Python 3 you can use the dict itself as an iterator 
providing both key and value.  If I'm right, then it could be simplified 
further to:



for i, (k, v) in enumerate(data):

A simple test will prove me right or wrong.


--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating a dict with an iteration counter? How would *you* do it?

2013-02-04 Thread Steven D'Aprano

On 05/02/13 09:26, Dave Angel wrote:


Another point. I don't currently have Python 3.x installed, but I seem to
remember that in Python 3 you can use the dict itself as an iterator
providing both key and value. If I'm right, then it could be simplified
further to:


for i, (k, v) in enumerate(data):


Nope, in both Python 2 and 3 iterating over a dict directly just provides the
key. That's also how "if key in dict" works.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating a dict with an iteration counter? How would *you* do it?

2013-02-04 Thread Dave Angel

On 02/04/2013 06:18 PM, Steven D'Aprano wrote:

On 05/02/13 09:26, Dave Angel wrote:


Another point. I don't currently have Python 3.x installed, but I seem to
remember that in Python 3 you can use the dict itself as an iterator
providing both key and value. If I'm right, then it could be simplified
further to:


for i, (k, v) in enumerate(data):


Nope, in both Python 2 and 3 iterating over a dict directly just
provides the
key. That's also how "if key in dict" works.



Then I'm glad I was tentative about it.  I do recall there was some 
difference.  Was it just that items(), keys() and values() methods 
return a view (iterator) instead of a list, and the iter*() versions are 
gone?


--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help- Regarding python

2013-02-04 Thread Oscar Benjamin
On 4 February 2013 06:24, Gayathri S  wrote:
> 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.

PCA only makes sense for multivariate data: your data should be a set
of vectors *all of the same length*. I'll assume that you were just
being lazy when you posted it and that you didn't bother to copy the
first and last lines properly...

[snip]
>
> Shall i use the following code for doing PCA on given input? could you tell
> me?

This code you posted is all screwed up. It will give you errors if you
try to run it.

Also I don't really know what you mean by "doing PCA". The code below
transforms your data into PCA space and plots a 2D scatter plot using
the first two principal components.

#!/usr/bin/env python
import numpy as np
from matplotlib import pyplot as plt

data = np.array([

[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],
])

# Compute the eigenvalues and vectors of the covariance matrix
C = np.cov(data.T)
eigenvalues, eigenvectors = np.linalg.eig(C)

# 2D PCA - get the two eigenvectors with the largest eigenvalues
v1, v2 = eigenvectors[:,:2].T
# Project the data onto the two principal components
data_pc1 = [np.dot(v1, d) for d in data]
data_pc2 = [np.dot(v2, d) for d in data]

# Scatter plot in PCA space
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(data_pc1, data_pc2, 'x')
ax.set_xlabel(r'$PC_1$')
ax.set_ylabel(r'$PC_2$')
ax.legend(['data'])
plt.show()


Oscar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating a dict with an iteration counter? How would *you* do it?

2013-02-04 Thread eryksun
On Mon, Feb 4, 2013 at 7:04 PM, Dave Angel  wrote:
>> Nope, in both Python 2 and 3 iterating over a dict directly just
>> provides the key. That's also how "if key in dict" works.

A dict implements __contains__ for an efficient "in" test. In general,
the interpreter falls back to using iteration if a type lacks
__contains__.

In 2.x iter(some_dict) returns a dictionary-keyiterator (weird
hyphen). In 3.x it's a dict_keyiterator (normal underscore).

> Was it just that items(), keys() and values() methods return a view
> (iterator) instead of a list, and the iter*() versions are gone?

In 3.x, keys() and items() return views that are iterable (__iter__)
and that implement the sequence methods __len__ and __contains__ as
well as a few set operations that return a set: intersection (&),
union (|), difference (-), and symmetric difference (^). Using the set
methods for items() requires the values to also be hashable. The view
returned by values() doesn't bother implementing __contains__ and the
set operations, but it does have __iter__ and __len__. 2.7 provides
these views via viewkeys(), viewitems(), and viewvalues().

The corresponding iterators returned by iter() in 3.x are
dict_keyiterator, dict_itemiterator, and dict_valueiterator.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2013-02-04 Thread heathen

On 02/04/2013 12:52 PM, Ghadir Ghasemi wrote:

hi guys, this is the first bit of my program converting from binary to decimal 
without use of built in functions.

binnum = input("Please enter a binary number:  ")
decnum = 0
rank = 1

for i in reversed(binnum):
 decnum += rank * int(i)
 rank *= 2
 print(decnum).

When I first tested the program, It printed the answer in a weird way. you can 
see the print screen of first tirst in the attachment. I wanted to know how I 
could adjust the program so that
it only prints the real answer. e.g If user enters , then program 
should only print 255.
thank you.



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Move your print statement out of the for loop.

for i in reversed(binnum):
  decnum += rank * int(i)
  rank *= 2
print(decnum)

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help- Regarding python

2013-02-04 Thread eryksun
On Mon, Feb 4, 2013 at 7:21 PM, Oscar Benjamin
 wrote:
> eigenvalues, eigenvectors = np.linalg.eig(C)

First sort by eigenvalue magnitude:

>>> idx = np.argsort(eigenvalues)[::-1]
>>> print idx
[ 0  1  2  3  8 10 11 12 14 22 20 21 18 19 23 24 17 16 15 13  9  7  5  6  4]

>>> eigenvalues = eigenvalues[idx]
>>> eigenvectors = eigenvectors[:, idx]

> # 2D PCA - get the two eigenvectors with the largest eigenvalues
> v1, v2 = eigenvectors[:,:2].T
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor