python - Python 需要帮助以获取项目 DUE TMRW 的列表,哈哈
问题描述
我的程序目前看起来像这样:
import random
answer = ""
correct_math = ["2", "3", "1"]
math_problems = ["What is the square root of 25? 1.) 4 2.) 5 3.) 6: ", "What is 97 + 113? 1.) 200 2.) 100 3.) 210: ", "What is 954 - 164? 1.) 790 2.) 835 3.) 756: "]
answer = input("STUDY GUIDE: What subject are you trying to study? Math (1) Science (2) History (3) : ")
if answer == "1":
answer = input(random.choice(math_problems))
我正在尝试使它调用一个随机问题来研究,但我不知道如何使它随机调用的问题等于答案列表中的答案。我将它们设置为 1:1,因此问题列表中的第一项在correctmath
列表中按顺序回答。如果有意义的话,我只需要知道如何调用与随机抽取的问题有关的正确答案。此外,我的代码并没有像那样隔开,只是不会让我添加新段落。
解决方案
以下是如何随机排序两个 numpy 数组并保持它们同时排序:
import numpy as np
data = np.array(["a","b","c","d"])
labels = np.array([1,2,3,4])
# create a numbered list of your indexes and shuffle it
ind = list(range(len(data)))
np.random.shuffle(ind)
data_rand = data[ind]
labels_rand = labels[ind]
我还做了一个快速的 Stackoverflow 搜索,这里还有一些其他方法:Better way to shuffle two numpy arrays in unison
推荐阅读
- javascript - React Native with Typescript - 可按下的按下属性
- groovy - 在 JMeter 中使用 JSR223 发送 TCP 请求数据
- next.js - NextAuth 用户密码实现如何工作?
- javascript - 如何在 NextJS 中添加动态 basePath
- cassandra - 是否有创建和填充 .cql 脚本形式的 Cassandra 演示数据库?
- python - Mypy 列表阴影
- c++ - c++ 读取套接字超时
- salesforce - 通过 Salesforce API 获取属于 Salesforce 中报表的所有潜在客户
- r - glmnet中的AIC比较
- postgresql - IPFS 哈希的最佳列类型是什么?