假设我在命令行中提供了一个模块,并希望使用"imp"模块导入它:
$ foo.py mod.a.b.c
Run Code Online (Sandbox Code Playgroud)
这样做的正确方法是什么?
拆分"mod.abc"并添加每条路径?"imp"的行为似乎与"import"并行.
我有一个带有多索引的大型HDFStore.如何获得其中一个索引级别?我看到我可以这样访问colindex:
store._handle.root.data.table.colindexes
Run Code Online (Sandbox Code Playgroud)
但尚未获得其中一个列索引的列表.
调试很慢。不清楚是否接受多个参数。Docstring错误/非标准。
例如我们可以做:
--initialization-actions abc
当它失败时,如何在几秒钟内而不是几分钟内进行调试……即作为脚本未完成创建步骤?
以下命令运行,但导致文件解压失败:
import io
import zipfile
b = io.BytesIO()
zf = zipfile.ZipFile(b, mode='w')
zf.writestr('a/b.txt', 'look here')
zf.writestr('a/c.txt', 'look there')
open('here.zip', 'wb').write(b.getbuffer())
Run Code Online (Sandbox Code Playgroud)
然后测试:
$ unzip here.zip
Archive: here.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of here.zip or
here.zip.zip, and cannot find …Run Code Online (Sandbox Code Playgroud) 好像有问题。很多东西都行不通。另一方面,tensorflow 2.0 似乎解决了很多 tensorboard 交互问题,因此值得使用。如何关闭所有急切的东西。
是否有更好的方法来构建 RealNVP 层以用作 tensorflow 2.0 中的标准可训练层?我最终将它包装在一个模型中。对于图层,变量没有出现在 trainable_variables 中。
像这样运行,但我怀疑有更好的方法:
from pylab import *
import numpy as np
import pandas as pd
import tensorflow as tf
import tensorflow_probability as tfp
tfb = tfp.bijectors
tfd = tfp.distributions
# class NVPLayer(tf.keras.layers.Layer):
class NVPLayer(tf.keras.models.Model):
def __init__(self, *, output_dim, num_masked, **kwargs):
super().__init__(**kwargs)
self.output_dim = output_dim
self.num_masked = num_masked
self.shift_and_log_scale_fn = tfb.real_nvp_default_template(
hidden_layers=[2],
activation=None, # linear
)
self.loss = None
def call(self, *inputs):
nvp = tfd.TransformedDistribution(
distribution=tfd.MultivariateNormalDiag(loc=[0., 0., 0.]),
bijector=tfb.RealNVP(
num_masked=self.num_masked,
shift_and_log_scale_fn=self.shift_and_log_scale_fn)
)
self.loss = tf.reduce_mean(nvp.log_prob(*inputs)) …Run Code Online (Sandbox Code Playgroud)