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

  • SEARCH
  • Home
  • 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 6547019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:46:46+00:00 2026-05-25T11:46:46+00:00

Given pairs of coordinates data = {{1, 0}, {2, 0}, {3, 1}, {4, 2},

  • 0

Given pairs of coordinates

data = {{1, 0}, {2, 0}, {3, 1}, {4, 2}, {5, 1}, 
        {6, 2}, {7, 3}, {8, 4}, {9, 3}, {10, 2}}

I’d like to extract peaks and valleys, thus:

{{4, 2}, {5, 1}, {8, 4}}

My current solution is this clumsiness:

Cases[
 Partition[data, 3, 1],
 {{ta_, a_}, {tb_, b_}, {tc_, c_}} /; Or[a < b > c, a > b < c] :> {tb, b}
]

which you can see starts out by tripling the size of the data set using Partition. I think it’s possible to use Cases and PatternSequence to extract this information, but this attempt doesn’t work:

Cases[
 data,
 ({___, PatternSequence[{_, a_}, {t_, b_}, {_, c_}], ___} 
         /; Or[a < b > c, a > b < c]) :> {t, b}
]

That yields {}.

I don’t think anything is wrong with the pattern because it works with ReplaceAll:

data /. ({___, PatternSequence[{_, a_}, {t_, b_}, {_, c_}], ___} 
             /; Or[a < b > c, a > b < c]) :> {t, b}

That gives the correct first peak, {4, 2}. What’s going on here?

  • 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-25T11:46:46+00:00Added an answer on May 25, 2026 at 11:46 am

    One of the reasons why your failed attempt doesn’t work is that Cases by default looks for matches on level 1 of your expression. Since your looking for matches on level 0 you would need to do something like

    Cases[
     data,
     {___, {_, a_}, {t_, b_}, {_, c_}, ___} /; Or[a < b > c, a > b < c] :> {t, b}, 
     {0}
    ]
    

    However, this only returns {4,2} as a solution so it’s still not what you’re looking for.
    To find all matches without partitioning you could do something like

    ReplaceList[data, ({___, {_, a_}, {t_, b_}, {_, c_}, ___} /; 
        Or[a < b > c, a > b < c]) :> {t, b}]
    

    which returns

    {{4, 2}, {5, 1}, {8, 4}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a data set of various currency pairs, how do I efficiently compute the
Given this sad thing below, which generates all pairs of only two ranges -
Given four (x,y) pairs that represent the four corners of an arbitrary polygon (quadrilateral)
I found the following statement: Map is an object that stores key/volume pairs. Given
Given a specific DateTime value, how do I display relative time, like: 2 hours
Given an absolute or relative path (in a Unix-like system), I would like to
Given 2 rgb colors and a rectangular area, I'd like to generate a basic
Given a series of GPS coordinate pairs, I need to calculate the area of
I have a data set with latitude and longitude coordinates (two separate decimal columns).
Given a collection of integers, what's a Java algorithm that will give all pairs

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.