DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 963,673 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
SalahElhossiny
SalahElhossiny

Posted on

How to get matrix columns without numpy in Python


mat = [
        [1, 2,3, 5], 
        [4, 6, 7, 8], 
        [9, 10, 11, 12], 
        [13, 14, 15, 16]
    ]


def convertToArr(el):
    return list(el)

cols = list(map(convertToArr, list(zip(*mat))))

print(cols)  # [[1, 4, 9, 13], [2, 6, 10, 14], [3, 7, 11, 15], [5, 8, 12, 16]]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

DEV has this feature:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. 🛠