python - 从单行输入创建坐标列表(x、y、z 变量)
问题描述
在这里我必须从单个输入行中提取坐标
输入有两部分:首先是点或坐标的数量,然后是每个坐标,用逗号分隔
输入:
2
1,2,3,4,5,6
预期输出:[[1,2,3],[4,5,6]]
到目前为止,这就是我想出的:
import numpy as np
def CreateList(string):
return list(int(i) for i in string.split(','))
num=input("enter number of cordinates")
string=input("enter the cordinates")
cordinates=CreateList(string)
CordinatesList = np.array(cordinates).reshape(num, 3)
print(CordinatesList)
这段代码给了我一个 numpy 实现的错误:
"CordinatesList = np.array(cordinates).reshape(num, 3)"
"TypeError: 'str' object cannot be interpreted as an integer"
repl 链接my_code
解决方案
推荐阅读
- php - 如何在 PHP 中显示本周的开始和结束日期?
- powershell - 是否可以使用 Invoke Webrequest 登录到使用 Azure AD B2C 身份验证的站点?
- c - 如何解决:传递“sutuntopla”的参数 1 使指针从整数变为没有强制转换警告?
- sql - 如何获取列的 n 个不同值的行
- python - 如何删除从网站上抓取的 \n 表单字符串
- javascript - JS中的计算器
- python - 其他两个命令之间的 Python 输入?
- python - 如何比较同一字符串中不同长度的部分?
- javascript - GET http://127.0.0.1:8000/dist/bundle.js net::ERR_ABORTED 404(未找到),尽管编译成功。(vuejs+django webapp)
- c - 你能帮我理解这个程序吗?