Sergio
Sergio

Reputation: 63

Transform matrix efficiently

I have this matrix:

matrix = [[3,2,3],
         [-6,7-9],
         [-6,5,-12]]

How can I create an array of the same size but with zeros using Python in the most efficient and short way without using numpy?

Upvotes: 0

Views: 32

Answers (1)

ThisIsAQuestion
ThisIsAQuestion

Reputation: 1967

An easy one-liner:

zeros = [[0]*len(matrix[0]) for _ in range(len(matrix))]

Upvotes: 1

Related Questions