0

I have this code where it supposed to reverse a list (decided to do it in complex way instead) and I was trying to print the transpose version of the reversed list but it seem to not work out

import numpy as np
  
    def func(n):
        dictionary = {
            0: 1 + 1,
            1: 0
        }
        l = []
        l.extend([n,n+1,dictionary[0] + 1])
        if(l == [1,2,3]):
            f = np.transpose(l)
            return f[::-1]
    
    func(1)

The output:

array([3,2,1])

What I was expecting for the output to be:

[3]
[2]
[1]
Henry Davis
  • 101
  • 1
  • 9
  • The result you're expecting isn't a single value. The reason that "transposing" a 1-dimensional input doesn't do anything, is because the point of transposition is to swap axes, and there isn't another axis to swap with. That said: please read https://stackoverflow.com/help/minimal-reproducible-example. We don't need to see the busy-work that creates the `l` value. All the code you need for this question is `print(np.transpose(np.array([1,2,3])))`. And the way you answer it is to read the documentation. – Karl Knechtel Dec 31 '21 at 06:25
  • @Karl Knechtel , Oh wow that so obvious silly me. Thanks! – Henry Davis Dec 31 '21 at 06:37

0 Answers0