0

I am trying to select the first 3 distinct points in a column excluding the first 0 point. I need distinct points to perform polynomial regression.

My_column:

  A = np.array([0, 0.5, 0, 0 ,1.0, 2.0])

Expected:

  B = np.array([0, 0.5, 0.0, 1.0])

Essentially I want to skip over one 0 and select the 1.0 instead.

Aksen P
  • 4,564
  • 3
  • 14
  • 27
  • What have you tried so far? Demonstrate this with code and highlight the exact problem you have. – sophros Jul 16 '19 at 08:40
  • Possible duplicate of [Getting first n unique elements from Python list](https://stackoverflow.com/questions/53887803/getting-first-n-unique-elements-from-python-list) – sophros Jul 16 '19 at 08:41
  • @sophros i tried to manually do an if statement to check if the previous number at location [i] == to the current number at location [i+1]. But i am unable to select it and i am not sure how to move on from here. – Ng Jian Sheng Jul 16 '19 at 08:57

1 Answers1

0
import numpy as np

A = np.array([0, 0.5, 0, 0 ,1.0, 2.0])
B = A[0]
B = np.append(B, list(set(A[1:]))[:3])
print(B)
Sraw
  • 18,892
  • 11
  • 54
  • 87