Skip to content

2D arrays with array module #11611

May 24, 2023 · 5 comments · 6 replies
Discussion options

You must be logged in to vote

if You mean: x[0] -> get row 0 , and x[0:1] -> get slice of row 0 from index 0 to 1 then in
getitem You need add isinstance(args[0], tuple) checking first, and then isinstance(args[0][1] , slice) and isinstance(args[0][1] , slice) for recognition what way you going to get values.

edit (something like that):

    def __getitem__(self, *args):
        if isinstance(args[0], tuple):  # ar[i,k]
            row, col = args[0][0], args[0][1]
            return self._buf[col + row * self._ncols]
        
        elif isinstance(args[0], slice):   # arr[i:k] # get row slice
     
            return  self._buf[args[0].start:args[0].stop]
       
        elif isinstance(args[0], int):  # arr[i]   …

Replies: 5 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@peterhinch
Comment options

@jimmo
Comment options

@jimmo
Comment options

Comment options

You must be logged in to vote
3 replies
@stinos
Comment options

@2dof
Comment options

Answer selected by peterhinch
@peterhinch
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants