0

Considering the following dataset:

>>> data[:10]
array([('T',  2,  8,  3, 5, 1,  8, 13, 0, 6,  6, 10,  8, 0,  8, 0,  8),
       ('I',  5, 12,  3, 7, 2, 10,  5, 5, 4, 13,  3,  9, 2,  8, 4, 10),
       ('D',  4, 11,  6, 8, 6, 10,  6, 2, 6, 10,  3,  7, 3,  7, 3,  9),
       ('N',  7, 11,  6, 6, 3,  5,  9, 4, 6,  4,  4, 10, 6, 10, 2,  8),
       ('G',  2,  1,  3, 1, 1,  8,  6, 6, 6,  6,  5,  9, 1,  7, 5, 10),
       ('S',  4, 11,  5, 8, 3,  8,  8, 6, 9,  5,  6,  6, 0,  8, 9,  7),
       ('B',  4,  2,  5, 4, 4,  8,  7, 6, 6,  7,  6,  6, 2,  8, 7, 10),
       ('A',  1,  1,  3, 2, 1,  8,  2, 2, 2,  8,  2,  8, 1,  6, 2,  7),
       ('J',  2,  2,  4, 4, 2, 10,  6, 2, 6, 12,  4,  8, 1,  6, 1,  7),
       ('M', 11, 15, 13, 9, 7, 13,  2, 6, 2, 12,  1,  9, 8,  1, 1,  8)], 
      dtype=[('f0', 'S1'), ('f1', '<i8'), ('f2', '<i8'), ('f3', '<i8'), ('f4', '<i8'), ('f5', '<i8'), ('f6', '<i8'), ('f7', '<i8'), ('f8', '<i8'), ('f9', '<i8'), ('f10', '<i8'), ('f11', '<i8'), ('f12', '<i8'), ('f13', '<i8'), ('f14', '<i8'), ('f15', '<i8'), ('f16', '<i8')])

How one can access all elements except the first one from each array. I am using the following code but to no avail.

>>> nd.array([[x[1:] for x in data[:10]])

Any help is really appreciated.

2
  • This seems to pretty much be a duplicate of stackoverflow.com/questions/46388186/…. Please edit your original question instead of creating a new one. Commented Sep 24, 2017 at 11:11
  • @glennsl, the other question asked about accessing one field, this is about accessing all but that one. Same data, but different task, Commented Sep 24, 2017 at 16:57

1 Answer 1

1

You can access all column names with the dtype.names attribute and then slice it:

>>> data[list(data.dtype.names[1:])]
array([( 2,  8,  3, 5, 1,  8, 13, 0, 6,  6, 10,  8, 0,  8, 0,  8),
       ( 5, 12,  3, 7, 2, 10,  5, 5, 4, 13,  3,  9, 2,  8, 4, 10),
       ( 4, 11,  6, 8, 6, 10,  6, 2, 6, 10,  3,  7, 3,  7, 3,  9),
       ( 7, 11,  6, 6, 3,  5,  9, 4, 6,  4,  4, 10, 6, 10, 2,  8),
       ( 2,  1,  3, 1, 1,  8,  6, 6, 6,  6,  5,  9, 1,  7, 5, 10),
       ( 4, 11,  5, 8, 3,  8,  8, 6, 9,  5,  6,  6, 0,  8, 9,  7),
       ( 4,  2,  5, 4, 4,  8,  7, 6, 6,  7,  6,  6, 2,  8, 7, 10),
       ( 1,  1,  3, 2, 1,  8,  2, 2, 2,  8,  2,  8, 1,  6, 2,  7),
       ( 2,  2,  4, 4, 2, 10,  6, 2, 6, 12,  4,  8, 1,  6, 1,  7),
       (11, 15, 13, 9, 7, 13,  2, 6, 2, 12,  1,  9, 8,  1, 1,  8)],
      dtype=[('f1', '<i8'), ('f2', '<i8'), ('f3', '<i8'), ('f4', '<i8'), 
             ('f5', '<i8'), ('f6', '<i8'), ('f7', '<i8'), ('f8', '<i8'),
             ('f9', '<i8'), ('f10', '<i8'), ('f11', '<i8'), ('f12', '<i8'), 
             ('f13', '<i8'), ('f14', '<i8'), ('f15', '<i8'), ('f16', '<i8')])
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.