小编Fil*_*lip的帖子

计算2 ^ n的理论时间与实际时间复杂度

我正在尝试计算时间复杂度,并将其与实际计算时间进行比较。

如果我没记错的话,时间复杂度是O(log(n)),但是从实际的计算时间来看,它看起来更像O(n)甚至O(nlog(n))。

造成这种差异的原因可能是什么?

def pow(n):
    """Return 2**n, where n is a nonnegative integer."""
    if n == 0:
        return 1
    x = pow(n//2)
    if n%2 == 0:
        return x*x
    return 2*x*x
Run Code Online (Sandbox Code Playgroud)

理论时间复杂度

在此处输入图片说明

实际运行时间

在此处输入图片说明

python time-complexity pow

12
推荐指数
2
解决办法
316
查看次数

ubuntu、python、ssl.SSLError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:852)

我正在运行一些示例代码来测试 Tensorflow 的安装是否可以在 GPU 上运行。Python 工作正常,我可以导入 Tensorflow 而不会出现任何错误。

但是,当我尝试从 TensorFlow 网站加载数据集时,遇到了问题并收到以下错误消息。

该问题与某些 SSL 证书有关,我对此知之甚少,因此我正在寻求帮助。

(相关) 代码

import tensorflow as tf
(x_train, y_train),(x_test, y_test) = tf.keras.datasets.mnist.load_data()
Run Code Online (Sandbox Code Playgroud)

错误消息

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)>

...

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)>

...

Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz: None -- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)
Run Code Online (Sandbox Code Playgroud)

完整回溯

Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz
Traceback (most recent call last):
  File "/home/filip/anaconda3/envs/tf/lib/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding')) …
Run Code Online (Sandbox Code Playgroud)

urllib ssl-certificate python-3.x tensorflow ubuntu-18.04

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