Monday, January 20, 2014

comp.lang.python - 26 new messages in 9 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* Help with simple code that has database defined - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/b71867faf4711297?hl=en
* question about input() and/or raw_input() - 11 messages, 6 authors
http://groups.google.com/group/comp.lang.python/t/310565f7979cee4c?hl=en
* graphical python - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/fbe4c24dcdbb015d?hl=en
* Can post a code but afraid of plagiarism - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/bb644bb09fed1442?hl=en
* Beginner Tutorials - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/ed9cc82315e6c3e6?hl=en
* python to enable javascript , tried selinium, ghost, pyQt4 already - 1
messages, 1 author
http://groups.google.com/group/comp.lang.python/t/a453f34131ad9343?hl=en
* Python declarative - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/d3cb0aca7152f06f?hl=en
* python-daemon for Python v3 - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/f93a6aca18b45b46?hl=en
* Need help vectorizing code - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/f48ecb4266405add?hl=en

==============================================================================
TOPIC: Help with simple code that has database defined
http://groups.google.com/group/comp.lang.python/t/b71867faf4711297?hl=en
==============================================================================

== 1 of 2 ==
Date: Sat, Jan 18 2014 6:23 pm
From: indar kumar


I have to save students information in a database that is keeping continuously track of the information. Format is as follows:
Information: <name> <course> <grade> <duration>

Note: if this name already exists there in database, just update the information of that(name) e.g course,grade and date. Otherwise, add it.

What I think:

Database={} #First Created a dictionary that will keep track
z = "Enter student name, course, grade and duration: "
line = raw_input(z)
while (line != "quit"):
data = line.split()
name = data[0]
line = raw_input(z)

This is just part because this is what I know how to do, for rest have no idea

The output should be like this:
{'alex': ['7', '8', '6'], 'john': ['9', '8', '7']})

Now as program will continuously prompt for input. If user enters "quit" it would exit. Otherwise it keeps taking input.

Now if there is already a name existing for example "alex" and his course, grade and duration are 7,8,6. Now in next turn of input if user again enters the name as alex but different entries for him e.g 9,9,9 so it should replace the older info by new e.g. it should replace 7,8,6 for alex by 9,9,9 and if user enters a entirely new name that is not in dictionary then it should be added to dictionary for example nancy 6 6 6 is the input then output should be:

{'alex': ['7', '8', '6'], 'john': ['9', '8', '7'],'nancy':['6','6','6']})


Kindly help.




== 2 of 2 ==
Date: Sat, Jan 18 2014 8:14 pm
From: Dennis Lee Bieber


On Sat, 18 Jan 2014 18:23:01 -0800 (PST), indar kumar
<indarkumar59@gmail.com> declaimed the following:

>I have to save students information in a database that is keeping continuously track of the information. Format is as follows:
>Information: <name> <course> <grade> <duration>
>

This is your third request in 24 hours... You've gone from a
description of just simple one-line inputs to produce a simple GPA output
up to something with persistence (meaning you need to have a data file of
some sort between invocations of the program), and additional data fields.

>Kindly help.

As you've been told, we do NOT do homework assignments (and if this is
NOT a homework assignment but an actual application for keeping student
grades for some school I strongly recommend you give them back whatever
money they paid you).

Ask a question about some aspect of Python that may not be understood,
and we'll give you an answer. "I need a program that does xyz, help!" will
not produce any results -- that's your job to do.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/






==============================================================================
TOPIC: question about input() and/or raw_input()
http://groups.google.com/group/comp.lang.python/t/310565f7979cee4c?hl=en
==============================================================================

== 1 of 11 ==
Date: Sat, Jan 18 2014 6:17 pm
From: Dennis Lee Bieber


On Sat, 18 Jan 2014 13:30:20 -0500, Roy Smith <roy@panix.com> declaimed the
following:

>Pardon me for being cynical, but in the entire history of the universe,
>has anybody ever used input()/raw_input() for anything other than a
>homework problem?

Quite often... Most of my "applications" are short things that don't
justify the effort of a GUI, but don't fit the command-line option only
mode of usage. raw_input() works quite well with providing user prompts.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/





== 2 of 11 ==
Date: Sat, Jan 18 2014 6:46 pm
From: Chris Angelico


On Sun, Jan 19, 2014 at 8:33 AM, Terry Reedy <tjreedy@udel.edu> wrote:
> On 1/18/2014 1:30 PM, Roy Smith wrote:
>>
>> Pardon me for being cynical, but in the entire history of the universe,
>> has anybody ever used input()/raw_input() for anything other than a
>> homework problem?
>
>
> Homework problems (and 'toy' programs, such as hangman), whether in a
> programming class or elsewhere, are one of the intended use cases of Python.
> How else would you get interactive input without the complexity of a gui?

With the network :) I've written plenty of programs whose sole
interaction is via sockets (telnet, HTTP, SMTP, whatever), or a
database, or somesuch.

But I've also written my share of interactive programs that use the
console. Plenty of programs don't need the fanciness of a GUI, but
need to prompt the user for stuff. If I write something for my brother
(and only him), I'm inclined to spend less effort on the UI than I
would for something of wide distribution, and console I/O is
approximately zero effort.

BTW, I'm assuming your mention of "input()/raw_input()" is covering
Py3 and Py2, respectively. I have *never* used input() in live Py2
code, and never intend to. It's way too subtle. On those really rare
occasions when you actually want to take something from the user and
immediately eval it, the extra keystrokes for eval(raw_input()) are,
IMO, a small price for the clarity.

ChrisA




== 3 of 11 ==
Date: Sat, Jan 18 2014 8:15 pm
From: Rustom Mody


On Sunday, January 19, 2014 12:00:20 AM UTC+5:30, Roy Smith wrote:
> Pardon me for being cynical, but in the entire history of the universe,
> has anybody ever used input()/raw_input() for anything other than a
> homework problem?

Similar 'cynicism' regarding print would be salutary for producing better programmers

[If youve taught programming and had to deal with code strewn with prints...]





== 4 of 11 ==
Date: Sat, Jan 18 2014 8:21 pm
From: Chris Angelico


On Sun, Jan 19, 2014 at 3:15 PM, Rustom Mody <rustompmody@gmail.com> wrote:
> On Sunday, January 19, 2014 12:00:20 AM UTC+5:30, Roy Smith wrote:
>> Pardon me for being cynical, but in the entire history of the universe,
>> has anybody ever used input()/raw_input() for anything other than a
>> homework problem?
>
> Similar 'cynicism' regarding print would be salutary for producing better programmers
>
> [If youve taught programming and had to deal with code strewn with prints...]

Why, exactly? How ought a program to produce filterable output?

ChrisA




== 5 of 11 ==
Date: Sat, Jan 18 2014 8:43 pm
From: Rustom Mody


On Sunday, January 19, 2014 9:51:36 AM UTC+5:30, Chris Angelico wrote:
> On Sun, Jan 19, 2014 at 3:15 PM, Rustom Mody wrote:
> > On Sunday, January 19, 2014 12:00:20 AM UTC+5:30, Roy Smith wrote:
> >> Pardon me for being cynical, but in the entire history of the universe,
> >> has anybody ever used input()/raw_input() for anything other than a
> >> homework problem?
> > Similar 'cynicism' regarding print would be salutary for producing better programmers
> > [If youve taught programming and had to deal with code strewn with prints...]

> Why, exactly? How ought a program to produce filterable output?

Because these two pieces of code

>>> def foo(x): print x+1

>>> def bar(x): return x+1

look identical (to a beginner at least)

>>> foo(3)
4
>>> bar(3)
4
>>>

And so if they see prints used cavalierly for demo purposes, they think the
prints are also ok for production.

As a professional programmer, you would of course understand
- 'normal' code that does some processing and then some output should not
have prints in the processing
- web-serving (type of) code that has little other than heavy-duty printing
should probably use a template engine of some sort

In any case prints all over is a code-smell
exacerbated by the way that manuals/examples need to be written




== 6 of 11 ==
Date: Sat, Jan 18 2014 8:59 pm
From: Chris Angelico


On Sun, Jan 19, 2014 at 3:43 PM, Rustom Mody <rustompmody@gmail.com> wrote:
> Because these two pieces of code
>
>>>> def foo(x): print x+1
>
>>>> def bar(x): return x+1
>
> look identical (to a beginner at least)
>
>>>> foo(3)
> 4
>>>> bar(3)
> 4
>>>>

As do these pieces of code:

>>> def quux(x): return str(x+1)
>>> def quux(x): return hex(x+1)[2:]

But we don't decry hex or str because of it. Every function has its
use and purpose. If someone uses the wrong tool for the job, s/he will
have to figure that out at some point - it doesn't mean the tool is
wrong.

If you're not using the REPL, print is critical. Don't assume everyone
uses interactive mode.

ChrisA




== 7 of 11 ==
Date: Sat, Jan 18 2014 10:24 pm
From: Steven D'Aprano


On Sat, 18 Jan 2014 13:30:20 -0500, Roy Smith wrote:

> Pardon me for being cynical, but in the entire history of the universe,
> has anybody ever used input()/raw_input() for anything other than a
> homework problem?

Yes. They are excellent for interactive command line tools.


--
Steven




== 8 of 11 ==
Date: Sun, Jan 19 2014 12:26 am
From: Rustom Mody


On Sunday, January 19, 2014 10:29:58 AM UTC+5:30, Chris Angelico wrote:
> On Sun, Jan 19, 2014 at 3:43 PM, Rustom Mody wrote:
> > Because these two pieces of code
> >>>> def foo(x): print x+1
> >>>> def bar(x): return x+1
> > look identical (to a beginner at least)
> >>>> foo(3)
> > 4
> >>>> bar(3)
> > 4

> As do these pieces of code:

> >>> def quux1(x): return str(x+1)
> >>> def quux2(x): return hex(x+1)[2:]

They do?

>>> quux1(2.3)
'3.3'

>>> quux2(2.3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in quux2
TypeError: hex() argument can't be converted to hex


If you want to give an irrelevant example at least give a correct one :D
the difference between str and hex is an arcane difference (Ive never used hex)
the difference between functions and procedures is absolutely basic.

And python is worse than not just academic languages like haskell in this
respect but even worse than C/Pascal etc.

In Pascal, the difference between procedure and function is
fundamental to the lang and is key to Pascal being good for academic
purposes.

In C, the difference is not so well marked but at least trivial
code-examples found in books/the net wont run straight-off without
some main-printf-etc boiler-plate.

In python lots of easy to check examples run straight off --
convenient for programmers of course but a headache for teachers who
are trying to set habits of minimal hygiene

> But we don't decry hex or str because of it. Every function has its
> use and purpose. If someone uses the wrong tool for the job, s/he will
> have to figure that out at some point - it doesn't mean the tool is
> wrong.

> If you're not using the REPL, print is critical. Don't assume everyone
> uses interactive mode.

"Everyone uses interactive mode" is of course an unreasonable assumption
"Everyone needs to learn (something or other at some time or other)" is not

And print (especially in python) screws up the learning-curve

tl;dr
You are wearing 'professional programmer' hat
I am wearing 'teacher' hat
Not sure what hat Roy or Steven are wearing




== 9 of 11 ==
Date: Sun, Jan 19 2014 2:39 am
From: Chris Angelico


On Sun, Jan 19, 2014 at 7:26 PM, Rustom Mody <rustompmody@gmail.com> wrote:
> If you want to give an irrelevant example at least give a correct one :D
> the difference between str and hex is an arcane difference (Ive never used hex)
> the difference between functions and procedures is absolutely basic.

They don't give the same result for every possible input, any more
than your two do:

>>> foo(1.234567890123456)
2.23456789012
>>> bar(1.234567890123456)
2.234567890123456

(Tested on 2.7.3 on Linux. YMMV.)

There's no difference in Python between functions and procedures. It's
all functions, and some of them implicitly return None. If there were
a difference, what would this be?

def none_if(value, predicate):
if not predicate(value): return value

Personally, I'm quite happy with Python and the print function. (Or
statement, if you prefer. Same difference.) The most fundamental
aspects of any program are input, output, and preferably some
computation in between; and the most fundamental forms of input are
the command line / console and the program's source, and the most
basic output is the console. So the most basic and obvious program
needs:

1) Access to the command-line arguments
2) The ability to read from the console
3) Some means of writing to the console.

Not every program will need all that, but they'd be the most obvious
and simplest methods of communication - especially since they're the
three that are easiest to automate. How do you run a GUI program
through automated testing? With difficulty. How do you run a stdio
program through automated testing? Pipe it some input and compare its
output to the standard. And that means people should be accustomed to
using print, and sys.argv, and (raw_)input.

Fortunately Python doesn't have ob_start() / ob_get_clean() to tempt
people to use print when they should use return. So there's no
problem.

ChrisA




== 10 of 11 ==
Date: Sun, Jan 19 2014 8:14 am
From: Grant Edwards


On 2014-01-18, Terry Reedy <tjreedy@udel.edu> wrote:
> On 1/18/2014 1:30 PM, Roy Smith wrote:
>> Pardon me for being cynical, but in the entire history of the universe,
>> has anybody ever used input()/raw_input() for anything other than a
>> homework problem?
>
> Homework problems (and 'toy' programs, such as hangman), whether in a
> programming class or elsewhere, are one of the intended use cases of
> Python. How else would you get interactive input without the complexity
> of a gui?

sys.stdin.readline()





== 11 of 11 ==
Date: Sun, Jan 19 2014 8:14 am
From: Ethan Furman


On 01/19/2014 12:26 AM, Rustom Mody wrote:
> On Sunday, January 19, 2014 10:29:58 AM UTC+5:30, Chris Angelico wrote:
>> On Sun, Jan 19, 2014 at 3:43 PM, Rustom Mody wrote:
>>>
>> As do these pieces of code:
>>
>>--> def quux1(x): return str(x+1)
>>--> def quux2(x): return hex(x+1)[2:]
>
> They do?
>
>--> quux1(2.3)
> '3.3'
>
>--> quux2(2.3)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "<stdin>", line 1, in quux2
> TypeError: hex() argument can't be converted to hex

(Will be) fixed in 3.5 [1] :)

--
~Ethan~

[1] Which is to say, both will raise an exception.





==============================================================================
TOPIC: graphical python
http://groups.google.com/group/comp.lang.python/t/fbe4c24dcdbb015d?hl=en
==============================================================================

== 1 of 3 ==
Date: Sat, Jan 18 2014 9:40 pm
From: buck


I'm trying to work through Skienna's algorithms handbook, and note that the author often uses graphical representations of the diagrams to help understand (and even debug) the algorithms. I'd like to reproduce this in python.

How would you go about this? pyQt, pygame and pyglet immediately come to mind, but if I go that route the number of people that I can share my work with becomes quite limited, as compared to the portability of javascript projects.

I guess my question really is: has anyone had success creating an interactive graphical project in the browser using python?

Is this a dream I should give up on, and just do this project in coffeescript/d3?




== 2 of 3 ==
Date: Sun, Jan 19 2014 12:19 am
From: Ian Kelly


On Sat, Jan 18, 2014 at 10:40 PM, buck <workitharder@gmail.com> wrote:
> I'm trying to work through Skienna's algorithms handbook, and note that the author often uses graphical representations of the diagrams to help understand (and even debug) the algorithms. I'd like to reproduce this in python.
>
> How would you go about this? pyQt, pygame and pyglet immediately come to mind, but if I go that route the number of people that I can share my work with becomes quite limited, as compared to the portability of javascript projects.
>
> I guess my question really is: has anyone had success creating an interactive graphical project in the browser using python?
>
> Is this a dream I should give up on, and just do this project in coffeescript/d3?

You should be able to do something without much fuss using HTML 5 and
either Pyjamas (which compiles Python code to Javascript) or Brython
(a more or less complete implementation of Python within Javascript).
For example, see the clock demo on the Brython web page.

Pyjamas is the more established and probably more stable of the two
projects, but you should be aware that there are currently two active
forks of Pyjamas and some controversy surrounding the project
leadership.




== 3 of 3 ==
Date: Sun, Jan 19 2014 3:13 am
From: Irmen de Jong


On 19-1-2014 6:40, buck wrote:
> I'm trying to work through Skienna's algorithms handbook, and note that the author often uses graphical representations of the diagrams to help understand (and even debug) the algorithms. I'd like to reproduce this in python.
>
> How would you go about this?

Would something like this help http://ipython.org/notebook.html ?

Irmen






==============================================================================
TOPIC: Can post a code but afraid of plagiarism
http://groups.google.com/group/comp.lang.python/t/bb644bb09fed1442?hl=en
==============================================================================

== 1 of 3 ==
Date: Sat, Jan 18 2014 10:31 pm
From: Steven D'Aprano


On Sat, 18 Jan 2014 14:32:21 -0800, indar kumar wrote:

> @Roy Smith
>
> Can you help me privately because its an assignment and have to submit
> plagiarism free

Then don't plagiarise.


Plagiarism means YOU copy other people. You shouldn't get in trouble
because other people copy you.

Talk to your tutor or teacher and ask what the school's policy is about
asking for external help on projects. Some schools will allow it if you
explain what help you received. Some prohibit it all together.

In general, we will help with questions about Python syntax and
libraries, but we try not to write your code for you. If you make a good-
faith attempt to solve the problem, and then ask for help, we shall try
to assist. But as I said, you should find out what your school or
university's policy is.


--
Steven




== 2 of 3 ==
Date: Sat, Jan 18 2014 10:45 pm
From: Devin Jeanpierre


On Sat, Jan 18, 2014 at 10:31 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Plagiarism means YOU copy other people. You shouldn't get in trouble
> because other people copy you.

Normally, both the person copying and the person who gave away their
work to be copied are punished. It simplifies figuring out who to
punish, and discourages people from enabling cheaters.

If one of their fellow students copied their assignment, they actually
likely would be in trouble, and could be expelled or failed.

-- Devin




== 3 of 3 ==
Date: Sun, Jan 19 2014 8:22 am
From: Grant Edwards


On 2014-01-18, indar kumar <indarkumar59@gmail.com> wrote:

> I want to show a code for review but afraid of plagiarism issues.
> Kindly, suggest how can I post it for review here without masking it
> visible for public

http://www.python.org/community/jobs/

I'm sure once you've agreed on contract and payment terms with whoever
you hire to do your private code review they will arrange a private
communications channel.








==============================================================================
TOPIC: Beginner Tutorials
http://groups.google.com/group/comp.lang.python/t/ed9cc82315e6c3e6?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Jan 18 2014 11:07 pm
From: simsonsjanis@gmail.com


On Friday, 18 January 2013 16:47:52 UTC+2, Rik wrote:
> Hi, I've developed a website for beginners to Python. I'd appreciate any comments or criticism. It's still under development, and should be finished in the next few months. Oh, and it's free to use.
>
>
>
> www.usingpython.com

code solutions should be collapsed by default, imho





==============================================================================
TOPIC: python to enable javascript , tried selinium, ghost, pyQt4 already
http://groups.google.com/group/comp.lang.python/t/a453f34131ad9343?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Jan 18 2014 11:58 pm
From: Giorgos Tzampanakis


On 2014-01-18, Jaiprakash Singh wrote:

> hi,
>
> can you please suggest me some method for study so that i can
> scrap a site having JavaScript behind it
>
>
> i have tried selenium, ghost, pyQt4, but it is slow and as a am
> working with thread it sinks my ram memory very fast.

I have tried selenium in the past and I remember it working reasonably
well. I am afraid you can't get around the slowness since you have to have
a web browser running.

--
Improve at backgammon rapidly through addictive quickfire position quizzes:
http://www.bgtrain.com/





==============================================================================
TOPIC: Python declarative
http://groups.google.com/group/comp.lang.python/t/d3cb0aca7152f06f?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Jan 19 2014 2:27 am
From: sertorbe@gmail.com


El miércoles, 15 de enero de 2014 18:02:08 UTC+1, Sergio Tortosa Benedito escribió:
> Hi I'm developing a sort of language extension for writing GUI programs
>
> called guilang, right now it's written in Lua but I'm considreing Python
>
> instead (because it's more tailored to alone applications). My question
>
> it's if I can achieve this declarative-thing in python. Here's an
>
> example:
>
>
>
> Window "myWindow" {
>
> title="Hello world";
>
> Button "myButton" {
>
> label="I'm a button";
>
> onClick=exit
>
> }
>
> }
>
> print(myWindow.myButton.label)
>
>
>
> Of course it doesn't need to be 100% equal. Thanks in advance
>
>
>
> Sergio

OK, thanks, maybe the to be read by python may be interesting .Anyway, I think I'll have to consider all the options I have right now (Lua,Python,A file readed by Python). Really, thanks, you are awesome.

Sergio.





==============================================================================
TOPIC: python-daemon for Python v3
http://groups.google.com/group/comp.lang.python/t/f93a6aca18b45b46?hl=en
==============================================================================

== 1 of 3 ==
Date: Sun, Jan 19 2014 2:30 am
From: Asaf Las


Hi Community

Is there ported to Python v3 python-daemon package?

https://pypi.python.org/pypi/python-daemon/

i am afraid it is not as simple as correction of relative path input
feature and except clauses in mentioned package.

Thanks

Asaf




== 2 of 3 ==
Date: Sun, Jan 19 2014 2:41 am
From: Ben Finney


Asaf Las <roegltd@gmail.com> writes:

> Is there ported to Python v3 python-daemon package?
>
> https://pypi.python.org/pypi/python-daemon/

Have a read through the archives for the 'python-daemon-devel'
discussion forum
<URL:http://lists.alioth.debian.org/mailman/listinfo/python-daemon-devel>,
where we have had discussions about porting the library to Python 3.

I'd be interested to know who wants us to keep Python 2 compatibility.
If we can drop that, then a Python 3 version of the library would be
much easier to maintain.

We are also in need of an active maintainer for the 'python-lockfile'
library <URL:https://pypi.python.org/pypi/lockfile/> which is commonly
used with 'python-daemon'.

--
\ "Pinky, are you pondering what I'm pondering?" "I think so, |
`\ Brain, but if we give peas a chance, won't the lima beans feel |
_o__) left out?" --_Pinky and The Brain_ |
Ben Finney





== 3 of 3 ==
Date: Sun, Jan 19 2014 5:21 am
From: Asaf Las


On Sunday, January 19, 2014 12:41:31 PM UTC+2, Ben Finney wrote:
> Have a read through the archives for the 'python-daemon-devel'
> discussion forum
> <URL:http://lists.alioth.debian.org/mailman/listinfo/python-daemon-devel>,
> where we have had discussions about porting the library to Python 3.
> I'd be interested to know who wants us to keep Python 2 compatibility.
> If we can drop that, then a Python 3 version of the library would be
> much easier to maintain.
Thanks. i have not seen this, but different port. it is on github.
yet got myself rid of errors during pip install, but was not sure about latter.

> We are also in need of an active maintainer for the 'python-lockfile'
> library <URL:https://pypi.python.org/pypi/lockfile/> which is commonly
> used with 'python-daemon'.

I would love to contribute but as a novice in Python, need time to make something valuable for community.

/Asaf





==============================================================================
TOPIC: Need help vectorizing code
http://groups.google.com/group/comp.lang.python/t/f48ecb4266405add?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Jan 19 2014 7:46 am
From: Oscar Benjamin


On 18 January 2014 20:51, Kevin K <richyokevin@gmail.com> wrote:
> I have some code that I need help vectorizing.
> I want to convert the following to vector form, how can I? I want to get rid of the inner loop - apparently, it's possible to do so.
> X is an NxD matrix. y is a 1xD vector.
>
> def foo(X, y, mylambda, N, D, epsilon):
> ...
> for j in xrange(D):
> aj = 0
> cj = 0
> for i in xrange(N):
> aj += 2 * (X[i,j] ** 2)
> cj += 2 * (X[i,j] * (y[i] - w.transpose()*X[i].transpose() + w[j]*X[i,j]))

As Peter said the y[i] above suggests that y has the shape (1, N) or
(N, 1) or (N,) but not (1, D). Is that an error? Should it actually be
y[j]?

You don't give the shape of w but I guess that it is (1, D) since you
index it with j. That means that w.transpose() is (D, 1). But then
X[i] has the shape (D,). Broadcasting those two shapes gives a shape
of (D, D) for cj. OTOH if w has the shape (D, 1) then cj has the shape
(1, D).

Basically your description is insufficient for me to know what your
code is doing in terms of all the array shapes. So I can't really
offer a vectorisation of it.

>
> ...
>
> If I call numpy.vectorize() on the function, it throws an error at runtime.

You've misunderstood what the numpy.vectorize function is for. The
vectorize function is a convenient way of generating a function that
can operate on arrays of arbitrary shape out of a function that
operates only on scalar values.


Oscar




==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate