小编mat*_*ick的帖子

动态导入python中的子模块

假设我在命令行中提供了一个模块,并希望使用"imp"模块导入它:

$ foo.py mod.a.b.c
Run Code Online (Sandbox Code Playgroud)

这样做的正确方法是什么?

拆分"mod.abc"并添加每条路径?"imp"的行为似乎与"import"并行.

python import imp

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

如何在pandas HDStore(pyTables)中访问索引

我有一个带有多索引的大型HDFStore.如何获得其中一个索引级别?我看到我可以这样访问colindex:

 store._handle.root.data.table.colindexes
Run Code Online (Sandbox Code Playgroud)

但尚未获得其中一个列索引的列表.

python pytables pandas

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

如何结合和测试Google Dataproc --initialization-actions

调试很慢。不清楚是否接受多个参数。Docstring错误/非标准。

例如我们可以做:

--initialization-actions abc

当它失败时,如何在几秒钟内而不是几分钟内进行调试……即作为脚本未完成创建步骤?

google-cloud-dataproc

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

如何在内存中创建包含多个文件和子文件夹的 zip 存档?

以下命令运行,但导致文件解压失败:

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)

python zip python-zipfile

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

如何在 tensorflow 2.0 中禁用急切执行?

好像有问题。很多东西都行不通。另一方面,tensorflow 2.0 似乎解决了很多 tensorboard 交互问题,因此值得使用。如何关闭所有急切的东西。

python tensorflow2.0

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

在 tensorflow 2.0 中构建 RealNVP 层的更好方法?

是否有更好的方法来构建 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)

normalization keras tensorflow2.0

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