2

I have a Numpy array of the form:

40002 1511863545
40000 1511863546
156 1511863547
40005 1511863547
40003 1511863548
40008 1511863549
340 1511863550
40011 1511863550
...

The first column is data, the second timestamps. The data is in two parts, separated by a gap of 40000.

What I need is two datasets:

156 1511863547
340 1511863550
...

and:

2 1511863545
0 1511863546
5 1511863547
3 1511863548
8 1511863549
11 1511863550

How can I,

  1. Split the data according to the value in the first column?
  2. Subtract 40000 from the first column of the second new dataset (leaving the timestamps intact)?

1 Answer 1

1

You can use a fairly simple test to do that like:

Code:

split_data = data[:, 0] < 40000
low_data = data[split_data]
high_data = data[~split_data]
high_data[:, 0] -= 40000

Test Code:

data = np.array([
    [40002, 1511863545],
    [40000, 1511863546],
    [156, 1511863547],
    [40005, 1511863547],
    [40003, 1511863548],
    [40008, 1511863549],
    [340, 1511863550],
    [40011, 1511863550],
])
print(data)

split_data = data[:, 0] < 40000
low_data = data[split_data]
high_data = data[~split_data]
high_data[:, 0] -= 40000

print(split_data)
print(low_data)
print(high_data)

Results:

[[     40002 1511863545]
 [     40000 1511863546]
 [       156 1511863547]
 [     40005 1511863547]
 [     40003 1511863548]
 [     40008 1511863549]
 [       340 1511863550]
 [     40011 1511863550]]

[False False  True False False False  True False]

[[       156 1511863547]
 [       340 1511863550]]

[[         2 1511863545]
 [         0 1511863546]
 [         5 1511863547]
 [         3 1511863548]
 [         8 1511863549]
 [        11 1511863550]]
Sign up to request clarification or add additional context in comments.

1 Comment

This answers the first part of my question, but the high_data has incorrect timestamps. I will try subtracting np.array([40000,0])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.