Re: [Numpy-discussion] Need more comments from scientific community on python-dev

2006-11-03 Thread Alexander Belopolsky
On 11/3/06, Torgil Svensson <[EMAIL PROTECTED]> wrote:
> class struct_type(Structure):
> _fields_ = []
>
> ...
> ... which is somewhat static in nature. How do you create "structures"
> dynamically?
>

You can put the above in a function that takes fields as an argument, or

type('struct_type', (Structure,), {'_fields_':[('a', c_int), ('b',
c_long)]})

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


Re: [Numpy-discussion] Need more comments from scientific community on python-dev

2006-10-31 Thread Alexander Belopolsky
On 10/31/06, Travis Oliphant <[EMAIL PROTECTED]> wrote:
...
> Please understand what I meant.  I meant putting effort into getting
> PyArray_DescrConverter to allow ctypes inputs and convert to the
> appropriate PyArray_Descr * structure.   I already understand ctypes
> objects.  I want the dtype() command to also understand them.
>

I think I am starting to understand. Forgive me for being slow.

Is it correct that you don't mind writing c_int * 10 instead of
dtype(('http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


Re: [Numpy-discussion] ndarray.count() ?

2006-09-07 Thread Alexander Belopolsky
On 9/7/06, Martin Spacek <[EMAIL PROTECTED]> wrote:
> What's the most straightforward way to count, say, the number of 1s or
> Trues in the array? Or the number of any integer?
>
> I was surprised to discover recently that there isn't a count() method
> as there is for Python lists. Sorry if this has been discussed already,
> but I'm wondering if there's a reason for its absence.
>

You don't really need count with ndarrays:

>>> from numpy import *
>>> a = array([1,2,3,1,2,3,1,2])
>>> (a==3).sum()
2

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


Re: [Numpy-discussion] .T Transpose shortcut for arrays again

2006-07-06 Thread Alexander Belopolsky
On 7/6/06, Tim Hochberg <[EMAIL PROTECTED]> wrote:
> ...
> Overloading '+' sure seems perverse, but maybe that's just me.
>
The first time I saw it, it seemed perverse to me as well, but it
actually make a lot of sense:

1. It is visually appealing as in  '+' makes '|' from '-' and '-' from
'|' and looks close enough to 't'.
2. It puts an otherwise useless operator to work.
3. Prefix spelling suggests that it should be swapaxes(0,1) rather
than swapaxes(-2,-1), which is the choice made by K.
4. You can't get any shorter than that (at least using a fixed width font :-).
5. It already does the right thing for rank<2.

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


Re: [Numpy-discussion] .T Transpose shortcut for arrays again

2006-07-06 Thread Alexander Belopolsky
On 7/6/06, Tim Hochberg <[EMAIL PROTECTED]> wrote:
> ...
> So this is essentially turning a row vector into a column vector? Is
> that right?
>
Being a definition, this is neither right nor wrong.  It all depends
on what you are using it for. If you want to distinguish row and
column vectors, you have to use rank-2, but it is convenient to to
think of rank-1 as an equivalent of either row or column and rank-0 as
a 1x1 array. If you define transpose as a rank-2 only operation, but
allow promotion of rank < 2 to rank 2, you end up with the rules of
S+.

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


Re: [Numpy-discussion] Time for beta1 of NumPy 1.0

2006-06-30 Thread Alexander Belopolsky
On 6/30/06, Sasha <[EMAIL PROTECTED]> wrote:

> File `numpy/core/src/arraytypes.inc.src'
> Lines executed:47.35% of 868

This is was an overly optimistic number.  More relevant is the
following obtained by disabling the #line directives:

File `build/src.linux-x86_64-2.4/numpy/core/src/arraytypes.inc'
Lines executed:26.71% of 5010

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


Re: [Numpy-discussion] Don't like the short names like lstsq and irefft

2006-06-15 Thread Alexander Belopolsky
On 6/15/06, Paul Dubois <[EMAIL PROTECTED]> wrote:
> And yes, I think FFT is a name. (:->  Exception for that.


There are more exceptions that Numeric is not taking advantage of:

equal, less, greater, ... -> eq, lt, gt, ...
inverse, generalized_inverse -> inv, pinv

In my view it is more important that code is easy to read rather than
easy to write. Interactive users will disagree, but in programming you
write once and read/edit forever :).

Again, there is no defense for abbreviating linear_least_squares
because it is unlikely to appear in an expression and waste valuable
horisontal space.  Contracting generalised_inverse is appropriate and
numpy does the right thing in this case.

The eig.., svd and cholesky choice of names is unfortunate because
three different abbreviation schemes are used: first syllable,
acronym and first word.  I would say: when in doubt spell it in full.


___
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


Re: [Numpy-discussion] Array Protocol change for Python 2.6

2006-06-09 Thread Alexander Belopolsky
On 6/9/06, Travis Oliphant <[EMAIL PROTECTED]> wrote:
> ...   In NumPy this is not quite the rule followed.
> Bascially attributes are used when getting or setting intrinsinc
> "properties" of the array.  Attributes are used for properties that are
> important in defining what an array *is*.   The flags attribute, for
> example, is an important intrinsinc property of the array but it returns
> an flags object when it is accessed.   The flat attribute also returns a
> new object (it is arguable whether it should have been a method or an
> attribute but it is enough of an intrinsic property --- setting the flat
> attribute sets elements of the array -- that with historical precedence
> it was left as an attribute).
>
> By this meausure,  the array interface should be an attribute.
>

Array interface is not an intrinsic property of the array, but rather
an alternative  representation of the array itself.

Flags are properly an attribute because they are settable.  Something like

>>> x.flags()['WRITEABLE'] = False

although technically possible, would be quite ugly.

Similarly, shape attribute,  although fails my rule of thumb by
creating a new object,

>>> x.shape is x.shape
False

is justifiably an attribute because otherwise two methods: get_shape
and set_shape would be required.

I don't think "flat" should be an attribute, however.   I could not
find the reference, but I remember a discussion of why __iter__ should
not be an attribute and IIRC the answer was because an iterator has a
mutable state that is not reflected in the underlying object:

>>> x = arange(5)
>>> i = x.flat
>>> list(i)
[0, 1, 2, 3, 4]
>>> list(i)
[]
>>> list(x.flat)
[0, 1, 2, 3, 4]

> >> My problem with __array_struct__ returning either a tuple or a CObject
> >> is that array protocol sholuld really provide both.
> >
> This is a convincing argument.   Yes, the array protocol should provide
> both.  Thus, we can't over-ride the usage of the same name unless that
> name produces an object through which both interfaces can be obtained.
>
> Is that Sasha's suggestion?
>
It was, but I quckly retracted it in favor of a mechanism to unpack the CObject.
FWIW, I am also now -0 on the name change from __array_struct__ to
__array_interface__ if what it provides is just a struct wrapped in a
CObject.


___
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion