comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: How to extract a scalar from a vector?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: How to extract a scalar from a vector? [message #74160] Tue, 04 January 2011 16:03 Go to next message
Balt is currently offline  Balt
Messages: 16
Registered: May 2010
Junior Member
David,

Perfect solution! You never cease to amaze... thanks so much!

Cheers

- Balt
Re: How to extract a scalar from a vector? [message #74161 is a reply to message #74160] Tue, 04 January 2011 15:43 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
> I think the problem is that IDL thinks that cal_data[sel_cal_data,2]
> and cal_data[sel_cal_data,3] are vectors of dimension 1, when they
> should be scalars.

I do not know what you mean by "thinks they are" 1-element arrays.
They *are* 1-element arrays. Any time an array indexed by an array (in
this case, the result of where), the result is an array, even if it
only has 1 element.

> See this:
> IDL> help,cal_data[sel_cal_data,
> 3]
> <Expression>    DOUBLE    = Array[1]

You are right that this is the problem, since the product of arrays of
different sizes has the size of the smaller of the two, in this case,
1.


> How on earth can I make cal_data[sel_cal_data,2] and
> cal_data[sel_cal_data,3] into a scalar? I tried this:

Use just one element of sel_cal_data (the one element is a scalar),
instead of the whole sel_cal_data array:

cal_data[sel_cal_data[0],3]
Re: How to extract a scalar from a vector? [message #74162 is a reply to message #74161] Tue, 04 January 2011 15:37 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Balt writes:

> See this:
> IDL> help,cal_data[sel_cal_data,3]
> <Expression> DOUBLE = Array[1]
>
> How on earth can I make cal_data[sel_cal_data,3] into
> a scalar?

IDL> Help, (cat_data[sel_cal_data,3])[0]

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: How to extract a scalar from a vector? [message #74259 is a reply to message #74160] Tue, 04 January 2011 16:08 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Balt writes:

> Perfect solution! You never cease to amaze... thanks so much!

This problem is one of the classic IDL gotchas!
I was just reading about it earlier today in the
Contour chapter of my new book. :-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: How to extract a scalar from a vector? [message #74493 is a reply to message #74162] Tue, 18 January 2011 23:07 Go to previous messageGo to next message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
Am 05.01.2011 00:37, schrieb David Fanning:
> Balt writes:
>
>> See this:
>> IDL> help,cal_data[sel_cal_data,3]
>> <Expression> DOUBLE = Array[1]
>>
>> How on earth can I make cal_data[sel_cal_data,3] into
>> a scalar?
>
> IDL> Help, (cat_data[sel_cal_data,3])[0]
>
> Cheers,
>
> David
>
>
>

Sometimes a scalar function
http://www.fz-juelich.de/icg/icg-1/idl_icglib/idl_source/idl _work/rb_lib/scalar.pro


makes it easier to initialize data e.g.
scalar(MAKE_ARRAY(1,val=1,type=m_type))

cheers

Reimar
Re: How to extract a scalar from a vector? [message #94779 is a reply to message #74162] Wed, 11 October 2017 03:10 Go to previous message
chrisbuc is currently offline  chrisbuc
Messages: 1
Registered: October 2017
Junior Member
On Tuesday, 4 January 2011 23:37:35 UTC, David Fanning wrote:
> Balt writes:
>
>> See this:
>> IDL> help,cal_data[sel_cal_data,3]
>> <Expression> DOUBLE = Array[1]
>>
>> How on earth can I make cal_data[sel_cal_data,3] into
>> a scalar?
>
> IDL> Help, (cat_data[sel_cal_data,3])[0]
>
> Cheers,
>
> David
>
>
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Thanks Dave,
I would never have thought of (arr[0])[0] to get a scaler from a 1 element array. Cheers :-)
Chris Buckley
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Colorimetric map in IDL
Next Topic: Using color tables in function graphics

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 05:19:16 PDT 2025

Total time taken to generate the page: 0.00446 seconds