python-3.5

Python 3.5 vs. 3.6 what made “map” slower compared to comprehensions

匆匆过客 提交于 2019-11-29 02:56:13
问题 I sometimes used map if there was a function/method that was written in C to get a bit extra performance. However I recently revisited some of my benchmarks and noticed that the relative performance (compared to a similar list comprehension) drastically changed between Python 3.5 and 3.6. That's not the actual code but just a minimal sample that illustrates the difference: import random lst = [random.randint(0, 10) for _ in range(100000)] assert list(map((5).__lt__, lst)) == [5 < i for i in

How to annotate types of multiple return values?

若如初见. 提交于 2019-11-28 20:06:52
How do I use type hints to annotate a function that returns an Iterable that always yields two values: a bool and a str ? The hint Tuple[bool, str] is close, except that it limits the return value type to a tuple, not a generator or other type of iterable. I'm mostly curious because I would like to annotate a function foo() that is used to return multiple values like this: always_a_bool, always_a_str = foo() Usually functions like foo() do something like return a, b (which returns a tuple), but I would like the type hint to be flexible enough to replace the returned tuple with a generator or

sift = cv2.xfeatures2d.SIFT_create() not working even though have contrib installed

痴心易碎 提交于 2019-11-28 18:45:33
So I am trying to use: sift = cv2.xfeatures2d.SIFT_create() and it is coming up with this error: cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'cv::xfeatures2d::SIFT::create' I am using Python 3.5.0 and opencv(3.4.3) and I am just using idle. This occured after I tried to install TensorFlow and I have tried looking around and have installed

Why is str.translate much faster in Python 3.5 compared to Python 3.4?

二次信任 提交于 2019-11-28 18:30:15
I was trying to remove unwanted characters from a given string using text.translate() in Python 3.4. The minimal code is: import sys s = 'abcde12345@#@$#%$' mapper = dict.fromkeys(i for i in range(sys.maxunicode) if chr(i) in '@#$') print(s.translate(mapper)) It works as expected. However the same program when executed in Python 3.4 and Python 3.5 gives a large difference. The code to calculate timings is python3 -m timeit -s "import sys;s = 'abcde12345@#@$#%$'*1000 ; mapper = dict.fromkeys(i for i in range(sys.maxunicode) if chr(i) in '@#$'); " "s.translate(mapper)" The Python 3.4 program

Why does pip freeze list “pkg-resources==0.0.0”?

一世执手 提交于 2019-11-28 17:50:01
On Ubuntu 16.04 with virtualenv 15.0.1 and Python 3.5.2 (both installed with apt ) when I create and activate new Python virtual environment with virtualenv .virtualenvs/wtf -p $(which python3) --no-site-packages source .virtualenvs/wtf/bin/activate I get the following output: Already using interpreter /usr/bin/python3 Using base prefix '/usr' New python executable in /home/das-g/.virtualenvs/wtf/bin/python3 Also creating executable in /home/das-g/.virtualenvs/wtf/bin/python Installing setuptools, pkg_resources, pip, wheel...done. Indeed pip freeze --all lists these 4 packages: pip==8.1.2 pkg

Why can't I use a starred expression?

为君一笑 提交于 2019-11-28 17:30:56
问题 My code $ python Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:53:06) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> a = (1, 2) >>> '%d %d %d' % (0, *a) '0 1 2' >>> '%d %d %d' % (*a, 3) '1 2 3' >>> '%d %d' % (*a) File "<stdin>", line 1 SyntaxError: can't use starred expression here >>> My question, why? In a more serious tone: I'd like an answer, or a reference, that details all the ins and outs of

TensorFlow on Windows: “pip install tensorflow” fails

Deadly 提交于 2019-11-28 14:49:19
I am using Visual Studio 2015, Python 3.5.2, Windows 10, and have recently upgraded pip to 9.0.1. I am trying to install Tensorflow 0.12 on my system. I tried to use VS's built in "Install Python Package" function, as well as command prompting pip install python Both ways I get the same error: Installing 'tensorflow' Collecting tensorflow Could not find a version that satisfies the requirement tensorflow (from versions: ) No matching distribution found for tensorflow 'tensorflow' failed to install. Exit code: 1` I don't know what to do from here. Supposedly the pip command was all I had to do

Tensorflow install on Windows Error

筅森魡賤 提交于 2019-11-28 14:16:56
Tensorflow is now available on Windows: https://developers.googleblog.com/2016/11/tensorflow-0-12-adds-support-for-windows.html I used pip install tensorflow. I try running the intro code: https://www.tensorflow.org/versions/r0.12/get_started/index.html I get this error: C:\Python\Python35-32\python.exe "C:/tensorflow_tutorial.py" Traceback (most recent call last): File "C:\Python\Python35-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper return importlib.import_module(mname) File "C:\Python\Python35-32\lib\importlib\__init__.py", line 126, in import

PermissionError While Installing TensorFlow Using Virtualenv

瘦欲@ 提交于 2019-11-28 11:08:34
问题 I was installing tensorflow using virtualenv. The following commands worked fine. $ virtualenv ~/.tensorflow/bin/activate $ pip install --upgrade tensorflow But if I try: $ virtualenv ~/.tensorflow/bin/activate $ pip3 install tensorflow I got PermissionError: I tried the last command with sudo. $ sudo pip3 install tensorflow Then it seems like I can import tensorflow outside virtualenv. (Is it correct?) How can I install tensorflow for python 3 only inside virtualenv? By the way, I am using

How to update chrome driver for windows 10

ⅰ亾dé卋堺 提交于 2019-11-28 09:25:37
问题 Hello I am looking to update my chrome driver to the latest version but ant find any information on updating the driver just info on installing it. What do I need to do to update the driver to the latest version? 回答1: chromedriver is a single self-contained executable file. Just replace your existing version with a newer one. download the latest version of chromedriver_win32.zip from https://sites.google.com/a/chromium.org/chromedriver/downloads unzip the file to extract chromedriver.exe