MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Using Extract where some indices are out of bounds (efficiently)

On Jan 8, 12:38 am, Julian Francis <julian.w.fran... at> wrote:
> [...]
> Thank you very much; that is excellent. My timings indicates your
> version is approximately 40 times faster than my original extract
> with arrayInBounds version.

Here's an improved version of myExtract2 that seems a little faster,
and a similar function, myExtract3, that may be faster still.

myExtract2[array_,indices_] := Extract[array, Part[indices,
  SparseArray[Times@@UnitStep[(#-1)*(Dimensions@array-#)& @
  Transpose@indices]] /. SparseArray[_,_,_,d_] :> Flatten@d[[2,2]] ]]

myExtract3[array_,indices_] := Extract[array, Part[indices,
  {Transpose@indices, Dimensions@array}]] /.
  SparseArray[_,_,_,d_] :> Flatten@d[[2,2]] ]]

  • Prev by Date: Re: original meaning of System` functions
  • Next by Date: Re: Extracting graphics from notebook
  • Previous by thread: Re: Using Extract where some indices are out of bounds (efficiently)
  • Next by thread: Re: WAV Import[] and Integer16 Issue