python-2.7

Python blurred image creation, to create a beautifully colored painting from black to white

扶醉桌前 提交于 2021-02-19 07:43:44
问题 on Pyhton I wanted to create a picture that goes from black to white, and I wrote the following code. But I think I'm doing a very small mistake, and that's the result. I actually wanted to create a similar image. Can you see where I made a mistake? import numpy as np from PIL import Image width = 100 height = 100 img = np.zeros((height, width), dtype=np.uint8) xx, yy=np.mgrid[:height, :width] circle = (xx - 50)**2 + (yy- 50)**2 for x in range (img.shape[0]): for y in range (img.shape[1]):

Python hex variable assignment

瘦欲@ 提交于 2021-02-19 06:58:45
问题 I'm using a variable to store data that gets sent by a socket. When I assign it in my program it works but when I read it from a file it is treated as a string. Example: data = '\x31\x32\x33' print data Outputs 123 # <--- this is the result I want when I read from a file to assign data f = open('datafile') <--- datafile contains \x31\x32\x33 on one line data = f.readline() print data Outputs \x31\x32\x33 # <--- wanted it to print 123, not \x31\x32\x33. 回答1: In Python the string '\x31\x32\x33'

Creating percentage stacked bar chart using groupby

六眼飞鱼酱① 提交于 2021-02-19 06:20:08
问题 I'm looking at home ownership within levels of different loan statuses, and I'd like to display this using a stacked bar chart in percentages. I've been able to create a frequency stacked bar chart using this code: df_trunc1=df[['loan_status','home_ownership','id']] sub_df1=df_trunc1.groupby(['loan_status','home_ownership'])['id'].count() sub_df1.unstack().plot(kind='bar',stacked=True,rot=1,figsize=(8,8),title="Home ownership across Loan Types") which gives me this picture:1 but I can't

Creating percentage stacked bar chart using groupby

大兔子大兔子 提交于 2021-02-19 06:20:06
问题 I'm looking at home ownership within levels of different loan statuses, and I'd like to display this using a stacked bar chart in percentages. I've been able to create a frequency stacked bar chart using this code: df_trunc1=df[['loan_status','home_ownership','id']] sub_df1=df_trunc1.groupby(['loan_status','home_ownership'])['id'].count() sub_df1.unstack().plot(kind='bar',stacked=True,rot=1,figsize=(8,8),title="Home ownership across Loan Types") which gives me this picture:1 but I can't

Python2: Using .decode with errors='replace' still returns errors

让人想犯罪 __ 提交于 2021-02-19 06:13:31
问题 So I have a message which is read from a file of unknown encoding. I want to send to a webpage for display. I've grappled a lot with UnicodeErrors and have gone through many Q&As on StackOverflow and think I have decent understand of how Unicode and encoding works. My current code looks like this try : return message.decode(encoding='utf-8') except: try: return message.decode(encoding='latin-1') except: try: print("Unable to entirely decode in latin or utf-8, will replace error characters

scipy optimise minimize — parallelisation options

自作多情 提交于 2021-02-19 05:49:05
问题 When running scipy optimize minimum using the L-BFGS-B method, I found that on certain computers, it uses all 8 cpu cores (see photo 1), on others it uses 4 out of 8 cores (see photo 2) and on others it only uses 1 core. I have not used any libraries/code to make it parallel -- it seems to be doing that by default. Is there a way that I can specify how many cores it should use easily? I couldn't find anything online that suggested scipy optimize uses parallelisation by default. fmin = scipy

C++: matplotlibcpp.h and Python.h linker error

≯℡__Kan透↙ 提交于 2021-02-19 05:30:12
问题 I am finding trouble linking a library in C++. I am trying for the first time to use "matplotlibcpp.h". This is a library that uses "Python.h" My code is not using either of the libraries yet. It gives error just by including "matplotlibcpp". I am using python2.7 and Ubuntu 18.04 and am using Eclipse. The code does not run if I include: #include "matplotlibcpp.h" // programme runs if this is commented out. But I need it to add new features. #include "Python.h" I have added these paths in

C++: matplotlibcpp.h and Python.h linker error

混江龙づ霸主 提交于 2021-02-19 05:28:59
问题 I am finding trouble linking a library in C++. I am trying for the first time to use "matplotlibcpp.h". This is a library that uses "Python.h" My code is not using either of the libraries yet. It gives error just by including "matplotlibcpp". I am using python2.7 and Ubuntu 18.04 and am using Eclipse. The code does not run if I include: #include "matplotlibcpp.h" // programme runs if this is commented out. But I need it to add new features. #include "Python.h" I have added these paths in

How to change the creation date of file using python on a mac?

南笙酒味 提交于 2021-02-19 05:02:21
问题 I need to update the creation time of a .mp4 file so that it will appear at the top of a list of media files sorted by creation date. I am able to easily update both the accessed and modified date of the file using os.utime, but have yet to find a good way to change the created date of a file to "now". My end goal is to seed media files to an iOS simulator using appium, and have those media files accessible in that script. The issue is that the video file will not be displayed in the

Python: xPath not available in ElementTree

孤人 提交于 2021-02-19 04:45:35
问题 I am trying to parse iTunes Playlist by using iterparse() of ElementTree but getting following error: AttributeError: 'Element' object has no attribute 'xpath' Code is given below: import xml.etree.ElementTree as ET context = ET.iterparse(file,events=("start", "end")) # turn it into an iterator context = iter(context) # get the root element event, root = context.next() for event, elem in context: z = elem.xpath(".//key") elem.clear() root.clear() print z What I am doing wrong? File is too big