0

I've try delete numpy ndarray's 1st column (eg. A, B, C ... A, B ) through

x = np.delete(x, 0, axis=1) 

or

x = np.delete(x, 0, axis=0)  

However, it's not work.

ndarray shape = ( 30000, 120, 15) 

[[['A' 0.0 0.0 ..., 0.0 0.0 'Y']
  ['B' 0.0 0.0 ..., 0.0 0.0 'Y']
  ['C' 0.0 0.0 ..., 0.0 0.0 'N']
   ..., 
  ['A' 0.0 0.0 ..., 0.0 0.0 'Y']
  ['B' 41.0 0.0 ..., 0.0 0.0 'N']]]  

How do I resolve this... Thank you.

1
  • Note that you can access the data as : x[:,:,1:] to have column 1 to end from you array. Commented Jun 1, 2017 at 2:32

1 Answer 1

3

The column is the 3rd dimension of the array, you need axis = 2:

import numpy as np
x = np.array([[['A', 1, 2],
              ['B', 2, 3]],
             [['A', 1, 2],
              ['B', 2, 3]]])

x.shape
#(2, 2, 3)

np.delete(x, 0, axis=2)
#array([[['1', '2'],
#        ['2', '3']],
# 
#       [['1', '2'],
#        ['2', '3']]], 
#      dtype='<U1')

Or you can use the slicing index:

x[...,1:]

#array([[['1', '2'],
#        ['2', '3']],
# 
#        [['1', '2'],
#         ['2', '3']]], 
#       dtype='<U1')
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you sooooooooooooo much!

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.