Re: Python Magazine

2013-05-24 Thread zoom

But why would anyone want to use IPv6?

On 05/25/2013 05:48 AM, Chris Angelico wrote:

On Sat, May 25, 2013 at 1:35 PM, Roy Smith  wrote:

"Python 3 vs. IPv6: who will win the race for early adoption?"


I think Py3 is winning that one so far. But really, both need to get
moving. Neither of my ISPs does IPv6 :(

Seconding the recommendation for QOTW, that's good fun.

ChrisA


--
http://mail.python.org/mailman/listinfo/python-list


weird behavior. bug perhaps?

2013-06-18 Thread zoom

Hi, I have a strange problem here. Perhaps someone would care to help me.

In the file test.py I have the following code:

from scipy import matrix, tile, mean, shape
import unittest

class TestSequenceFunctions(unittest.TestCase):

def setUp(self):
self.m = [[1,2],[3,4],[3,4],[3,4]]

def test_simplify(self):
m = matrix(self.m)
print shape(m)
print [shape(m)[1],1]
print shape(tile(mean(m,1),[shape(m)[1],1]).T)

if __name__ == '__main__':
unittest.main()

(Note that test.py, is just a simplification of my testing file, 
sufficient to reproduce the weird behavior that I'm  about to describe.)


If i run it in terminal via "python test.py" command I get the following 
output:


(4, 2)
[2, 1]
(1, 8)
.
--
Ran 1 test in 0.000s

OK


Now comes the funny part.
Let's try to run the following code in python interpreter:

>>> m = [[1,2],[3,4],[3,4],[3,4]]
>>>
>>> from scipy import matrix, tile, mean, shape
>>> print shape(m)
(4, 2)
>>> print [shape(m)[1],1]
[2, 1]
>>> print shape(tile(mean(m,1),[shape(m)[1],1]).T)
(4, 2)

Note the difference between outputs of:
print shape(tile(mean(m,1),[shape(m)[1],1]).T)


I mean, WTF?
This is definitely not the expected behavior.
Anybody knows what just happened here?

--
http://mail.python.org/mailman/listinfo/python-list


Re: weird behavior. bug perhaps?

2013-06-18 Thread zoom

On 06/18/2013 04:27 PM, rusi wrote:

On Jun 18, 7:23 pm, zoom  wrote:

Hi, I have a strange problem here. Perhaps someone would care to help me.

In the file test.py I have the following code:

from scipy import matrix, tile, mean, shape
import unittest

class TestSequenceFunctions(unittest.TestCase):

  def setUp(self):
  self.m = [[1,2],[3,4],[3,4],[3,4]]

  def test_simplify(self):
  m = matrix(self.m)
  print shape(m)
  print [shape(m)[1],1]
  print shape(tile(mean(m,1),[shape(m)[1],1]).T)

if __name__ == '__main__':
  unittest.main()

(Note that test.py, is just a simplification of my testing file,
sufficient to reproduce the weird behavior that I'm  about to describe.)

If i run it in terminal via "python test.py" command I get the following
output:

(4, 2)
[2, 1]
(1, 8)
.
--
Ran 1 test in 0.000s

OK

Now comes the funny part.
Let's try to run the following code in python interpreter:

  >>>  m = [[1,2],[3,4],[3,4],[3,4]]
  >>>
  >>>  from scipy import matrix, tile, mean, shape
  >>>  print shape(m)
(4, 2)
  >>>  print [shape(m)[1],1]
[2, 1]
  >>>  print shape(tile(mean(m,1),[shape(m)[1],1]).T)
(4, 2)

Note the difference between outputs of:
print shape(tile(mean(m,1),[shape(m)[1],1]).T)

I mean, WTF?
This is definitely not the expected behavior.
Anybody knows what just happened here?


[Never used scipy so pls excuse if I am off...]

Given list m, in the class you are doing m ->  matrix(m)
which you dont seem to be doing in the interpreter.


yes, that's the thing.

thanks a lot

FYI this happens because

>>> shape(mean(m,1))
(4, 1)
>>> shape(mean(array(m),1))
(4,)

thanks again
--
http://mail.python.org/mailman/listinfo/python-list


Re: weird behavior. bug perhaps?

2013-06-18 Thread zoom

On 06/18/2013 05:25 PM, Robert Kern wrote:

On 2013-06-18 15:23, zoom wrote:

Hi, I have a strange problem here. Perhaps someone would care to help me.

In the file test.py I have the following code:

from scipy import matrix, tile, mean, shape
import unittest

class TestSequenceFunctions(unittest.TestCase):

def setUp(self):
self.m = [[1,2],[3,4],[3,4],[3,4]]

def test_simplify(self):
m = matrix(self.m)
print shape(m)
print [shape(m)[1],1]
print shape(tile(mean(m,1),[shape(m)[1],1]).T)

if __name__ == '__main__':
unittest.main()

(Note that test.py, is just a simplification of my testing file,
sufficient to
reproduce the weird behavior that I'm about to describe.)

If i run it in terminal via "python test.py" command I get the
following output:

(4, 2)
[2, 1]
(1, 8)
.
--
Ran 1 test in 0.000s

OK


Now comes the funny part.
Let's try to run the following code in python interpreter:

>>> m = [[1,2],[3,4],[3,4],[3,4]]
>>>
>>> from scipy import matrix, tile, mean, shape
>>> print shape(m)
(4, 2)
>>> print [shape(m)[1],1]
[2, 1]
>>> print shape(tile(mean(m,1),[shape(m)[1],1]).T)
(4, 2)

Note the difference between outputs of:
print shape(tile(mean(m,1),[shape(m)[1],1]).T)


I mean, WTF?
This is definitely not the expected behavior.
Anybody knows what just happened here?


As rusi noted, the difference between your two snippets is that in one,
you converted the list of lists to a matrix object in your test suite
but not in your interactive session. Most numpy functions like mean()
will convert their arguments to regular numpy.ndarray objects rather
than matrix objects. matrix is a subclass of ndarray that adds special
behavior: in particular, operations on matrix objects retain their
2D-ness even when an ndarray would flatten down to a 1D array.

[~]
|1> import numpy as np

[~]
|2> m = [[1,2],[3,4],[3,4],[3,4]]

[~]
|3> a = np.array(m)

[~]
|4> b = np.matrix(m)

[~]
|5> np.mean(a, axis=1)
array([ 1.5, 3.5, 3.5, 3.5])

[~]
|6> np.mean(b, axis=1)
matrix([[ 1.5],
[ 3.5],
[ 3.5],
[ 3.5]])

[~]
|7> np.mean(a, axis=1).shape
(4,)

[~]
|8> np.mean(b, axis=1).shape
(4, 1)


This will propagate through the rest of your computation.

Personally, I recommend avoiding the matrix type. It causes too many
problems. Stick to plain ndarrays.

You will probably want to ask further numpy questions on the
numpy-discussion mailing list:

http://www.scipy.org/scipylib/mailing-lists.html


didn't see it earlier.

thanks.

so ndarrays, you say...


--
http://mail.python.org/mailman/listinfo/python-list


Re: Illegal suggestions on python list

2013-07-04 Thread zoom

On 07/05/2013 12:30 AM, Chris Angelico wrote:

On Fri, Jul 5, 2013 at 3:10 AM, Rustom Mody  wrote:

On Thu, Jul 4, 2013 at 9:16 PM, Steven D'Aprano
  wrote:


Which crime is that? Presumably you mean an actual criminal felony, not a
mere civil offence. Under which jurisdiction?

If piracy is a crime, and not just a civil offence, then surely so is
libel.


You've got your OO class hierarchy mixed up and then imposing that on me.

See
http://www.nolo.com/legal-encyclopedia/crimes-felonies-misdemeanors-infractions-classification-33814.html

I did not say or suggest felony.
Maybe misdemeanor or infarction. Dunno which. IANAL...


The specific terms don't really matter here, but in most
jurisdictions, "felony" will be a term that unambiguously refers to a
crime against the law, as distinct from what Steven is comparing
against, civil damages.

If I shoot you dead, I have committed murder. This is a crime.

If I put up a sign saying "Entrance to" over my
own door, next to yours, then I have committed no crime, but you can
sue me in civil court for your loss of business resulting from my
action.

Whether one of them is classed as a felony in some jurisdiction or not
doesn't matter, what matters is that one is simply not a crime.
Violating a license agreement usually is not a crime (and if done in
good faith, is often considered a bug to be fixed, not a suit to be
pressed - but that does NOT apply here), hence the analogies to
criminal action somewhat break down.

That said, though, offering in public to rip someone off is just as
unwise as offering in public to commit a crime.

ChrisA


Probably...

http://en.wikipedia.org/wiki/Aaron_Swartz#JSTOR
--
http://mail.python.org/mailman/listinfo/python-list


Imaging library

2012-11-29 Thread zoom

C'mon guys, don't be so picky.
The point is that that he cannot find python library that can easily 
create HDR image or process RAW images (or some other image format).
Also, AFAIK there is no built in support for standard imaging filters, 
color space conversion, etc (as Alasdair also mentioned). One can do 
this with scipy, and this is how I do it. But I'm also interested if 
there is some library that implements any of those. IMHO it would be 
useful if one could code the same effects easily as clicking on the 
effect button in GIMP or Blender.
This is interesting question, and if any of you have any ideas on how 
this can be achieved, please share your knowledge with us.


P.S.
We do not need to tutor people about whether a RAW format is a specific 
image format or not (http://en.wikipedia.org/wiki/Raw_image_format) - we 
understand the point of his question albeit it is not clearly stated.
Assume good will - nobody is stating that PIL or scipy are bad, we 
simply ask whether there is something more out there.


It would be more useful if we would provide information on how to do it, 
or connect him with someone who can do it. Or point where he can request 
such feature or publish his solution. The policy not to implement every 
format under the sky is a legal one, but by implementing it one-by-one - 
together we might even get there.

--
http://mail.python.org/mailman/listinfo/python-list


Python modules

2013-01-14 Thread zoom
Is there any "rules" regarding importing python modules within your own 
module? I mean, how does this affects the performance of the program?


For example, I have my own module named "sound".
At the top of the file sound.py I have:
import scipy

In the code I have:
import scipy, sound, etc

Now I have two instances of every function within scipy, e.g.
scipy.r_[a] = sound.scipy.r_[a]

Module importing is quite fast, but not instant. It takes some time, but 
it happens only once. My concern is whether I hold all these multiple 
instances of same function in the memory, and does this reduce the 
performance of my program.


In short, when creating a module, is it worthwhile to be careful and 
import only necessary functions, nothing more?

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python modules

2013-01-14 Thread zoom

On 01/14/2013 04:01 PM, Dan Sommers wrote:

On Mon, 14 Jan 2013 15:54:27 +0100, zoom wrote:


Is there any "rules" regarding importing python modules within your own
module? I mean, how does this affects the performance of the program?


"Even the initializers are optimized!" -- Mel, the real programmer


Great!


Unless you've profiled it, and the extra memory taken up by unused
functions or modules is measurable and near the top of the list of
performance issues, I wouldn't worry about it.


Now I have two instances of every function within scipy, e.g.
scipy.r_[a] = sound.scipy.r_[a]


No:  now you have two names for every function within scipy.  The
functions themselves are not duplicated.

Dan


Now I love Python even more...
--
http://mail.python.org/mailman/listinfo/python-list


Save to a file, but avoid overwriting an existing file

2014-03-12 Thread zoom

Hi!

I would like to assure that when writing to a file I do not overwrite an 
existing file, but I'm unsure which is the best way to approach to this 
problem. As I can see, there are at least two possibilities:


1. I could use fd = os.open("x", os.O_WRONLY | os.O_CREAT | os.O_EXCL)
which will fail - if the file exists. However, I would prefer if the 
program would try to save under different name in this case, instead of 
discarding all the calculation done until now - but I' not too well with 
catching exceptions.


2. Alternatively, a unique string could be generated to assure that no 
same file exists. I can see one approach to this is to include date and 
time in the file name. But this seems to me a bit clumsy, and is not 
unique, i.e. it could happen (at least in theory) that two processes 
finish in the same second.


Any suggestions, please?
--
https://mail.python.org/mailman/listinfo/python-list