# Extracing information from a table

I am new to Mathematica. I have created a table of real numbers. I want to create a new table that contains the set of values of $i$ such that, in my original table, the $i$th entry is greater than the $(i+1)$th entry.

For example If I had the table {1,2,5,2,9} my new table would be {3}.

Here's a way:

lis = {1, 2, 5, 2, 9};
Flatten[Position[Greater @@@ Partition[lis, 2, 1], True]]
(* {3} *)


Here's an explanation:

Partition will group the elements in twos

Partition[lis, 2, 1]
(* {{1, 2}, {2, 5}, {5, 2}, {2, 9}} *)


Then we use @@@ to apply a Greater at level 1

Greater @@@ Partition[lis, 2, 1]
(* {False, False, True, False} *)


Since 5 > 2, True appears in the third position. We use Position to see where True occurs and we're done.

pckpstn = Pick[Range[Length[#] - 1], Negative@Differences@#] &;
lst = {3, 1, 2, 5, 2, 1, 9, 1};
pckpstn@lst
(* {1, 4, 5, 7} *)

• Hey, nice to see you answering again! :) – rm -rf Mar 29 '14 at 21:00

Here's a way using ListConvolve and SparseArray's properties:

list = {1, 2, 5, 2, 9};
SparseArray[UnitStep@ListConvolve[{-1, 1}, list]]["NonzeroPositions"]
(* {{3}} *)