Reputation: 3635
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
Upvotes: 2
Views: 2204
Reputation: 115510
>>> 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']]
Upvotes: 1
Reputation: 229281
>>> arr=np.array([[1,2,3],[4,5,6],[7,8,9]])
>>> arr[:,:-1]
array([[1, 2],
[4, 5],
[7, 8]])
Upvotes: 6