Newbie question about numpy

2006-08-24 Thread Paul Johnston
Hi I'm new to python and have just been taking a look at what it has
to offer.
I noted the lack of matrices so installed numpy
I know the documentation is chargable so wanted a quick play to see if
I should buy it 
However 

_
from numpy  import *

a = array([[1,2,3],[4,5,6],[1,2,3]])
b = array([[1,3,6],[2,5,1],[1,1,1]])

print 'a = \n',a,"\n"
print 'b = \n',b,"\n"

print 'a has shape ', a.shape
print 'b has shape ', b.shape, "\n"

print "a * b is \n", a * b
_

Gives me 
_
a =
[[1 2 3]
 [4 5 6]
 [1 2 3]] 

b =
[[1 3 6]
 [2 5 1]
 [1 1 1]] 

a has shape  (3, 3)
b has shape  (3, 3) 

a * b is
[[ 1  6 18]
 [ 8 25  6]
 [ 1  2  3]]
_


I know its a long time since my degree but that's not matrix
multiplication is it ?

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


Re: Newbie question about numpy

2006-08-25 Thread Paul Johnston
On Thu, 24 Aug 2006 17:23:49 GMT, Dennis Lee Bieber
<[EMAIL PROTECTED]> wrote:

>On Thu, 24 Aug 2006 16:38:45 +0100, Paul Johnston
><[EMAIL PROTECTED]> declaimed the following in
>comp.lang.python:
>
>> I know its a long time since my degree but that's not matrix
>> multiplication is it ?
>
>   Define "matrix multiplication"...
>
>   What you see appears to be multiplication of corresponding elements.
>
>   Were you expecting a dot product, or a cross product, or something
>else?
>

That as explained in
http://people.hofstra.edu/faculty/stefan_Waner/RealWorld/tutorialsf1/frames3_2.html

As I say its been a long time :-)

Thanks to everyone for the help.
Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Unicode characters

2006-09-04 Thread Paul Johnston
Hi
I have a string which I convert into a list then read through it
printing its glyph and numeric representation

#-*- coding: utf-8 -*-

thestring = "abcd"
thelist = list(thestring)

for c in thelist:
 print c,
 print ord(c)

Works fine for latin characters but when I put in a unicode character
a two byte character gives me two characters. For example an arabic
alef returns

*  216
* 167

( the first asterix is the empty set symbol the second a double "s")

Putting in sequential characters i.e. alef, beh, teh mabuta, gives me
sequential listings i.e.
216  167
216  168
216  169 
So it is reading the correct details.


Is there anyway to get the c in the for loop to recognise it is
reading a multiple byte character.
I have followed the info in PEP 0263 and am using Python 2.4.3 Build
12 on a Windows box  within Eclipse 3.2.0 and Python plugins 1.2.2

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


Detecting Updates on Arbitrary Objects

2009-03-13 Thread Paul Johnston
Hi,

I would like to be able to install a code hook to detect updates on
arbitrary objects. To give some background, I'm writing a web widget
library, that uses request-local storage. If there's a mutable object
on a widget (a dict is common), I'd like any attempts to update the
dict to cause the dict to be cloned into request-local storage and the
update applied.

Now, I did have this working quite nicely for dict and list instances,
by subclassing dict and list, and overriding the write methods (or
most of them - __setitem__, __delitem__, append, etc.) When the dict/
list is added to the widget, it's replaced with a clone, using the
DictProxy/ListProxy subclass. (I realise Proxy may have been slightly
inaccurate as a name) However, sometimes a user needs to use a list-
like object that isn't a list, and this approach breaks down.

So, I think I need to do a real object proxy - a class that defers
almost all attributes to an inner instance that it stores, but
overrides a few. The following is my initial attempt, which almost
works, but I think there must be a better way. In particular, needing
to explicitly override __iter__ and __eq__ spells trouble - what about
__ne__, __gt__, etc. Also, is there a way to catch just any change,
rather than trying to know all the change methods. A way to do this
for arbitrary objects (not just dicts and lists) would be good too.

Any hints, tips, or pointers to docs online?

Thanks,

Paul


class GenericProxy(object):
def __init__(self, obj):
self._obj = obj
def __getattr__(self, a):
return getattr(self._obj, a)

def __iter__(self):
return self._obj.__iter__()
def __eq__(self, x):
return self._obj.__eq__(x)

__setitem__ = _catch_modify('__setitem__')
__delitem__ = _catch_modify('__delitem__')
append = _catch_modify('append')
insert = _catch_modify('insert')
--
http://mail.python.org/mailman/listinfo/python-list


jpeg package

2010-05-01 Thread Paul Johnston
Hi,

I've used the jpeg library on PyPI in the past and it's been great:
http://pypi.python.org/pypi/jpeg/0.1.4

However, the library home page is now unaccessible. I can't even find
the library on archive.org. Any idea how I can get it?
http://www.emilas.com/jpeg/

Thanks,

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


class or instance method

2009-06-17 Thread Paul Johnston
Hi,

I would like to have a method that is both a classmethod and an
instancemethod. So:

class MyClass(object):
  @class_or_instance
  def myfunc(cls_or_self):
pass

The semantics I'd like are:
When you call MyClass.myfunc, it gets passed a class
When you call MyClass().myfunc, it gets passed an instance

I'm sure I've seen some code to do this somewhere, but I can't find it
now. Any help appreciated.

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


Re: class or instance method

2009-06-21 Thread Paul Johnston
Hi,

> class class_or_instance(object):
>     def __init__(self, fn):
...

This works a treat, thank-you.

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


Determining __name__ from the code that called a function

2009-07-27 Thread Paul Johnston
Hi,

In ToscaWidgets 2 experimental, when defining resources you often do
something like this:
CSSLink(modname=__name__, filename='static/mycss.css')

Now, what I'd like to do is make the "modname=__name__" optional, to
make code more concise. I figure there must be some way (using inspect
or something) to determine what __name__ would be in the code that
just called my function. Couldn't immediately see how to do this - any
suggestions? Thanks,

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