Python Forum
Distance between indicies of a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Distance between indicies of a list
#1
how can i determine the distance between two indices in a list of values?

given a = [-1, 5, 4, 8, 3, 21, 18, 16, 3, 2, 3, 1, 4, 5, 17, 22, 36, 33, 34, 9, 1, -2]

how can i write a code which finds the distance between a[0] and a[3]?
Reply
#2
What do you mean by distance?
If you mean position, then the distance is clearly 3.
If you mean difference between values, then it's a[3] - a[0]
Or are is it something entirely different you have in mind?
Reply
#3
Basically i have to write a function which satisfies the following criteria:

The three possible outcomes are "Insufficient data", "Not detected" and a list of non overlapping indices that are greater than or equal to the given threshold value, and that satisfy the following criteria:
- an index is not selected if the value at the index is less than a value at one of it's overlapping indices.
- an index is not selected if it is overlapping with first or last index.
We say two indices are overlapping if the distance between them is less than the width of the pattern.

an example is this:

threshold = 15
pattern_width = 4
data_series = [-1, 5, 4, 8, 3, 21, 18, 16, 3, 2, 3, 1, 4, 5, 17, 22, 36, 33, 34, 9, 1, -2]
data_series = data_series + [-2, 4, -1, 7, 13, 12, 3, 1, 4, 5, 26, 22, 28, 27, 26, 2, 8, 6]

expected_answer = [5, 16, 34]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Distance between two points! zepel 14 33,732 Apr-28-2017, 08:32 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020