Costa.Gustavo
Costa.Gustavo

Reputation: 849

Slice numpy arrays

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]

Upvotes: 0

Views: 38

Answers (1)

Nicolas Gervais
Nicolas Gervais

Reputation: 36584

There you go, I wrote the code for you.

x[:, :-1]

Upvotes: 1

Related Questions