如何使用理解力将字符串矩阵转换为整数矩阵 [英] How to convert a matrix of strings into a matrix of integers using comprehensions
本文介绍了如何使用理解力将字符串矩阵转换为整数矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个矩阵[['1','2'],['3','4']],我想将其转换为整数矩阵.有没有办法使用理解力?
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?
推荐答案
一般情况下:
int_matrix = [[int(column) for column in row] for row in matrix]
这篇关于如何使用理解力将字符串矩阵转换为整数矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文