Group Abstract Group Abstract

Message Boards Message Boards

7
|
8.4K Views
|
4 Replies
|
17 Total Likes
View groups...
Share
Share this post:

ArrayCrop: anti ArrayPad, à la ImageCrop

Attachments:
POSTED BY: Vitaliy Kaurov
4 Replies
POSTED BY: Sander Huisman
POSTED BY: Sander Huisman
POSTED BY: Sander Huisman
Posted 9 years ago

Position and Extract allow a more direct approach than SparseArray while keeping the logic similar. Shorter code plus a 2-3x speedup on the 5D case makes a good trade I think.

ArrayCrop[a_, b_] :=
 Extract[a,
  Span @@@ MinMax /@
    Transpose@Position[a, Except@b, {-1}, Heads -> False]]

ArrayCrop[a_] := ArrayCrop[a, 0]
POSTED BY: Michael Hale
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard