python - 用户提供 MXN 矩阵,我想转换为 numpy 矩阵
问题描述
输入
2 3 **Here 2,3 are size of mateix m,n**
2 3 4
5 6 7
输出
[
[2 3 4]
[5 6 7]
]
注意:-使用 Numpy 包
解决方案
将mxn输入读取为 numpy 矩阵:
import numpy as np
m,n = map(int, input().split())
arr = np.zeros((m,n))
for i in range(m):
arr[i] = np.array(list(map(int, input().split())))
输出 :
array([[1., 2., 3.],
[4., 5., 6.]])
推荐阅读
- amazon-web-services - Terraform - 使用地图时“此处不需要命名的参数”
- reactjs - mime.lookUp 不是我的 React 打字稿项目中的一个函数
- html - 如何从网站点亮手机闪光灯
- kubernetes-helm - 在预安装挂钩中为机密创建文件
- python - 从值中获取键(值在列表中)
- python - 在 read_csv() 之后在数据框中打印列时出现关键错误
- python - 多维数组/准图像的连通分量标记
- javafx - Javafx 中的透明度与混合效果
- assembly - 在长模式下使用 IRET 进入 CPL=3
- selenium - 迭代并打开新的浏览器页面会导致 StaleElementReferenceException