2
A=[['2' '7' 'fas']
 ['4' '8' 'sda']
 ['1' '5' 'daf']
 ['2' '24' 'gag']]

How can I get just matrix A, instead last "atribute" in each row:

A=[['2' '7']
 ['4' '8']
 ['1' '5' ]
 ['2' '24']]

I know that last element in row is [:-1]

I tried with numpy:

A[:,  ?? ]

Matrix A is random elements, so I was thinking somethin in this way: A[:,end-1], but numpy don't know what is end

2 Answers 2

6
>>> arr=np.array([[1,2,3],[4,5,6],[7,8,9]])
>>> arr[:,:-1]
array([[1, 2],
       [4, 5],
       [7, 8]])
Sign up to request clarification or add additional context in comments.

Comments

1
>>> A = [ ['2', '7', 'fas']
        , ['4', '8', 'sda']
        , ['1', '5', 'daf']
        , ['2', '24', 'gag']
        ]

>>> [ x[:-1] for x in A ]
[['2', '7'], ['4', '8'], ['1', '5'], ['2', '24']]

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.