python-3.5

How to set Python3.5.2 as default Python version on CentOS?

帅比萌擦擦* 提交于 2019-12-17 07:24:15
问题 Is there a way to set the Python 3.5.2 as the default Python version on CentOS 7? currently, I have Python 2.7 installed as default and Python 3.5.2 installed separately. I used the following commands mv /usr/bin/python /usr/bin/python-old sudo ln -fs /usr/bin/python3 /usr/bin/python but after that yum gives the error. -bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory is there something I'm missing here? NOTE: its the similar but opposite question of Linux

Difference between numpy dot() and Python 3.5+ matrix multiplication @

感情迁移 提交于 2019-12-17 04:12:29
问题 I recently moved to Python 3.5 and noticed the new matrix multiplication operator (@) sometimes behaves differently from the numpy dot operator. In example, for 3d arrays: import numpy as np a = np.random.rand(8,13,13) b = np.random.rand(8,13,13) c = a @ b # Python 3.5+ d = np.dot(a, b) The @ operator returns an array of shape: c.shape (8, 13, 13) while the np.dot() function returns: d.shape (8, 13, 8, 13) How can I reproduce the same result with numpy dot? Are there any other significant

How to specify multiple return types using type-hints

为君一笑 提交于 2019-12-17 03:34:35
问题 I have a function in python that can either return a bool or a list . Is there a way to specify the return types using type hints. For example, Is this the correct way to do it? def foo(id) -> list or bool: ... 回答1: From the documentation class typing.Union Union type; Union[X, Y] means either X or Y. Hence the proper way to represent more than one return data type is from typing import Union def foo(client_id: str) -> Union[list,bool] But do note that typing is not enforced. Python continues

How to replace the ' \\ ' with ' \ ' in a bytes file?

可紊 提交于 2019-12-13 17:19:26
问题 Here is my problem: I have an encrypted bytes file like this: [w\x84\x7f@\xc6\xab\xc8 I want to decrypt it with PyCrypto, but I find a confused bug like the following: Code here: from Crypto.Cipher import DES key = 'jsfghutp' cipher = DES.new(key, DES.MODE_ECB) s = open('d:/Thu-Aug-2018.bin','rb').read() cipher.decrypt(s) If I run this, it will throw an error: ValueError Traceback (most recent call last) <ipython-input-3-4fcf0e8076ca> in <module>() ----> 1 cipher.decrypt(s) D:\Python\anaconda

How to find the number of hours between two dates excluding weekends and certain holidays in Python? BusinessHours package

三世轮回 提交于 2019-12-13 16:54:30
问题 I'm trying to find a very clean method to calculate the number of hours between two dates excluding weekends and certain holidays . What I found out is that the package BusinessHours (https://pypi.python.org/pypi/BusinessHours/1.01) can do this. However I did not find any instruction on how to use the package (the syntax actually) especially how to input the holidays. I found the original code of the package (https://github.com/dnel/BusinessHours/blob/master/BusinessHours.py) but still not so

Tensorflow not running on GPU in jupyter notebook

荒凉一梦 提交于 2019-12-13 15:17:24
问题 Installed Cuda and cudnn sucessfully for the GTX 1080 ti on Ubuntu, running a simple TF program in the jupyter notebook the speed does not increase in a conda environment running tensorflow-gpu==1.0 vs tensorflow==1.0. When I run nvidia-smi : +-----------------------------------------------------------------------------+ | NVIDIA-SMI 375.66 Driver Version: 375.66 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A |

How do I extract a value (I want an int not row) from a dataframe and do simple calculations on it? [closed]

只谈情不闲聊 提交于 2019-12-13 11:03:39
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I've got a dataframe lets call it "df" in apache spark with 3 colums and about 1000 rows. One of the colums "stores" a double in each row that either is 1.00 or 0.00 lets call it "column x" I need to get the amount of rows in "column x" that is 1.00 to use as a variable. I know at least 2 ways of doing it but I

Locate all similar “touching” elements in a 2D Array (Python) [closed]

北城以北 提交于 2019-12-13 10:00:44
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . Let's say I have the array: someArray = [["0","1","1","0"] ["0","1","0","1"] ["0","1","0","1"] ["0","1","1","0"]] I would like to point out one element in the array and then be able to identify every similar "touching" element (touching meaning if the array was viewed as a grid,

an error occured to add picture in python

拥有回忆 提交于 2019-12-13 09:46:12
问题 I am new in python and I am using python 3.5 version. I want to add photo to python, and here's the code I wrote: from tkinter import * win=Tk() win.title("Python Image") canvas=Canvas(win,width=500,height=500) canvas.pack() my_image=PhotoImage(file="C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg") canvas.create_image(0,0,anchor=NW,image=my_image) win.mainloop() But when I run it, the following error occurred: Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit

Pyusb on Windows 7 - NotImplemented Error :is_kernal_driver_active

放肆的年华 提交于 2019-12-13 09:14:34
问题 I am using escposprinter python library for printing my data in thermal printer. It depends on pyusb. the library is working fine in linux . While in windows 7 ,i get the it have some issues. Here are output i get. File "main.py", line 1, in <module> from app import app File "D:\freeth-in-erp-60ab8eb96fad\app\__init__.py", line 94, in <module> from .api_routes import * File "D:\freeth-in-erp-60ab8eb96fad\app\api_routes.py", line 44, in <module> from .printer import pos File "D:\freeth-in-erp