Questions tagged [python]

530193 questions
1

votes
1

answer
117

Views

Converting a VPython program to an exe using cx_Freeze

I have coded a VPython simulation but I can't compress it into an exe using cx_Freeze. I think it is because of VPython module since cx_Freeze works when I compress other programs that don't use VPython. Detailed steps: This is my test simulation program: from vpython import * ### Simulation ### def...
Momo 6aye3
1

votes
2

answer
851

Views

Tell pylint what the return type of a method is

To give details: this is a constrained environment with Python 2.7.14, Pylint 1.8.1, and Astroid 1.6.0 and various other modules, but I can't easily install new modules such as mypy (not even with virtualenv) or make major changes to the codebase. Due to https://github.com/PyCQA/pylint/issues/400 I'...
MadScientist
1

votes
0

answer
24

Views

Print Dates range if they are available in db

from below code i am going to print date ranges that's fine but what the problem is i need to print the date ranges , those available in database only [this image shows the created_at date field which is in look model . I need these dated to be printed if user select the date rage between dec 1 to...
Access_Doomer
1

votes
1

answer
330

Views

Passing Parameters to upload_to Parameter in Django File Upload

I am using the following post to upload files in Django: https://simpleisbetterthancomplex.com/tutorial/2016/08/01/how-to-upload-files-with-django.html. In the post, it mentions that the upload_to parameter can be a callable that returns a string. In the example provided, the callable accepts two pa...
Foobar
1

votes
1

answer
101

Views

python cPickle.PicklingError: Can't pickle <type 'instancemethod'> .I know the reason, but I don't know how to solve it

I need a reliable code, and I've done a lot of related tests, and it seems that it can only serialize the string and not serialize the sheet object from multiprocessing import Pool import openpyxl def proxy(cls_instance, index): return cls_instance.func(index) class Runner(object): def __init__(self...
loopbing
1

votes
2

answer
395

Views

Preprocess the input data slow down the input pipeline when using Tensorflow Dataset API to read TFRecords file

I am using Tensorflow Dataset API to read TFRecords files, but the GPU usage is still low (10%). I reckon the cause is that I preprocess the data before they are fed into the sess.run(). Here is my code below. 1. Create a dataset from 3 separate files. tf.reset_default_graph() # The content of TFR...
Lion Lai
1

votes
0

answer
186

Views

Websocket communication works with localtunnel but not ngrok

I created a little multiplayer game to learn how Python's asyncio worked. I tested everything on localhost first -- everything worked. I then used ngrok to expose my localhost so I could play with some friends. However, every time they connected through ngrok, their client never updated. The client...
Peter Wang
1

votes
3

answer
4.3k

Views

how to fetch firebase data?

I am new to python and firebase and I am trying to flaten my firebase database. I have a database in this format each cat has thousands of data in it. All I want is to fetch the cat names and put them in an array. for example I want the output to be ['cat1','cat2'....] I was using this tutorial ht...
learner101
1

votes
1

answer
50

Views

how to convert pandas time data into the format that can be processed by matplotlib

in the 3 section of lecture, i encounrtered a problem that I could not upload any finance data from yahoo, so I use pandas datareader to uploaded a stock info for microsoft here is that code: MS= data.DataReader(name = 'MSFT', data_source = 'yahoo', start = '2007-07- 10', end = '2008-12-10') MS.head...
Xiaoyang Wu
1

votes
0

answer
77

Views

Pixel control in terminal with Python

I am just getting to grips with modern programming having previously dabbled in QBasic as a child. In QBasic I could run in DOS and write a program which would control individual pixels on the screen. I was able to do quite a lot graphically with this without having to worry about windows etc. I've...
Luke Richards
1

votes
0

answer
263

Views

I am having trouble training a simple neural network

I am learning to make neural network and I have derived the following equations for backpropagation. Is something wrong with this because I can't seem to get the neural network training. I am coding in python and the accuracy I get is around 10 (I get this even when I don't train my network). Howeve...
Nischit Pradhan
1

votes
2

answer
88

Views

Create a new column in a dataframe if the column contains a string from a column of another dataframe

I want to create a new column in my dataframe if the column contains any of the values from a column of a second dataframe. First dataframe WXYnineZAB EFGsixHIJ QRSeightTUV GHItwoJKL YZAfiveBCD EFGsixHIJ MNOthreePQR ABConeDEF MNOthreePQR MNOthreePQR YZAfiveBCD WXYnineZAB GHItwoJKL KLMsevenNOP EFGsix...
Prasad
1

votes
0

answer
306

Views

run a function in python as non blocking thread

I am simulating a use case in which clients send a request to the server for a particular service time and then, the server creates a new VM for each client request and then stop VM and destroy VM when service time is over. For simulating this behavior, I have made a client request generator whic...
Amarjit Singh
1

votes
1

answer
794

Views

Python > Matplotlib > Animated live plot > framerate

this is my first question post. Im seeing a refresh rate of about 1 frame every 5 seconds in my live plot using the below code. I want to see something close to real-time updates. The serial rate of the data being plotted is sufficient to support at least 2 frames per second. I've built this sim...
Matt Bauer
1

votes
2

answer
53

Views

Passing Python variable to Javascript with Webapp2/Jinja2

I've researched this answer and haven't found a way to do this using webapp2. I need to pass a variable from my Python code into my Javascript code. I understand how to pass variables into my HTML using Jinja2 but I am stumped on how they can then be used in Javascript. This is what I have put in th...
user9109814
1

votes
1

answer
71

Views

Django: how to mock a user with FB privilegies

I need to check that the content of a template is loaded properly. However, I need a user that has Facebook integration. This is my view: def profile(request, user_id): '''A user's public pledge settings.''' user = get_object_or_404(SocialUser, pk=user_id) # We only want to show profile pages for us...
lmiguelvargasf
1

votes
0

answer
118

Views

zbar not working on netcat video stream from raspberry pi read using OpenCV

I am streaming video feed from raspberry pi using netcam to my PC and using zbar to read qr codes i the feed. I am reading the named pipe using ffmpeg: FFMPEG_BIN = 'ffmpeg' command = [ FFMPEG_BIN, '-i', 'fifo264', # fifo is the named pipe '-pix_fmt', 'gray', # opencv requires bgr24...
Snehil Vijay
1

votes
0

answer
29

Views

Adding n different lists to list results same list repeating [duplicate]

This question already has an answer here: List of lists changes reflected across sublists unexpectedly 12 answers How to clone or copy a list? 20 answers When I add lists to my list the result is list of correct length, but all the lists are the same, last list I added code: cycle_points = [] for...
Arttu Hyvönen
1

votes
1

answer
227

Views

Returning an image from a Django view using django-sslserver

I'm trying to return an image from a Django 1.11 view while using django-sslserver and Pillow. Here's a minimal view I made for testing. def get_image(request): img = Image.open('oh_noes_cat.png', mode='r') response = HttpResponse(content_type='image/png') img.save(response, 'png') return response I...
clairempr
1

votes
0

answer
61

Views

What's the right way to get the current time in python in a way that will be guaranteed to be consistent with the filesystem?

I have a very simple build script that's behaving in an unexpected way (for me) on Linux. Part of the script simply checks that the files generated by a build stage hasn't been manually replaced with a stale file. # load the cache from a json file if os.path.getmtime(some_path) < cache['timestamp']:...
Frank
1

votes
1

answer
263

Views

Binary Segmentation of an complex image in python. [closed]

I was trying to implement a binary segementation for my project work but I got stucked with the binary segmentation code. I just want to a get a continuos segmentation of a player and background in the picture like this image (A proper segmentation of a hand). imgort numpy as np impo...
kanik garg
64

votes
19

answer
121.6k

Views

Check if a number is a perfect square

How could I check if a number is a perfect square? Speed is of no concern, for now, just working.
1

votes
1

answer
142

Views

Error while trying to establish session with user's PIN (smartcard)

I'm using python-pkcs11 to access a smartcard I own. Right now, I was trying to create a session, so that I could retrieve the Public Key from the card. This is the code I was testing: path = (...) os.environ['PKCS11 MODULE'] = path lib = pkcs11.lib(os.environ['PKCS11 MODULE']) password = bytes('123...
imll
1

votes
0

answer
1.1k

Views

Pandas Styling HTML with Style.apply [duplicate]

This question already has an answer here: How to use `style` in conjunction with the `to_html` classes on a DataFrame? 1 answer Change the color of text within a pandas dataframe html table python using styles and css 2 answers I am trying to use my highlight_diff function to compare two dataframe...
Tyler Russell
1

votes
0

answer
29

Views

How to pass several values as nosetests' options in setup.cfg?

I currently run my tests with : nosetests3 -vd -w . module1 module2 ...And I would like to automate these options. However, I can't find a way to pass several values to an option... I tried this : [nosetests] verbosity=1 detailed-errors=1 where=. module1 module2 ...But it replies ValueError: Worki...
hl037_
1

votes
0

answer
91

Views

stop scipy fsolve or hybrd immediately when the tolerance is reached

I am dealing with a time-­consuming optimization problem where each function evaluation takes about 20 minutes, and I have to perform the optimization for several parameters. Therefore, I would like to terminate the scipy fsolve or hybrd immediately when the maximum of the function return values ar...
henhans
1

votes
0

answer
626

Views

how to make tensorflow pb file of the modified model by using pb file of pre-trained graph

I try to make image retrieval application by using tensorflow. I want to use a pre-trained Inception v3 model for feature extraction. I got the pb file of Incetion v3 from tensorflow mobile demo. BUT this model is for classification. so I have to use the model without a few layers at the end of the...
주은혜
1

votes
0

answer
92

Views

Simple GET request in cURL is unresponsive

I wrote python code for a very basic server to test cURL on my terminal (Mac OS X) from flask import Flask node = Flask(__name__) @node.route('/greet', methods=['GET']) def greet(): print 'hello, world' return 'hey!' node.run() However, when I ran the code on my terminal, using $ python testblock....
ztlm622
1

votes
0

answer
189

Views

I am trying to change the value of an exposed variable in RPyC. I receive an error. What am I doing wrong?

I am using RPyC for a client-server application. I try to change the value of exposed_variable when I call exposed_change() method. I receive 'UnboundLocalError: local variable 'exposed_variable' referenced before assignment' error. However, if I make exposed_variable global (before I try to modify...
SomeoneNew
1

votes
1

answer
599

Views

pytesseract results different from tesseract command line results

I am trying to convert a scanned page to text using both pytesseract and tesseract command line on Ubuntu. The results are remarkably different (pytesseract performs way better than tesseract command line) and I am unable to understand why. I looked at the default values for the parameters and trie...
randomSampling
1

votes
0

answer
55

Views

Using tqdm with a class and arguments

Im attemting to use tqdm and multiprocessing to run through a range of values and pass that same range value into the class im calling as an argument. I can't seem to find anything useful online on how to pass arguments of the iteration into the fuction call (in my case im calling a class function),...
iNoob
1

votes
1

answer
37

Views

Python 3.6: Using object instance name for raising errors

I'm attempting to create a 3-d graphics engine using Python 3.6, Tkinter, and specifically NOT pygame (or any other 3d graphics engines) as part of a university assignment. Within this project, I have had to create a 'matrix' class, which allows me to easily create and manipulate mxn matrices. I bel...
William Pulford
1

votes
0

answer
182

Views

Python : spectrogram speech recognition

I am trying to reproduce a preprocessing seen in a youtube video https://www.youtube.com/watch?v=g-sndkf7mCs where they create a spectrogram taking a windows of 20 ms and then apply an FFT on it. Finally they feed a neural network with the spectrogram obtained. I am using the scipy package but I am...
Shiro
1

votes
0

answer
36

Views

Vectorize quintuple for loop in numpy, with non-trivial indexing

I have a series of nested for loops, used to populate a rank-3 array as follows: S = ... # Some number N = ... # Some other number an_array = np.zeros((S, N * N, N * N)) for s in range(S): for i in range(N): for a in range(N): for j in range(N): for b in range(N): an_array[s, i * N + a, j * N + b]...
Daniele Grattarola
1

votes
0

answer
349

Views

Python 3.5.x multiprocessing throwing “OSError: [Errno 12] Cannot allocate memory” on a 74% free RAM system

I wrote a Python 3.5 application that spawns several processes using multiprocessing library. It runs on Ubuntu 16.04.3 LTS on a dedicated server machine that ships with 2 x Intel Xeon E2690 v1 (8 cores each) and 96GB of RAM. This system runs a PostgreSQL instance which is configured to use a maximu...
pietrop
1

votes
2

answer
71

Views

Tensorflow multiplication of constants performance slower than tf.random

I'm using Tensorflow for some non-DL computation, and I'm running into a behaviour I don't understand. I am testing the multiplication of a square matrix by itself: tf.matmul(a,a): when the matrix is created with tf.constant when the matrix is randomly initialized at each run My expectation is that...
Anna-Chiara Bellini
1

votes
0

answer
38

Views

javascript template for showing table body

I am using ajax for updating/refreshing the cart when an item is removed from the cart table to show the updated items. ajax functionality and logic is working but could not show the following template inside {% for furniture in cart.furnitures.all %} {% include 'includes/carts/remove-furniture.htm...
pri
1

votes
1

answer
36

Views

How to search some word in python help() built-in function result?

Sometimes I need search some thing inside some python library docs that I have installed and I always use help() built-in function but I would like to know if there are some way to search inside this content or even better, without need to open a python terminal. I really would like to know some cl...
Juan Antonio
1

votes
0

answer
187

Views

NLTK: Auto suggestion for query completion using grammar

I want to implement Auto-Suggestion for question completion (Refer Section 3.2) for my FCFG using nltk APIs. E.g. Consider the following CFG grammar: S -> NP VP NP -> Det NN | PropN VP -> V NP | V V -> 'eats' | 'sleeps' | 'ate' Det -> 'a' | 'an' | 'the' NN -> 'police' | 'horse' | 'apple' | 'potato'...
Aman Gill
1

votes
0

answer
336

Views

Find mapping between spherical panorama and new image in opencv

I have an established spherical 360 view and a new undistorted image I want to find a mapping between each image pixel and the 360 view, which effectively means finding the θ and ϕ in spherical coordinates for every x and y in cartesian I have been playing around a bit and I do have a set of match...
rikkertkoppes

View additional questions