How to convert a matrix of strings into a matrix of integers using comprehensions

后端 未结 4 682
甜味超标
甜味超标 2021-01-29 03:42

I have a matrix [[\'1\', \'2\'], [\'3\', \'4\']] which I want to convert to a matrix of integers. Is there is a way to do it using comprehensions?

4条回答
  •  悲&欢浪女
    2021-01-29 04:14

    In the general case:

    int_matrix = [[int(column) for column in row] for row in matrix]
    

提交回复
热议问题