Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
last index
#1
Hi

In Python, starting indexes from 0 (it has been the choice of Guido Van Rossum from what I read some time ago, but it's confusing compare to Matlab or Julia for example) and it leads to some quirkinesses, but maybe I'm doing wrong and that's why more experienced people may give me/us a more relevant method.

Some practical examples and my understanding:
## array copy
B1 = np.copy(A[3:, :]);      # here all the lines fron the 3rd up the last one are taken into account
B2 = np.copy(A[3:-1, :]);    # as usually in python the last index is not included in the list

## now the goal is to delete the last column/row => "-1" is used
C = np.delete(A, -1, axis=1); # the last column is removed
D = np.delete(A, -1, axis=0); # ditto for the last row
Is there another (relevant) way to proceed?
(of course I did some searches on internet, but that's the only I've found so far)

Thanks for your feedback

Paul
Reply


Messages In This Thread
last index - by paul18fr - Jul-31-2019, 08:35 AM
RE: last index - by ichabod801 - Jul-31-2019, 01:13 PM
RE: last index - by paul18fr - Jul-31-2019, 01:27 PM
RE: last index - by perfringo - Jul-31-2019, 05:10 PM
RE: last index - by paul18fr - Jul-31-2019, 08:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Getting Index Error - list index out of range krishna 2 2,603 Jan-09-2021, 08:29 AM
Last Post: buran
  Getting Index Error - list index out of range RahulSingh 2 6,143 Feb-03-2020, 07:17 AM
Last Post: RahulSingh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020