Alan Jackson | 1 May 04:11

problem referencing single element arrays

Having a problem with numpy that has me stumped.

I have a large set of arrays. I want to set up cross reference lists of
elements within those arrays, with the lists just being pointers to the objects
(floating point numbers) stored in the arrays.

The problem is that some arrays have only a single element, so when I try to
store a[0] for a single element array, I get an error, "0-d arrays can't be
indexed". How do I get a pointer to the object stored and not the array for
single element arrays? 

Or maybe I don't want to be doing this?

--

-- 
-----------------------------------------------------------------------
| Alan K. Jackson            | To see a World in a Grain of Sand      |
| alan <at> ajackson.org          | And a Heaven in a Wild Flower,         |
| www.ajackson.org           | Hold Infinity in the palm of your hand |
| Houston, Texas             | And Eternity in an hour. - Blake       |
-----------------------------------------------------------------------
Robert Kern | 1 May 04:39
Picon
Gravatar

Re: problem referencing single element arrays

On Wed, Apr 30, 2008 at 9:11 PM, Alan Jackson <alan <at> ajackson.org> wrote:
> Having a problem with numpy that has me stumped.
>
>  I have a large set of arrays. I want to set up cross reference lists of
>  elements within those arrays, with the lists just being pointers to the objects
>  (floating point numbers) stored in the arrays.
>
>  The problem is that some arrays have only a single element, so when I try to
>  store a[0] for a single element array, I get an error, "0-d arrays can't be
>  indexed". How do I get a pointer to the object stored and not the array for
>  single element arrays?

a[()]

>  Or maybe I don't want to be doing this?

Quite possibly. Can you expand on your use case?

--

-- 
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
Anne Archibald | 1 May 04:41
Picon

Re: problem referencing single element arrays

2008/4/30 Alan Jackson <alan <at> ajackson.org>:
> Having a problem with numpy that has me stumped.
>
>  I have a large set of arrays. I want to set up cross reference lists of
>  elements within those arrays, with the lists just being pointers to the objects
>  (floating point numbers) stored in the arrays.
>
>  The problem is that some arrays have only a single element, so when I try to
>  store a[0] for a single element array, I get an error, "0-d arrays can't be
>  indexed". How do I get a pointer to the object stored and not the array for
>  single element arrays?
>
>  Or maybe I don't want to be doing this?

Well, I'm not totally sure I know what you mean, but I think what you
want can be done in a reasonable way. Numpy has two subtly different
kinds of object, scalars and rank zero arrays; I think rank zero
arrays can be made to do what you want, more or less, but they're kind
of a neglected corner case. But a rank-1 array that happens to have
only one element should behave in a perfectly reasonable fashion, and
indexing it with [0] should work fine. The only trick is constructing
one the right way: if A is a rank-1 array and we want to make a view
that lets us get at element j, we can do
e = A[j:j+1]
and then, for example,
e[0] = newvalue

Anne
Alan Jackson | 1 May 05:03

Re: problem referencing single element arrays

On Wed, 30 Apr 2008 21:39:53 -0500
"Robert Kern" <robert.kern <at> gmail.com> wrote:

> On Wed, Apr 30, 2008 at 9:11 PM, Alan Jackson <alan <at> ajackson.org> wrote:
> > Having a problem with numpy that has me stumped.
> >
> >  I have a large set of arrays. I want to set up cross reference lists of
> >  elements within those arrays, with the lists just being pointers to the objects
> >  (floating point numbers) stored in the arrays.
> >
> >  The problem is that some arrays have only a single element, so when I try to
> >  store a[0] for a single element array, I get an error, "0-d arrays can't be
> >  indexed". How do I get a pointer to the object stored and not the array for
> >  single element arrays?
> 
> a[()]
> 
> >  Or maybe I don't want to be doing this?
> 
> Quite possibly. Can you expand on your use case?
> 

Imagine a 3D coordinate system. I have connected, non-recumbent sheets
of various sizes in this 3D space. I set up a dictionary of arrays where
a set of 3 arrays contains the X, Y, Z-values of the points on a sheet, 
the dictionary so I can name each sheet.

I'd also like to access the data points vertically, at a particular X,Y
what are all the sheets and points? That's the purpose of my cross reference.

(Continue reading)

Jeevan Baretto | 1 May 11:09
Picon

Surrogate Model/Response Surface model

Hi,
I was looking for an optimization module in Scipy on Surrogate model ( http://en.wikipedia.org/wiki/Surrogate_model ) also known as Response Surface model. I couldn't find one. Can anyone help me out with this?

Thanks,
Jeevan

IIT Bombay

_______________________________________________
SciPy-user mailing list
SciPy-user <at> scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-user
Joseph Turian | 1 May 21:54
Picon
Gravatar

Iteration over scipy.sparse matrices?

Is there a (storage-format agnostic) method for iterating over the elements of a sparse matrix?
I don't care what order they come in. I just want to make sure that I can iterate over the matrix in time linear in nnz, and have the (row, col) and data for each non-zero entry.

Thanks!

  Joseph

--
Academic: http://www-etud.iro.umontreal.ca/~turian/
Business: http://www.metaoptimize.com/

_______________________________________________
SciPy-user mailing list
SciPy-user <at> scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-user
Dharhas Pothina | 1 May 22:15
Picon
Picon
Favicon

Converting arrays to dates for plot_date()

Hi,

I'm sure there is a simple way to do this that I'm missing. I'm coming form a matlab background and am still
having trouble understanding the interactions between arrays and lists etc

I have a file with time series data

1986 7 8 32.1
1986 7 9 42.5
1986 7 10 22.2
...

I've read this in using loadtxt to the arrays : year,month,day & data

What I want to do is use matplotlibs plot_date() command to plot the data against the date.

I've worked out that I can use something like

datestr2num(['2006-01-01','2006-01-02'])

to generate the list of dates for plot_date()

but I can't work out how to convert 

year = array([2006.0,2007.0])
month = array([11,12])
day = array([1,2])

into the form

datestring = array(['2006-11-1','2007-12-2'])

I've also tried using the datetime() function but I've worked out that doesn't work with numpy arrays.

any pointers/help would be greatly appreciated.

thanks,

- dharhas
Robert Kern | 1 May 22:20
Picon
Gravatar

Re: Surrogate Model/Response Surface model

On Thu, May 1, 2008 at 4:09 AM, Jeevan Baretto <jeevan.baretto <at> gmail.com> wrote:
> Hi,
> I was looking for an optimization module in Scipy on Surrogate model (
> http://en.wikipedia.org/wiki/Surrogate_model ) also known as Response
> Surface model. I couldn't find one. Can anyone help me out with this?

There is nothing in particular in scipy which forms the surrogate
models except perhaps splines in scipy.interpolate if the dimensions
are small. There is some Gaussian process (equivalent to kriging) code
here:

  http://code.google.com/p/random-realizations/

Once you have fitted the surrogate model, you can make a function from
it to pass to any of the optimization routines in scipy.optimize.

--

-- 
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
Anne Archibald | 1 May 22:27
Picon

Re: Polynomial interpolation

2008/4/30 Rob Clewley <rob.clewley <at> gmail.com>:
> Could someone please make the new interpolation classes into new-style
>  classes? And I don't know if it's considered a big deal, but for
>  future compatibility maybe the exception raising should be done in the
>  functional style: ValueError("message") rather than ValueError,
>  message ?

Done. Plus the procedural versions are there. (Thirty-eight lines of
docstring for two lines of function!)

Anne
John Hunter | 1 May 22:49
Picon
Gravatar

Re: Converting arrays to dates for plot_date()

On Thu, May 1, 2008 at 3:15 PM, Dharhas Pothina
<Dharhas.Pothina <at> twdb.state.tx.us> wrote:

>  to generate the list of dates for plot_date()
>
>  but I can't work out how to convert
>
>  year = array([2006.0,2007.0])
>  month = array([11,12])
>  day = array([1,2])

dates = [datetime.date(y,m,d) for y,m,d in zip(year, month, day)]
plot(dates, data)  # requires 0.91.2 or svn -- else use date2num and plot_date

JDH

Gmane