0

In my case I had array list of:

testSet =[[14017.0, 146.58, 5.0, '1'], [3869.0, 91.66, 5.0, '1'], [9365.0, 131.16, 5.0, '1'], [1258.0, 62.8, 5.0, '1'], [2979.0, 95.9, 4.0, '1'], [5556.0, 109.4, 5.0, '1'], [14501.0, 144.0, 5.0, '1'], [3664.0, 106.5, 5.0, '1'], [6149.0, 117.6, 2.0, '2'], [5556.0, 109.4, 5.0, 2']]

I just wanna copy the last element in every array to my new array. How to copy that array so I can get output:

[1,1,1,1,1,1,1,1,2,2]
2
  • list, i dont use numpy Commented Jun 16, 2020 at 8:21
  • yes, iam sorry. Commented Jun 16, 2020 at 8:36

1 Answer 1

1

Just you list comprehension and you are good to go.

new = [array[-1] for array in testSet]

Complexity is just O(n) where n is the length of your testSet.

Sign up to request clarification or add additional context in comments.

Comments

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.