[Numpy-discussion] segfault in vdot

2009-12-17 Thread Neal Becker
http://projects.scipy.org/numpy/ticket/1335

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] np.void from 0d array + subclassing

2009-12-17 Thread Pierre GM
All,
* What is the most efficient way to get a np.void object from a 0d structured 
ndarray ?
* Is there any way to subclass np.void ?
Thanks a lot in advance !
P.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] np.void from 0d array + subclassing

2009-12-17 Thread Francesc Alted
A Thursday 17 December 2009 15:16:29 Pierre GM escrigué:
 All,
 * What is the most efficient way to get a np.void object from a 0d
  structured ndarray ?

I normally use `PyArray_GETITEM` C macro for general n-d structured arrays.  I 
suppose that this will work with 0-d arrays too.

-- 
Francesc Alted
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] np.void from 0d array + subclassing

2009-12-17 Thread David Goldsmith
On Thu, Dec 17, 2009 at 6:16 AM, Pierre GM pgmdevl...@gmail.com wrote:
 All,
 * What is the most efficient way to get a np.void object from a 0d structured 
 ndarray ?
 * Is there any way to subclass np.void ?

The standard way (more or less) works for me:

 class myvoidclass(np.void):
... pass
...
 foo = myvoidclass()
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: function takes exactly 1 argument (0 given)
 foo = myvoidclass(1)
 dir(foo)
['T', '__abs__', '__add__', '__and__', '__array__',
'__array_interface__', '__array_priority__', '__array_struct__', '__
array_wrap__', '__class__', '__copy__', '__deepcopy__', '__delattr__',
'__delitem__', '__dict__', '__div__', '__divmod__
', '__doc__', '__eq__', '__float__', '__floordiv__', '__ge__',
'__getattribute__', '__getitem__', '__gt__', '__hash__',
'__hex__', '__init__', '__int__', '__invert__', '__le__', '__len__',
'__long__', '__lshift__', '__lt__', '__mod__', '__m
odule__', '__mul__', '__ne__', '__neg__', '__new__', '__nonzero__',
'__oct__', '__or__', '__pos__', '__pow__', '__radd__
', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__',
'__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__
rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__',
'__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__seta
ttr__', '__setitem__', '__setstate__', '__str__', '__sub__',
'__truediv__', '__weakref__', '__xor__', 'all', 'any', 'arg
max', 'argmin', 'argsort', 'astype', 'base', 'byteswap', 'choose',
'clip', 'compress', 'conj', 'conjugate', 'copy', 'cum
prod', 'cumsum', 'data', 'diagonal', 'dtype', 'dump', 'dumps', 'fill',
'flags', 'flat', 'flatten', 'getfield', 'imag', '
item', 'itemset', 'itemsize', 'max', 'mean', 'min', 'nbytes', 'ndim',
'newbyteorder', 'nonzero', 'prod', 'ptp', 'put', '
ravel', 'real', 'repeat', 'reshape', 'resize', 'round',
'searchsorted', 'setfield', 'setflags', 'shape', 'size', 'sort',
 'squeeze', 'std', 'strides', 'sum', 'swapaxes', 'take', 'tofile',
'tolist', 'tostring', 'trace', 'transpose', 'var', 'v
iew']

Is there something more specific you want to do?

DG

 Thanks a lot in advance !
 P.
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] np.void from 0d array + subclassing

2009-12-17 Thread Pierre GM
On Dec 17, 2009, at 10:16 AM, Francesc Alted wrote:
 A Thursday 17 December 2009 15:16:29 Pierre GM escrigué:
 All,
 * What is the most efficient way to get a np.void object from a 0d
 structured ndarray ?
 
 I normally use `PyArray_GETITEM` C macro for general n-d structured arrays.  
 I 
 suppose that this will work with 0-d arrays too.

Francesc, you're overestimating my knowledge of C... Can we stick to the Python 
implementation ?
Here's the catch: IIUC, each individual element of a nD structured array is a 
void, provided the element can be accessed, ie that n0. A 0D array cannot be 
indexed, so I don't know how capture the object below. The sad trick I found 
was to do a .reshape(1)[0], but that looks really overkill...

 
 The standard way (more or less) works for me:
 
 class myvoidclass(np.void):
 ... pass
 ...

David, what do you do w/ the __new__ of myvoidclass ? Just an empty class 
doesn't help me much, 'm'fraid.

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] np.void from 0d array + subclassing

2009-12-17 Thread David Goldsmith
On Thu, Dec 17, 2009 at 2:11 PM, Pierre GM pgmdevl...@gmail.com wrote:
 Francesc, you're overestimating my knowledge of C... Can we stick to the 
 Python implementation ?
 Here's the catch: IIUC, each individual element of a nD structured array is a 
 void, provided the element can be accessed, ie that n0. A 0D array cannot be 
 indexed, so I don't know how

Unless someone can explain why it isn't, this sounds like an API
inconsistency, which in turn I would characterize as a bug.  But
others may disagree and/or explain it away...

 capture the object below. The sad trick I found was to do a .reshape(1)[0], 
 but that looks really overkill...


 The standard way (more or less) works for me:

 class myvoidclass(np.void):
 ...     pass
 ...

 David, what do you do w/ the __new__ of myvoidclass ? Just an empty class 
 doesn't help me much, 'm'fraid.

Presumably, whatever you want (i.e., override it, calling the base
class constructor inside your __new__ if/when needed) - I've never
done this, so I have no reason to believe it would/should behave any
differently than any other Python subclass; your question merely
provoked me to check to see if the normal subclassing syntax did not
work for some reason, and since I found that it did, I thought I'd
post that result as a data point.  Now, if you're generally
unfamiliar (but it doesn't sound like you are) with what to do with a
subclass' __new__, I'm sure someone else can more easily point you to
a reference for that issue.  Is there some reason you believe you have
to override __new__ differently in your use-case?

DG


 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] np.void from 0d array + subclassing

2009-12-17 Thread Robert Kern
On Thu, Dec 17, 2009 at 16:11, Pierre GM pgmdevl...@gmail.com wrote:
 On Dec 17, 2009, at 10:16 AM, Francesc Alted wrote:
 A Thursday 17 December 2009 15:16:29 Pierre GM escrigué:
 All,
 * What is the most efficient way to get a np.void object from a 0d
 structured ndarray ?

 I normally use `PyArray_GETITEM` C macro for general n-d structured arrays.  
 I
 suppose that this will work with 0-d arrays too.

 Francesc, you're overestimating my knowledge of C... Can we stick to the 
 Python implementation ?
 Here's the catch: IIUC, each individual element of a nD structured array is a 
 void, provided the element can be accessed, ie that n0. A 0D array cannot be 
 indexed, so I don't know how capture the object below. The sad trick I found 
 was to do a .reshape(1)[0], but that looks really overkill...

a[()]

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth.
  -- Umberto Eco
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] np.void from 0d array + subclassing

2009-12-17 Thread Pierre GM
On Dec 17, 2009, at 6:35 PM, Robert Kern wrote:
 On Thu, Dec 17, 2009 at 16:11, Pierre GM pgmdevl...@gmail.com wrote:
 On Dec 17, 2009, at 10:16 AM, Francesc Alted wrote:
 A Thursday 17 December 2009 15:16:29 Pierre GM escrigué:
 All,
 * What is the most efficient way to get a np.void object from a 0d
 structured ndarray ?
 
 I normally use `PyArray_GETITEM` C macro for general n-d structured arrays. 
  I
 suppose that this will work with 0-d arrays too.
 
 Francesc, you're overestimating my knowledge of C... Can we stick to the 
 Python implementation ?
 Here's the catch: IIUC, each individual element of a nD structured array is 
 a void, provided the element can be accessed, ie that n0. A 0D array cannot 
 be indexed, so I don't know how capture the object below. The sad trick I 
 found was to do a .reshape(1)[0], but that looks really overkill...
 
 a[()]

Well, that's slick and really neat !!! Typically Robert K's... Thanks a lot !!!
And would you have anything as cool for the reverse operation (from np.void to 
0d array) ?
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] np.void from 0d array + subclassing

2009-12-17 Thread Robert Kern
On Thu, Dec 17, 2009 at 17:41, Pierre GM pgmdevl...@gmail.com wrote:
 On Dec 17, 2009, at 6:35 PM, Robert Kern wrote:
 On Thu, Dec 17, 2009 at 16:11, Pierre GM pgmdevl...@gmail.com wrote:

 Here's the catch: IIUC, each individual element of a nD structured array is 
 a void, provided the element can be accessed, ie that n0. A 0D array 
 cannot be indexed, so I don't know how capture the object below. The sad 
 trick I found was to do a .reshape(1)[0], but that looks really overkill...

 a[()]

 Well, that's slick and really neat !!! Typically Robert K's... Thanks a lot 
 !!!
 And would you have anything as cool for the reverse operation (from np.void 
 to 0d array) ?

a = np.array(v)

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth.
  -- Umberto Eco
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] np.void from 0d array + subclassing

2009-12-17 Thread David Goldsmith
On Thu, Dec 17, 2009 at 3:46 PM, Robert Kern robert.k...@gmail.com wrote:
 On Thu, Dec 17, 2009 at 17:41, Pierre GM pgmdevl...@gmail.com wrote:
 Well, that's slick and really neat !!! Typically Robert K's... Thanks a lot 
 !!!

Yeah, sometimes I think the only reason we have a mailing list is so
that we're not all just emailing Robert all the time... ;-)

DG
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] [AstroPy] Rotating and Transforming Vectors--Flight Path of a Celestial Body

2009-12-17 Thread Wayne Watson
It's starting to come back to me. I found a few old graphics books that
get into transformation matrices and such. Yes, earth centered. I ground
out some code with geometry and trig that at least gets the first point
on the path right. I think I can probably apply a rotation around the
x-axis several times with a 1/2 degree rotation for each step towards
the north to get the job done.

I'm still fairly fresh with Python, and found a little bit of info in a
Tentative numpy tutorial. I found this on getting started with matrices:

from numpy import matrix

Apparently matrix is a class in numpy, and there are many others, linalg 
I think is one. How
does one find all the classes, and are there rules that keep them apart. 
It was tempting to add
import numpy in addition to the above, but how is what is in numpy 
different that the classes?
Is numpy solely class driven? That is, if one does a from as above to 
get all the classes, does
it give all the capabilities that just using import numpy does?


Anne Archibald wrote:
 2009/12/17 Wayne Watson sierra_mtnv...@sbcglobal.net:
   
 I'm just getting used to the math and numpy library, and have begun
 working on a problem of the following sort.

 Two observing stations are equidistant, 1/2 degree, on either side of a
 line of longitude of 90 deg west, and both are at 45 deg latitude. Given
 the earth's circumference as 25020 miles, a meteor is 60 miles above the
 point between the two sites. That is, if you were standing at long
 90deg  and lat 45 deg, the meteor would be that high above you. 70 miles
 along the long line is 1 degree, so the stations are 70 miles apart.  I
 want to know the az and el of the meteor from each station.  With some
 geometry and trig, I've managed to get that first point; however,  I can
 see  moving the meteor say, 1/2 deg, along its circular path towards the
 north pole is going to require more pen and pencil work to get the az/el
 for it.

 Long ago in a faraway time, I used to do this stuff. It should be easy
 to rotate the vector to the first point 1/2 deg northward, and find the
 vector there, then compute the new az and el from each station. Maybe.
 I'm just beginning to look at the matrix and vector facilities in numpy.
 Maybe someone can comment on how this should be done, and steer me
 towards what I need to know in numpy.
 

 You may find that the problem grows drastically easier if you work as
 much as possible in so-called earth-centered earth-fixed coordinates
 (sometimes called XYZ) coordinates. These are a rectilinear coordinate
 system that rotates with the earth, with the Z axis through the north
 pole and the X axis through the equator at the Greenwich meridian.
 It's kind of horrible for getting altitudes, since the Earth is sort
 of pear-shaped, but it makes the 3D geometry much simpler.

 If you don't go this route, I'd recommend picking one station and
 defining a rectilinear coordinate system based on its north and
 vertical vectors. The north and vertical vectors of the other station
 will be at somewhat funny angles (unless you can get away with
 treating the Earth as flat between the two), but whatever rectilinear
 coordinates you choose, a dot product lets you calculate vector
 lengths and angles between them, and a cross product lets you build
 vectors orthogonal to a given pair. So, for example, if your station
 has north vector N and up vector U, you can get its east vector as
 E=cross(N,U) (then normalize it); if you want to convert an absolute
 north to a local north (i.e. one that is horizontal) you can do
 N=cross(E,U) (and normalize it). Then you can get the azimuth of a
 vector V using dot(N,V)/sqrt(dot(V,V)) and dot(E,V)/sqrt(dot(V,V)).


 Anne

   

-- 
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 ... humans'innate skills with numbers isn't much
  better than that of rats and dolphins.
   -- Stanislas Dehaene, neurosurgeon

Web Page: www.speckledwithstars.net/


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] [AstroPy] Rotating and Transforming Vectors--Flight Path of a Celestial Body

2009-12-17 Thread Anne Archibald
2009/12/18 Wayne Watson sierra_mtnv...@sbcglobal.net:
 It's starting to come back to me. I found a few old graphics books that
 get into transformation matrices and such. Yes, earth centered. I ground
 out some code with geometry and trig that at least gets the first point
 on the path right. I think I can probably apply a rotation around the
 x-axis several times with a 1/2 degree rotation for each step towards
 the north to get the job done.

 I'm still fairly fresh with Python, and found a little bit of info in a
 Tentative numpy tutorial. I found this on getting started with matrices:

 from numpy import matrix

 Apparently matrix is a class in numpy, and there are many others, linalg
 I think is one. How
 does one find all the classes, and are there rules that keep them apart.
 It was tempting to add
 import numpy in addition to the above, but how is what is in numpy
 different that the classes?
 Is numpy solely class driven? That is, if one does a from as above to
 get all the classes, does
 it give all the capabilities that just using import numpy does?

Many things in python are classes; a class is a way of attaching
relevant functions to a collection of data (more precisely, a class is
a *type*, defining the interpretation of data; usually they also carry
a collection of functions to operate on that data). So the central
feature of numpy is a class, ndarray, that represents a collection of
values of homogeneous type. This may be one, two, or many-dimensional,
and there are various operations, including linear algebra, on them
available in numpy.

The matrix class is a special kind of ndarray in which a number of
modifications have been made. In particular, the * operator no longer
does element-wise operations, it does matrix multiplication. There are
also various rules designed to ensure that matrix objects are always
two-dimensional. I avoid matrix objects like the plague, but some
people find them useful.

numpy.linalg is an entirely different beast. It is a *module*, a
collection of functions (and potentially objects and classes). It is
like sys or os: you import it and the functions, objects and classes
it contains become available. This is a basic feature of python. What
is unusual (but not unique) is that rather than having to explicitly
import it like:

import numpy
import numpy.linalg

numpy.linalg.svd(numpy.ones((3,2)))

numpy automatically imports it for you, every time. This is done for
historical reasons and won't change, but is a wart.

For your purposes, I recommend simply using numpy arrays -
three-element arrays for vectors, three-by-three for matrices - and
using the linear algebra functions numpy provides to act on them. For
example, dot does matrix-matrix, matrix-vector, and vector-vector
multiplication.


Anne

P.S. you can usually write out a rotation explicitly, e.g. as
[[cos(t), sin(t), 0],
 [-sin(t), cos(t), 0],
 [0, 0, 1]]
but if you want a more general one I believe there's a clever way to
make it using two reflections. -A
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion