小编Eud*_*die的帖子

如何在python中直接将文件添加到zip?

我是python的新手。在这里,我的目标是将数据放入zip文件中。以下是我编写的代码,其中我将数据写入unzipped_file,然后在zipped_file.zip中写入unzipped_file,然后删除未压缩的文件。

import os
import zipfile

##Some code above.............
for some_data in big_data:
    with open('unzipped_file', 'a+') as unzipped_f:
        unzipped_f.write(some_data)

##Some code in between...........

with zipfile.ZipFile('zipped_file.zip', 'w') as zipped_f:
    zipped_f.write("unzipped_file")

os.remove("unzipped_file")
Run Code Online (Sandbox Code Playgroud)

而不是创建一个中间的unzipped_file。我可以一步一步将数据直接写到zipped_file中吗?

python zip

4
推荐指数
2
解决办法
2032
查看次数

如何在张量流中的切片张量上使用tf.clip_by_value()?

我正在使用RNN根据最近24小时的湿度和温度值预测下一小时的湿度和温度。为了训练模型,我的输入和输出张量的形状为[24,2],如下所示:

[[23, 78],
 [24, 79],
 [25, 78],
 [23, 81],
  .......
 [27, 82],
 [21, 87],
 [28, 88],
 [23, 90]]
Run Code Online (Sandbox Code Playgroud)

在这里,我只想将“湿度”列(秒)的值限制在0到100之间,因为它不能超出该值。

我用于此目的的代码是

.....
outputs[:,1] = tf.clip_by_value(outputs[:,1], 0, 100)
.....
Run Code Online (Sandbox Code Playgroud)

并得到以下错误:

'Tensor' object does not support item assignment
Run Code Online (Sandbox Code Playgroud)

什么是将tf.clip_by_value()仅用于一列的正确方法?

python deep-learning tensorflow

2
推荐指数
1
解决办法
3843
查看次数

标签 统计

python ×2

deep-learning ×1

tensorflow ×1

zip ×1