Q:

How to delete a column in Numpy array

my array look like this (9 columns)
[('2012-07', 'abc', 'EXECUTIVE', '149', '16 TO 18', 150., 1995,'apt', 1000000)
 ('2012-10', 'abc', 'EXECUTIVE', '194', '22 TO 24', 163., 1987, 'ma',  1010000)
  ('2014-12', 'abc', 'EXECUTIVE', '190', '19 TO 21', 150., 1987, 'ma', 1000000)] 

print(a.shape)
output >> (3,)
print(len(a))
output >> 3

I want to delete the last 2nd column, so it will look like this
[('2012-07', 'abc', 'EXECUTIVE', '149', '16 TO 18', 150., 1995, 1000000)
 ('2012-10', 'abc', 'EXECUTIVE', '194', '22 TO 24', 163., 1987, 1010000)
  ('2014-12', 'abc', 'EXECUTIVE', '190', '19 TO 21', 150., 1987, 1000000)] 

I tried the np.delete function:
b = np.delete(a,7,axis=1)

Error >> AxisError: axis 1 is out of bounds for array of dimension 1

My array has multiple rows with 9 columns, just want to delete one column.
Any help would be very much appreciated.
Thanks!

A:

a.shape : (3,), it means there's only 3 element on axis 0, no axis 1. Should check how your matrix data assigned to a.
import numpy as np

a = [('2012-07', 'abc', 'EXECUTIVE', '149', '16 TO 18', 150., 1995, 'apt', 1000000),
     ('2012-10', 'abc', 'EXECUTIVE', '194', '22 TO 24', 163., 1987, 'ma',  1010000),
     ('2014-12', 'abc', 'EXECUTIVE', '190', '19 TO 21', 150., 1987, 'ma',  1000000)]

b = np.array(a)

c = np.delete(b,7,axis=1)

A:

The first thing to note is that you have a structured Numpy array.
It must be created with dtype parameter, otherwise all field types are U...
(Unicode strings of certain size).
I created such an array running:
a = np.array([
    ('2012-07', 'abc', 'EXECUTIVE', '149', '16 TO 18', 150., 1995, 'apt', 1000000),
    ('2012-10', 'abc', 'EXECUTIVE', '194', '22 TO 24', 163., 1987, 'ma',  1010000),
    ('2014-12', 'abc', 'EXECUTIVE', '190', '19 TO 21', 150., 1987, 'ma',  1000000)],
    dtype='U7, U3, U10, i4, U10, f4, i4, U4, i4')

Note that even if you didn't pass field names (only types like above), Numpy
still assigns default filed names, as f0, f1 and so on.
To print field names you can run e.g. a.dtype.names. In the above case I got:
('f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8')

so probably your task is to delete f7 field (check in your environment).
Maybe you have some field names explicitely assigned by your code, so use
the last but one name instead.
To get a copy of a Numpy array with this column dropped, you can run:
import numpy.lib.recfunctions as rcf
b = rcf.drop_fields(a, 'f7')

or save it back under a if you wish.
A remark concerning the solution proposed by Jason Yang:
If you run b.shape you will get (3, 9), whereas your sample contains
(3,) and the array which I created has just this shape.
So your array must have been created some other way than in his solution. 

