Hi there.
I'm trying to create a simple class called Vector which inherit from
array.
class Vector(array):
def __init__(self,length):
"""initialize a vector of random floats of size length. floats
are in interval [0;1]"""
array.__init__(self,'f')
for _ in xrange(length
from array import array
class Vector(array):
def __init__(self,size):
print "pouet"
array.__init__('f')
print "pouet"
v = Vector('c')
print repr(v)
will output :
pouet
pouet
array('c')
--
http://mail.python.org/mailman/listinfo/python-list
Obviously, there is something I didn't catch in python's inheritance.
from array import array
class Vector(array):
def __init__(self,size):
print self.typecode
array.__init__(self,'f')
>>> v = Vector('c')
c
Here, it says the typecode is 'c' - I thought such an information was
Hmm ... I'm definitely not a python wizard, but it seems to be quite a
special case that breaks the rules ... unpythonic, isn't it ?
Has anyone seen a PEP on this subject ?
Just in case a troll reads this message : i'm not saying python sucks
or has huge design flaws here ...
--
http://mail.pyt
Hi.
i've already something about inheriting from array a few weeks ago and
had my answer. But again, there is something that I don't understand.
Here is my vector class, which works quite well :
class Vector(array):
def __new__(cls,length,data=None):
return super(Vector,cls).__new__(c
That's great, thanks !
To put it short, when I create a Stimulus object, it first seek
__new__() method. But if I don't define it, it looks for the one
defined in Vector. This raises a problem because the parameters passed
to Stimulus(params) aren't fitting with Vector parameters, raising an
excep
Hi there.
Reading the page on python performance ( http://scipy.org/PerformancePython
) made me realize that I can achieve tremendous code acceleration with
numpy just by using "u[:,:]" kind of syntax the clever way.
Here is a little problem (Oja's rule of synaptic plasticity)
* W is a matrix co
Hi there.
I'm strugling here with some boost python code (damn I hate C++) :
All I want to do is to initialize the content of an array with a numpy
ndarray parameter. I have this, which actually works. But I want to
add some kind of data check such as :
* is array two dimensional ?
* are the dim
What I'm trying to say here : a numpy array is supposed to have it's
shape stored as a tuple. What I want to do is to access this
information from my C++ code, in order to do some validity check.
So, by looking around in the doc of boost/python/numeric.hpp I was
able to do this :
void
Layer::set_
Hi there !
I'm just starting to use Numeric here, and I'm wondering : how can I
efficiently initialize every values of a N-dimensional array, given I
don't know the number of dimensions ?
I'm looking for something like a map function, or a way to conveniently
iterate through the whole N-array, bu
I tried to use Numeric.fromfunction, but there seems to be a problem :
the function called must have the right number of args (hint : the
number of dimensions, which I don't know). So i tried to use a function
like :
def myfunc(*args, **kw):
return 0
and then i get :
>> Numeric.fromfunctio
Thanks for your precious advices. The flat iterator is definitely what
i need.
--
http://mail.python.org/mailman/listinfo/python-list
Hi there.
I am working with multi-dimensional arrays and I need to get
coordinates of the min value in it.
using myarray.argmin() returns the index in the flatten array, which is
a first step, but I wonder if it is possible to get the coordinates
directly as an array, rather than calculating them
thanks. unravel_index do the trick.
Travis E. Oliphant wrote:
> TG wrote:
> > Hi there.
> >
> > I am working with multi-dimensional arrays and I need to get
> > coordinates of the min value in it.
> >
> > using myarray.argmin() returns the index in the f
hi there.
I'm struggling with a function of numpy. Here it is :
import numpy as NP
mean = NP.array([0,0])
cov = NP.array([[1,0.25],[0.25,1]])
v = NP.random.multivariate_normal(mean,cov)
Quite simple code : it is supposed to generate an array of two random
values taken from a multinormal distrib
Hi there.
Anyone knows how to use numpy / scipy in order to solve this ?
* A is an array of shape (n,)
* X is a positive float number
* B is an array of shape (n,)
* O is an array of shape (n,) containing only zeros.
A.X - B = O
min(X)
thanks.
--
http://mail.python.org/mailman/listinfo/python
Ben C wrote:
> On 2006-07-17, TG <[EMAIL PROTECTED]> wrote:
> > Hi there.
> >
> > Anyone knows how to use numpy / scipy in order to solve this ?
> >
> > * A is an array of shape (n,)
> > * X is a positive float number
> > * B is an array of shap
hi.
This is my first try on modules.
I've got :
tom/
__init__.py
core.py
ui.py
data.py
then, when I'm in my ipython shell :
?> from tom import *
this works, it loads core, ui and data
but when I do this :
?> import tom
?> tom.core
AttributeError: 'module' object has no att
I've just found this :
If I add :
"import core, data, ui" inside my "tom/__init__.py" file, it will
work. But this line does not seems to exist in other files (after
having a look at several files inside /usr/lib/python2.4).
--
http://mail.python.org/mailman/listinfo/python-list
I know this is a bad habit ... I was just doing it to show what is
disturbing me.
Obviously the "star" syntax finds the submodules because they are
loaded, but when I properly load the module alone with "import tom",
the "dot" syntax does not find "tom.core".
BartlebyScrivener wrote:
> >> > from
BartlebyScrivener wrote:
> then you no longer need tom, you imported all of his FUNCTIONS (never
> heard of submodule).
my mistake, I was using the wrong name
tom/ <-- package
__init__.py
core.py <
data.py < these are modules contained in tom/
ui.py <
if I import t
okay,
so only when I have inside __init__.py
__all__ = ["core"]
this works
?> from tom import *
?> help(core)
but (in a brand new interpretor)
?> import tom
?> help(tom.core)
AttributeError: 'module' object has no attribute 'core'
got it. But ...
?> import numpy
?> help(numpy.core)
this w
okay, thanks everyone. this is much clearer now.
--
http://mail.python.org/mailman/listinfo/python-list
hi.
let's say I have :
from numpy import *
x = identity(5)
y = zeros((7,7))
I want to paste x into y, starting at coordinates (1,1) in order to
change y to something like this :
0 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 1 0 0
0 0 0 0 0 1 0
0 0 0 0 0 0 0
how would you do t
Thanks, that's exactly what I needed.
Tim Heaney wrote:
> You can use Python slice notation for each dimension
>
> y[1:6,1:6] = x
>
--
http://mail.python.org/mailman/listinfo/python-list
25 matches
Mail list logo