Checking if each individual element is within a range of 80 by comparing it to the next element

I have a .csv file containing 2289 data points. The first ten are as follows:

[1071936.0, 1231944.0, 1391953.0, 1551957.0, 1711960.0, 1711961.0, 1871964.0, 2031968.0, 2031969.0, 2191973.0]

Within this dataset, there are two specific data points on rows 5 and 6 that are only one value apart. Since the array is sorted in ascending order, I want to check if element X and element X + 1 are within 80 units of each other. If they are, I intend to remove element X + 1.

n = 0
y = []
for k in range(10):
    y = duplicates_removed_tr_sc
    window = duplicates_removed_tr_sc[n]
    for x in range(80):
        if(duplicates_removed_tr_sc[k]== duplicates_removed_tr_sc[n]):
            del y[k+1] #delete the k+1 element if it is 
            window = window + 1
y = np.asarray(y)
y = sorted(y)

I attempted the above code but unfortunately did not obtain the desired result. Any assistance would be greatly appreciated!

Answer №1

When handling data, it's crucial to establish a FRESH list that contains only the desired information.

filtered_data = []
previous_value = -9999
for point in datapoints:
    if point - previous_value > 80:
        filtered_data.append(point)
    previous_value = point
filtered_data = np.array(filtered_data)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to add a new json line to an existing json file?

I'm currently working on a Python project where I need to manipulate a JSON file. with open('..\config_4099.json', "r") as fid: jaySon = json.load(fid) The json file has a flat structure, so there are no internal elements to modif ...

What is the process of leveraging Numpy to calculate the product of each element in matrix x with every element in matrix y?

As I incorporate Numpy into my neural network, I am facing a challenge with implementing a step when updating the weights. This step involves an input rho_deltas (shape: (m,)) and self.node_layers[i-1].val (shape: (n,)), producing an output of self.previo ...

What specific Python error is triggered by the message 'OSError: [Errno 98] Address already in use'?

I'm currently developing a simple Python TCP socket server. I am looking to handle a certain exception mentioned earlier in my code. Can anyone provide guidance on what should be placed after except in order to achieve this? ...

Javascript splice method mistakenly eliminating the incorrect elements

I have an array of objects like the one below: [{"name":"Rain"},{"name":"Storm"},{"name":"Forest"}] These objects are indexed as follows: [0, 1, 2]. I'm attempting to delete an item at a specific position using this code: $scope.selectedSound ...

Converting POST data into an array using Angular

I am facing an issue with my post request setup in a NodeJS app. The data sent returns as an array, but I am struggling to convert it into the desired format. My Angular code is structured as follows: newWord = ''; keyword = ''; onCli ...

Encountering a StaleElementReferenceException when attempting to interact with buttons in a dynamically updated table using Python with Selenium Webdriver

Encountering a StaleElementReferenceException while testing a webpage with a table is proving to be a challenge. The table includes points and the status of two Blocking points, each with toggle state buttons for 'Yes' and 'No'. The st ...

Scraping data from the web using Selenium and the 'CLASS_NAME' attribute should only exclude certain elements

In Python, when using Selenium for web scraping, is there a way to locate an element by its CLASS_NAME but only return the elements under the class name 'xxxx' and not those under 'xxxxyy'? The following code retrieves all elements wit ...

Converting Grouped Pandas DataFrames to JSON format

I am encountering some difficulties converting the given dataframe into a JSON structure. Despite my attempts, I haven't been able to complete the final step successfully. Here is the data frame I have: serialNumber | date | part | value | n ...

Error: The JSON array could not be parsed because the value was not found within it

After arranging the array in ascending order, I have obtained the following JSON array: [{"id":0,"dependency":"no","position":0,"type":"textinput","label":"t01"},{"id":0,"dependency":"no","position":1,"type":"textarea","label":"t02"},{"id":1,"dependency": ...

A TypeScript class transferring data to a different class

I have a set of class values that I need to store in another class. function retainValues(data1,data2){ this.first = data1; this.second = data2; } I am looking for a way to save these class values in a different class like this -> let other = NewC ...

Unable to render page with scrapy and javascript using splash

I am currently trying to crawl this specific page. Following a guide on Stack Overflow to complete this task, I attempted to render the webpage but faced issues. How can I resolve this problem? This is the command I used: scrapy shell 'http://local ...

Issues with deleting dictionaries from a list using Python

I have encountered a puzzling issue in my code. There are certain pieces of logic where keys/values or dictionaries get removed under specific conditions. However, when these objects are added to a top-level dictionary and converted into a JSON object, the ...

What is the best way to retrieve a subprocess in a Flask application?

I have a question regarding my Python Flask script. I am fairly new to Python and Flask, so please bear with me. The second decorator in my code is supposed to return the subprocess to the /results page. While the ping test does print in the terminal, I ...

Establish relationships with points of intersection

I've managed to successfully generate the vertices of a sphere using a function. However, I'm now facing a challenge in generating the edges/connectivity between these vertices. Does anyone have any suggestions or solutions on how I can achieve t ...

What is the best way to access data from outside a forEach loop in JavaScript?

I am trying to access the value of my uid outside of the foreach loop in my code. Can anyone assist me with this? This is the code I am working with: var conf_url = "https://192.168.236.33/confbridge_participants/conference_participants.json?cid=009000 ...

Using Symfony 3 to iterate through an array containing different Classes

Is there a way to extract values from JSON data that have been placed into my classes (Match, Player)? I attempted using a foreach loop, but found it challenging since the data is stored in classes. Can someone provide guidance on how to tackle this issue ...

Retrieving information from a text file using Python 3

I have created a script that saves players' names along with their scores. My goal is to retrieve this data back into Python for the purpose of organizing it into a table within a user interface. I believe there must be a straightforward solution, b ...

What is the best way to generate bootstrap rows from this code in React JS?

In my current array of objects, I have twelve items: { data:[ { type:"tweets", id:"1", attributes:{ user_name:"AKyleAlex", tweet:"<a href="https://twitter.com/Javi" target="_blank"> ...

Divergent Results in Sorting Algorithms Between Python Arrays and Numpy Arrays

Below, you will find some code for a merge sort algorithm that I have implemented. Initially, I tested it using a Python array of integers and everything was working perfectly. However, when I decided to test it further by generating a random set of number ...

Pytorch issue: RuntimeError - The last dimension of the input must match the specified input size. Expected dimension 7, but received dimension 1

I am currently delving into the realm of machine learning and working on constructing an LSTM neural network. My model takes in 7 features as input and aims to predict 2 labels. However, I encountered an error when passing all 7 inputs into the LSTM laye ...