Re: Expanding a vector by replicating elements individually

2010-09-24 Thread gburde...@gmail.com
On Sep 22, 1:30 am, Peter Otten <__pete...@web.de> wrote: > > array([1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) > > Peter Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Expanding a vector by replicating elements individually

2010-09-21 Thread gburde...@gmail.com
Given m=numpy.array([[1, 2, 3]]) I want to obtain array([[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]]) One way I've found to do this is: numpy.reshape(numpy.tile(m,(4,1)),(12,1),'f').T Another way is: numpy.reshape(numpy.tile(m,(4,1)).flatten(1),(1,12)) Is there a simpler way to do this, without h

Default return values for out-of-bounds list item

2010-01-21 Thread gburde...@gmail.com
Is there a built-in method in python that lets you specify a "default" value that will be returned whenever you try to access a list item that is out of bounds? Basically, it would be a function like this: def item(x,index,default): try: return x[index] except IndexError: return

Something confusing about non-greedy reg exp match

2009-09-06 Thread gburde...@gmail.com
If I do this: import re a=re.search(r'hello.*?money', 'hello how are you hello funny money') I would expect a.group(0) to be "hello funny money", since .*? is a non-greedy match. But instead, I get the whole sentence, "hello how are you hello funny money". Is this expected behavior? How can I s

BaseHTTPRequestHandler delays server response after "Popen"ing a program that waits for user input? (getline, fgets, etc.)

2009-04-16 Thread gburde...@gmail.com
I'm trying to write a very simple HTTP client/server program where the client uploads a file via PUT using pycurl, and the server accepts the file, "POpen"s a program, sends back "HELLO" to the client, then displays "good morning". The problem is when the "POpen"ed C++ program (test1.cpp below) wa