0

In a data sequence as follows, I need to remove the last element of each sequence to create a new array:

x = np.array([[0.0023,0.0065, 0.0076,0.098,1], [0.0033,0.0063, 0.0072,0.088,1], [0.0013,0.0075, 0.0077,0.093,0], [0.0025,0.0065, 0.0079,0.099,0]])

The expected output:

0.0023 | 0.0065 | 0.0076 | 0.098
0.0033 | 0.0063 | 0.0072 | 0.088
0.0013 | 0.0075 | 0.0077 | 0.093
0.0025 | 0.0065 | 0.0079 | 0.099

Anyway, what I need is to remove the last column, but I can't. With the syntax below, I remove the last line. How should I slice the array to meet my needs?

x[0:3]
1
  • You need to slice on the second dimension. x[:,:3] Commented Nov 5, 2019 at 17:31

1 Answer 1

1

There you go, I wrote the code for you.

x[:, :-1]
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.