Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1017669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:44:24+00:00 2026-05-16T10:44:24+00:00

In Mathematica the command Select only lets define a selection criterion for each element

  • 0

In Mathematica the command Select only lets define a selection criterion for each element of a list on its own.

I want to specify a criterion that is dependend of a function of the previous and/or next element and a function on all elements, respectively. The first and last element cannot be tested that way, but they should be selected anyway.

Doing that iteratively probably would not be a problem, I want to try it functional first.

I would imaging using it somehow like that:

Select[list,FirstQ||LastQ,Func1[#-1,#]&&Func2[#,#1]&&Func3[list]&]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:44:25+00:00Added an answer on May 16, 2026 at 10:44 am

    I suggest using the Partition function. To get each element of a list grouped with its immediate neighbors you can do this

    Partition[{a,b,c,d,e}, 3, 1]
    

    to get this:

    {{a,b,c}, {b,c,e}, {c,d,e}}
    

    Knowing that, we can make a “select with neighbors” function that roughly matches your spec:

    SelectWN[list_, firstq_, lastq_, trinaryfunc_] := Join[
      If[firstq, {First@list}, {}], 
      Select[Partition[list, 3, 1], trinaryfunc@@#&][[All,2]], 
      If[lastq, {Last@list}, {}]]
    

    Note that in the arguments to trinaryfunc, #2 is the list element itself, #1 is the left neighbor, and #3 is the right neighbor.
    It would be nice to generalize this to use any number of neighbors, not just the immediate neighbors, but then you’d want a better way to refer to them than the analog of {#1, #2, #3}.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does mathematica have something like select any that gets any element of a list
I have a big list of rules in Mathematica, but I want to select
Consider the following dialog with the command-line interface to the kernel: $ math Mathematica
Mathematica's list of built-in formats is pretty extensive; however, JSON is not on that
In Mathematica I have a list: x = {1,2,3,3,4,5,5,6} How will I make a
The problem is that I want to output Mathematica compatible floating point numbers. The
In Mathematica, it is possible to reuse the output of the previous command by
The output of the Mathematica command ListPointPlot3D[ Join @@ Table[{x, y, 0}, {x, -6,
I want to create a formatted document from a list of expressions. One of
I am doing a computing-intensive benchmark using Mathematica and its J/Link Java interface. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.