python-3.x

Hue Tint Color error converting tiff to jpg in python3 with pillow

冷暖自知 提交于 2021-02-11 12:36:38
问题 While saving jpg thumbnails from tiff (CMYK) file I'm encountering the following problem: Thumbnail created with color mode conversion from CMYK to RGB gets blue hue: Thumbnail created from the same tiff in photoshop (no ICC profile, not converted to sRGB, RGB only) get the colors the right way: Thumbnails created without color mode conversion (jpeg with CMYK) gets similar results to the photoshopped ones but are not usable for the web (still blue). Code snippet: img = Image.open(img_tiff)

How to do a partial conditioning on a tag for find_all() in bs4?

淺唱寂寞╮ 提交于 2021-02-11 12:35:12
问题 I have an xml which has multiple tags which look like this: <textblock height="55" hpos="143" id="Page1_Block5" lang="en-US" stylerefs="StyleId-E6BF91A3-3D6A-442F-9A46-22A0459A02E9- font1" vpos="226" width="393"> I want to get all the <textblock> tags clustered by a Page ( id property in the textblock tag). However, my id is written in the following way: id="Page1_Block5" . However, I want to condition only on the Page number, and not the block number. (I want all blocks of a specific page).

plot doesn't update on button click but does when window resized

穿精又带淫゛_ 提交于 2021-02-11 12:35:08
问题 What's going on: Program in python3/qt5/matplotlib. I am plotting three subplots and few plots in each. I wanted to update plots if user changes any data. That proved rather complicated hence the button 'Replot'. It calls a function that clears canvas and ... reloads the entire widget. It doesn't work as expected: when I press the button nothing happens, but when window gets resized after button clicked it does update the plot. What would be a correct way to do it without having to put all

How to center the nonzero values within 2D numpy array?

此生再无相见时 提交于 2021-02-11 12:35:04
问题 I'd like to locate all the nonzero values within a 2D numpy array and move them so that the image is centered. I do not want to pad the array because I need to keep it the same shape. For example: my_array = np.array([[1, 1, 0, 0], [0, 0, 2, 4], [0, 0, 0, 0], [0, 0, 0, 0]]) # center... >>> [[0 0 0 0] [0 1 1 0] [0 2 4 0] [0 0 0 0]] But in reality the arrays I need to center are much larger (like 200x200, 403x403, etc, and they are all square). I think np.nonzero and np.roll might come in handy

How to center the nonzero values within 2D numpy array?

六月ゝ 毕业季﹏ 提交于 2021-02-11 12:34:11
问题 I'd like to locate all the nonzero values within a 2D numpy array and move them so that the image is centered. I do not want to pad the array because I need to keep it the same shape. For example: my_array = np.array([[1, 1, 0, 0], [0, 0, 2, 4], [0, 0, 0, 0], [0, 0, 0, 0]]) # center... >>> [[0 0 0 0] [0 1 1 0] [0 2 4 0] [0 0 0 0]] But in reality the arrays I need to center are much larger (like 200x200, 403x403, etc, and they are all square). I think np.nonzero and np.roll might come in handy

plot doesn't update on button click but does when window resized

纵饮孤独 提交于 2021-02-11 12:34:09
问题 What's going on: Program in python3/qt5/matplotlib. I am plotting three subplots and few plots in each. I wanted to update plots if user changes any data. That proved rather complicated hence the button 'Replot'. It calls a function that clears canvas and ... reloads the entire widget. It doesn't work as expected: when I press the button nothing happens, but when window gets resized after button clicked it does update the plot. What would be a correct way to do it without having to put all

Clicking a button to create a new button using PyQt5 python [duplicate]

这一生的挚爱 提交于 2021-02-11 12:33:54
问题 This question already has answers here : QLabel does not display in QWidget (2 answers) Closed 1 year ago . I'm trying to create a window(UI) that have a button click action implemented using python and PyQt5 . But, i want my button to create a new button when i clicked it. (i.e: clicking a button to create a new button). Can some one notify me on how to do that? my sample code is as follows: from PyQt5.QtWidgets import QApplication, QWidget, QPushButton from PyQt5.QtGui import QIcon from

Python code is not throwing error but the desired output is not the same

删除回忆录丶 提交于 2021-02-11 12:33:50
问题 Unable to receive the output of the python code.I have tried debugging the code by printing each line def get_sum_metrics(predictions, metrics=[]): for i in range(0,3): metrics.append(lambda x:x+i) sum_metrics = 0 for metric in metrics: sum_metrics += metric(predictions) return sum_metrics def main(): print(get_sum_metrics(0)) print(get_sum_metrics(1)) print(get_sum_metrics(2)) print(get_sum_metrics(3,[lambda x:x])) print(get_sum_metrics(0)) print(get_sum_metrics(1)) print(get_sum_metrics(2))

Extract zip file and keeping top folder using python

那年仲夏 提交于 2021-02-11 12:32:29
问题 I have folder in like CW1234.zip and it has various folders and subfolders like below. So, CW1234.zip has CW_All folder which in turn has CW123 and CW234 folders and so on CW1234.zip CW_All CW123 xyz.pdf CW234 abc.doc and to extract I use this code: from zipfile import ZipFile with ZipFile(r'CW41234.zip', 'r') as zipObj: # Extract all the contents of zip file in current directory zipObj.extract() The only problem is the unzipped folder I get is from CW_All and all the subfolders and file.

ProgrammingError at /admin/order/order/ relation “order_order” does not exist LINE 1: SELECT COUNT(*) AS “__count” FROM “order_order”

此生再无相见时 提交于 2021-02-11 12:32:23
问题 I'm working with django rest framework and I have a app named order. I wanted to change my order logic and I changed order app's models. but when I want to open order and order_item models in admin panel I have this error: ProgrammingError at /admin/order/order/ relation "order_order" does not exist LINE 1: SELECT COUNT(*) AS "__count" FROM "order_order" and also when i run migrate command it doesn't migrate well and doesn't create the order and OrderItem tabels in the database. I'm using