我想用datatyp uint8添加numpy数组.我知道这些数组中的值可能足够大,可以发生溢出.所以我得到类似的东西:
a = np.array([100, 200, 250], dtype=np.uint8)
b = np.array([50, 50, 50], dtype=np.uint8)
a += b
Run Code Online (Sandbox Code Playgroud)
现在,是的[150 250 44].但是,我希望uint8的值太大而不是uint8允许的最大值,而不是溢出.所以我想要的结果就是[150 250 255].
我可以使用以下代码获得此结果:
a = np.array([100, 200, 250], dtype=np.uint8)
b = np.array([50, 50, 50], dtype=np.uint8)
c = np.zeros((1,3), dtype=np.uint16)
c += a
c += b
c[c>255] = 255
a = np.array(c, dtype=np.uint8)
Run Code Online (Sandbox Code Playgroud)
问题是,我的数组非常大,因此创建具有更大数据类型的第三个数组可能是内存问题.是否有一种快速且更有效的内存方式来实现所描述的结果?
python numpy image-processing integer-overflow numpy-ndarray
我正在使用setuptools来构建我的python项目的sphinx文档(python setup.py build_sphinx).
正如在本网站上找到的那样,我使用setup.cfg配置了构建过程:
[build_sphinx]
source-dir = docs/source
build-dir = docs/build
all_files = 1
Run Code Online (Sandbox Code Playgroud)
但是,我想补充一些选项.具体来说,我想将所有警告转换为错误,这可以使用sphinx-build带有选项的命令-W:
sphinx-build --help
Sphinx v1.1.3
Usage: /usr/bin/sphinx-build [options] sourcedir outdir [filenames...]
Options: -b <builder> -- builder to use; default is html
-a -- write all files; default is to only write new and changed files
-E -- don't use a saved environment, always read all files
-t <tag> -- include "only" blocks with <tag>
-d <path> -- path …Run Code Online (Sandbox Code Playgroud)