![]() |
Removing rows from array - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Removing rows from array (/thread-29731.html) |
Removing rows from array - claw91 - Sep-17-2020 Hello, I want to replicate this Matlab code into Python FILE(1:985,:) = [ ]; FILE is an nx2 array. n si quite large but it's not important. If I understand correctly, the code should remove from the FILE array all rows from first to 985th. This is what I've come up with in Python FILE = np.delete(FILE, FILE[0:985,...].astype('int'), axis = 0)However it doesn't seem to work as I want, it removes only 19 rows from the array. Why is that? Here you can find the FILE array: https://pastebin.com/ it's a 40.001 x 2 The resulting FILE at the end should be 39.016 x 2 but I get 39.982 x 2 RE: Removing rows from array - scidam - Sep-17-2020 If you want to drop first 985 rows, just do: FILE = FILE[985:, ...]If you want to drop first 985 rows and convert the array to integer type do: FILE = FILE[985:, ...].astype(int) # maybe astype(np.int64), astype(np.int16) choose appropriate one.If you still want to use delete, you can do the same as follows: FILE = np.delete(FILE, range(985), axis=0)Note, that the second argument is an array of row numbers to delete. Finally, it is not pep8-compliant to use capitalized letters for variable names. RE: Removing rows from array - claw91 - Sep-18-2020 Thank you. Can you please explain why my second argument FILE[0:985,...]is not the same as yours range(985)? RE: Removing rows from array - scidam - Sep-18-2020 (Sep-18-2020, 01:50 PM)claw91 Wrote: Can you please explain why my second argument You passed FILE[0:985,...].astype('int') , that are values of the first column converted to ints, but you need to pass row numbers which you want to be deleted, range(985) stands (approx.) for [0, 1, ..., 984] - these are row numbers.
|