Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10306 > unrolled thread

Re: vector ordering problem

Started byBill Rowe <readnews@sbcglobal.net>
First post2012-06-01 09:18 +0000
Last post2012-06-01 09:18 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: vector ordering problem Bill Rowe <readnews@sbcglobal.net> - 2012-06-01 09:18 +0000

#10306 — Re: vector ordering problem

FromBill Rowe <readnews@sbcglobal.net>
Date2012-06-01 09:18 +0000
SubjectRe: vector ordering problem
Message-ID<jqa1dc$bho$1@smc.vnet.net>
On 5/31/12 at 2:51 AM, marco.lazzaretti82@gmail.com (Marco
Lazzaretti) wrote:

>Hi, I have these two vectors, vector1 and vector2. I need to
>have vector2 sorted by a positions vector, given by a vector1. e.g.
>vector1 ={32,4,28,11,20}
>position_vector1= Ordering[vector1]
>position_vector1 = {5,1,4,2,3}

This is clearly code you did not try in Mathematica. That is:

In[1]:= vector1 = {32, 4, 28, 11, 20};
Ordering[vector1]

Out[2]= {2,4,5,3,1}

And trying to do

position_vector1 = Ordering[vector1]

will result in an error. Mathematica does not allow an
underscore character in a variable name. The underscored
character has a reserved system meaning.

>vector2 = {78,12,95,14,35}

>requested output {35,78,14,12,95}

This is easily done.

In[3]:= vector2 = {78, 12, 95, 14, 35};
pos = {5, 1, 4, 2, 3};
vector2[[pos]]

Out[5]= {35,78,14,12,95}

Here I've used the position vector you posted rather than what
would be returned by Ordering. If instead I use Ordering the
result would be:

In[6]:= vector2[[Ordering@vector1]]

Out[6]= {12,14,35,95,78}

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web