Skip to content
Advertisement

Immutable numpy array?

Is there a simple way to create an immutable NumPy array? If one has to derive a class from ndarray to do this, what’s the minimum set of methods that one has to override to achieve immutability? Answer You can make a numpy array unwriteable: Also see the discussion in this thread: http://mail.scipy.org/pipermail/numpy-discussion/2008-December/039274.html and the documentation: http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flags.html

Python SocketServer error upon connection

I am running a Python server using the socketserver module in Python 3.1. Every time I get a connection from the client (which succeeds client side), my server receives an error. Here is my code: And here is my error: The odd thing I noticed about the error is that the port it gives on the second line is different

Why can’t I find any pywin32 documentation/resources

I cannot find pywin32 documentation or even a little synopsis of what the module is (I am aware its for win32 API stuff). Is there any pywin32 documentation or resources? Maybe some examples? Answer The PyWin32 installation includes a .chm help file at [Pythonpath]Libsite-packagesPyWin32.chm. The same info is online at http://timgolden.me.uk/pywin32-docs/index.html ActiveState used to keep this documentation online as well,

NumPy: calculate averages with NaNs removed

How can I calculate matrix mean values along a matrix, but to remove nan values from calculation? (For R people, think na.rm = TRUE). Here is my [non-]working example: With NaNs removed, my expected output would be: Answer I think what you want is a masked array: Edit: Combining all of the timing data Returns:

How to tell if a date is between two other dates?

I have the following codes: date, start and end are all variables with the format of 1/1. What should I do to have it print out the right result? i tried date as 10/2, start as 3/14 and end as 11/7 and it’s print ‘No!’, which means it’s not running right. I guess have to format them to a date

Python: Make class iterable

I have inherited a project with many large classes constituent of nothing but class objects (integers, strings, etc). I’d like to be able to check if an attribute is present without needed to define a list of attributes manually. Is it possible to make a python class iterable itself using the standard syntax? That is, I’d like to be able

How to overwrite the previous print to stdout?

If I had the following code: I would get the output of What I would like to do is instead of printing a newline, I want to replace the previous value and overwrite it with the new value on the same line. Answer Simple Version One way is to use the carriage return (‘r’) character to return to the start

how to open url in new tab from django?

i have to open the result page using render_to_response on a new tab Answer Django is server-side, opening in a new tab is client-side. So use an <A> with a target=”_blank” http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=target%3Dblank But of course spawning new windows/tabs is annoying for the user, so try not to do that after all.

Advertisement