h5 数据制作与读取

数据集制作
data,list均是numpy形式,
一般是list形式,使用np.array转换。
制作:

with h5py.File(savepath, 'w') as hf:
     hf.create_dataset(name , value)
with h5py.File(savepath, 'r') as hf:
     hf.get(name)
def make_data(sess, data, label):
  """
  Make input data as h5 file format
  Depending on 'is_train' (flag value), savepath would be changed.
  """

  if FLAGS.is_train:
    savepath = os.path.join(os.getcwd(), 'checkpoint/train.h5')
  else:
    savepath = os.path.join(os.getcwd(), 'checkpoint/test.h5')


  with h5py.File(savepath, 'w') as hf:
    hf.create_dataset('data', data=data)
    hf.create_dataset('label', data=label)

数据集读取

def read_data(path):
  """
  Read h5 format data file
  Args:
    path: file path of desired file
    data: '.h5' file format that contains train data values
    label: '.h5' file format that contains train label values
  """
  with h5py.File(path, 'r') as hf:
    data = np.array(hf.get('data'))
    label = np.array(hf.get('label'))
    return data, label
  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
H5答题游戏的制作需要涉及到前端和后端两个方面的知识,包括HTML、CSS、JavaScript、PHP等技术。以下是一个简单的教程,希望对您有帮助。 1. 界面设计 首先,需要设计答题界面。可以使用HTML和CSS来实现。可以在网上搜索一些答题游戏的界面,参考其设计。在设计时需要考虑到题目、选项、计时器、得分等元素的排版。 2. 题目数据 答题游戏需要题目数据,可以将数据存储在一个JSON文件中,或者存储在数据库中。每个题目包括题目内容和选项。可以在JSON文件中定义一个数组,每个元素是一个包含题目和选项的对象。 3. 前端逻辑 在前端逻辑中,需要使用JavaScript来实现计时器、得分计算、题目切换等功能。可以使用jQuery等库来简化代码。可以使用AJAX技术从服务器获取题目数据。 4. 后端逻辑 在后端逻辑中,需要使用PHP等语言来处理答题结果。可以将答题结果存储在数据库中,或者发送邮件给管理员。 以下是一个简单的示例源码,仅供参考: HTML代码: ``` <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>答题游戏</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <div class="question"> <h2 id="question"></h2> </div> <div class="options"> <ul> <li><button id="option1"></button></li> <li><button id="option2"></button></li> <li><button id="option3"></button></li> <li><button id="option4"></button></li> </ul> </div> <div class="score"> <p>得分:<span id="score">0</span></p> </div> <div class="timer"> <p>剩余时间:<span id="timer">30</span>秒</p> </div> <button id="start">开始游戏</button> </div> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="app.js"></script> </body> </html> ``` CSS代码: ``` body { margin: 0; padding: 0; font-family: Arial, sans-serif; } .container { max-width: 800px; margin: 0 auto; text-align: center; } .question { margin-bottom: 20px; } .options { margin-bottom: 20px; } .options ul { margin: 0; padding: 0; list-style: none; } .options li { display: inline-block; margin: 0 10px; } .options button { padding: 10px 20px; font-size: 16px; background-color: #ccc; border: none; border-radius: 5px; } .score { margin-bottom: 20px; } .timer { margin-bottom: 20px; } .timer span { font-weight: bold; } #start { padding: 10px 20px; font-size: 16px; background-color: #ccc; border: none; border-radius: 5px; } ``` JavaScript代码: ``` $(function() { var questions = []; // 题目数据 var currentQuestion = 0; // 当前题目 var score = 0; // 得分 var timer = 30; // 计时器 // 从服务器获取题目数据 $.get('questions.json', function(data) { questions = data; }); // 点击开始游戏按钮 $('#start').click(function() { $(this).hide(); showQuestion(); startTimer(); }); // 点击选项按钮 $('.options button').click(function() { var answer = $(this).text(); var correctAnswer = questions[currentQuestion].answer; if (answer == correctAnswer) { score++; $('#score').text(score); } nextQuestion(); }); // 显示当前题目 function showQuestion() { var question = questions[currentQuestion]; $('#question').text(question.question); $('#option1').text(question.option1); $('#option2').text(question.option2); $('#option3').text(question.option3); $('#option4').text(question.option4); } // 显示下一题 function nextQuestion() { if (currentQuestion < questions.length - 1) { currentQuestion++; showQuestion(); } else { endGame(); } } // 开始计时器 function startTimer() { setInterval(function() { timer--; $('#timer').text(timer); if (timer == 0) { endGame(); } }, 1000); } // 结束游戏 function endGame() { $('.question').hide(); $('.options').hide(); $('.timer').hide(); $('.score').text('你的得分是:' + score); } }); ``` 其中,questions.json文件中存储了题目数据,格式如下: ``` [ { "question": "1 + 1 = ?", "option1": "1", "option2": "2", "option3": "3", "option4": "4", "answer": "2" }, { "question": "2 + 2 = ?", "option1": "2", "option2": "3", "option3": "4", "option4": "5", "answer": "4" }, ... ] ``` 这只是一个简单的示例,实际的答题游戏需要根据自己的需求进行设计和开发。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值