I have three lists: "targets", "contexts", and "labels." I'm iterating through the list, and trying to delete rows in the "targets" and the "contexts" lists where the equivalent row in "labels" is a 0. But, when I try to delete the row in my "contexts" list, Numpy complains that whatever's supposed to be in that row doesn't exist.

```
import json
import numpy as np
import pandas as pd
import os
assert os.path.isfile("train-v1.1.json"),"Non-existent file"
from tensorflow.python.client import device_lib
import tensorflow.compat.v1 as tf
#import keras
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
import re
regex = re.compile(r'\W+')
#Reading the files.
def readFile(filename):
  with open(filename) as file:
    fields = []
    JSON = json.loads(file.read())
    articles = []
    for article in JSON["data"]:
      articleTitle = article["title"]
      article_body = []
      for paragraph in article["paragraphs"]:
        paragraphContext = paragraph["context"]
        article_body.append(paragraphContext)
        for qas in paragraph["qas"]:
          question = qas["question"]
          answer = qas["answers"][0]
          fields.append({"question":question,"answer_text":answer["text"],"answer_start":answer["answer_start"],"paragraph_context":paragraphContext,"article_title":articleTitle})
      article_body = "\\n".join(article_body)
      article = {"title":articleTitle,"body":article_body}
      articles.append(article)
  fields = pd.DataFrame(fields)
  fields["question"] = fields["question"].str.replace(regex," ")
  assert not (fields["question"].str.contains("catalanswhat").any())
  fields["paragraph_context"] = fields["paragraph_context"].str.replace(regex," ")
  fields["answer_text"] = fields["answer_text"].str.replace(regex," ")
  assert not (fields["paragraph_context"].str.contains("catalanswhat").any())
  fields["article_title"] = fields["article_title"].str.replace("_"," ")
  assert not (fields["article_title"].str.contains("catalanswhat").any())
  return fields,JSON["data"]
trainingData,training_JSON = readFile("train-v1.1.json")
print("JSON dataset read.")
#Text preprocessing
## Converting text to skipgrams
print("Tokenizing sentences.")
strings = trainingData.drop("answer_start",axis=1)
strings = strings.values.flatten()
textTokenizer = Tokenizer()
textTokenizer.fit_on_texts(strings)
questionsTokenized_train = pad_sequences(textTokenizer.texts_to_sequences(trainingData["question"]))
print(questionsTokenized_train.shape)
contextTokenized_train = pad_sequences(textTokenizer.texts_to_sequences(trainingData["paragraph_context"]))
print("Sentences tokenized.")
from tensorflow.keras.preprocessing.text import *
from tensorflow.keras.preprocessing.sequence import skipgrams,make_sampling_table
def skipgrams_labels(sequence,vocabulary_length,window_size=3):
    try:
        couples,labels = skipgrams(sequence,vocabulary_length,window_size=window_size)
        assert len(couples) > 0
        target_word,context = zip(*couples)
        return np.array([target_word,context,labels]).T
    except Exception as e:
        raise ValueError("Exception in skipgrams_labels")
    def positive_skipgrams(sequence,vocabulary_length,window_size=3):
        targets,contexts,labels = skipgrams_labels(sequence,vocabulary_length,window_size=3)
        for target,context,label in zip(targets,contexts,labels):
            if (label == 0):
                targets = np.delete(targets,target)
                contexts = np.delete(contexts,context)
        return targets,contexts

```

Error:

> 
> --------------------------------------------------------------------------- IndexError Traceback (most recent call
>  last) in ()
>  ----> 1 question\_skipgrams\_train = [positive\_skipgrams(sequence,vocabulary\_length) for sequence in
>  questionsTokenized\_train]
> 
> 
>  in (.0)
>  ----> 1 question\_skipgrams\_train = [positive\_skipgrams(sequence,vocabulary\_length) for sequence in
>  questionsTokenized\_train]
> 
> 
>  in positive\_skipgrams(sequence,
>  vocabulary\_length, window\_size)
>  4 if (label == 0):
>  5 targets = np.delete(targets,target)
>  ----> 6 contexts = np.delete(contexts,context)
>  7 return targets,contexts
> 
> 
> ~/anaconda3/envs/tensorflow\_p36/lib/python3.6/site-packages/numpy/lib/function\_base.py
>  in delete(arr, obj, axis) 4374 raise IndexError(  
> 
>  4375 "index %i is out of bounds for axis %i with "
>  -> 4376 "size %i" % (obj, axis, N)) 4377 if (obj < 0): 4378 obj += N
> 
> 
> IndexError: index 44086 is out of bounds for axis 0 with size 132
> 
> 
> 

I don't understand why anything's wrong here. This feels like a bit of a weird error, because NumPy must have been able to find the element - else why wouldn't the for loop be the one with an error?

I even replaced the skipgrams\_labels function with hardcoded values, indicating something must be wrong with the function.

What do you recommend I do instead?