Questions tagged [python]

22684 questions
2

votes
0

answer
169

Views

vectorized matrix power and matrix dot using numpy

I want to calculate the power of many 2-D matrices, and would like to do it as fast as possible. I couldn't find a vectorized method to do it. For example: import numpy as np mat_list = [np.mat(np.random.randn(100,100)) for i in range(1000)] output = [np.linalg.matrix_power(mat_list[i], 100) for i i...
user5497
7

votes
0

answer
1.9k

Views

Grabbing Lists of Members of Google+ Communities [closed]

The Google+ Communities service appears to have launched without an API. Has anyone managed to come up with a Python script that can pull down a list of members of a Google+ Community? The calling URL to view community members is of the form: https://plus.google.com/u/0/_/communities/members?hl=en_G...
psychemedia
2

votes
0

answer
74

Views

Analyzing data with Excel [Python]

I'm a beginner in Python and as an exercize, I'm trying to run some basic statistical tests on some data that I have. The data is saved in an Excel file and it is structured in this way: 1 4 h 2,882233356 1,5 h 1 2 3 b 0,786094826 1 b 1 3 4 h 0,726763523 1 h 1 4 7 b...
2

votes
0

answer
106

Views

Iteration over cursor with pymongo unreasonably slow

Context I have a mongo database that has one collection called documents. This collection has 436333 entries and I have to do some operations on each of them. My code is: client = MongoClient() db = client['database'] documents = db.documents.find() bias = { 'title': pd.DataFrame(index=POS_TAGS, dty...
2

votes
0

answer
186

Views

XGBoost Convergence Plot with Sklearn Wrapper

I am using the sklearn wrapper for xgboost. I would like to generate a plot of AUC for both my train and test samples for each iteration as shown in the plot below. In sklearn you can use warm_start to iterate one at a time so you can easily stop to evaluate performance. Is there a way to do the...
Chris
2

votes
0

answer
146

Views

PyQt folder dialog change size after compiling

Im using Python 2.7 and PyQt4. I wrote a simple program that ask for directory on exit using QFileDialog.getExistingDirectory(). Then it shows it in a QMessageBox and ask the user if he wants to quit. The full code is: import sys from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __in...
ohad987
2

votes
0

answer
124

Views

Hooks in setuptools/distutils for post-install verification

I have a package that uses swig to generate some C++ interfaces to an external library, specifically udunits-2. On some systems, namely CentOS, the package will install successfully but when python tries to load the library an import error is raised. ImportError: /usr/local/lib/libudunits2.so.0: und...
lukecampbell
0

votes
0

answer
4

Views

How to scrap with conditions?

I am trying to scrap flight information from Orbitz with the folloing conditions: Choose Flight Only City flying from City flying to , Choose one-way flight on 15/12/2018 , Choose 1 adult and my code should return a csv file with the following information: Cities flying from and flying to Airports f...
xueyang wei
2

votes
0

answer
18

Views

Using NLTK/NaiveBayesClassifier, always getting 'Positive' output on test data

I have recently begun trying to get into Machine Learning and was following a tutorial that created a model that could determine if an inputted tweet was positive or negative. The program worked decently well, but it wasn't very accurate and I didn't want to tackle working with the Twitter API yet,...
Tom D
2

votes
0

answer
72

Views

try .. except Exception as <variable>

How can I get the entire object returned instead of just the "error_message" value when an error is thrown? (details below) I am currently working with the block.io API and am trying to extract data from the object returned when an error is thrown for a certain API call. I am working in Python 3.6....
vindard
2

votes
0

answer
351

Views

Migrating pandas dataframe from local computer using odo

Loading a pandas dataframe into postgres using odo does not work. I first use SQLalchemy to create a table object. The name of the table on my local postgres instance is testaccounts. meta = MetaData(bind=engine) table = Table('testaccounts', meta, schema='custom') odo(df, table)`enter code here Wh...
Lucas Neo
2

votes
0

answer
55

Views

Cannot allocate memory when forking in Python, but there is memory

When I run the following Thread, it spawns 5 forks. The first time I run it, it goes smooth, everything ok. But when it runs again, after the sleep(60) (while True loop), by the time the thread tries to fork() the processes, I get the following error: OSError: [Errno 12] Cannot allocate memory _td =...
Rodrigo Formighieri
2

votes
0

answer
485

Views

Python to interact with Youtube

I have started learning how to code in python and so far I've been doing normal exercises and I have an idea using which I want to explore more on python. It goes something like this. User is listening to music on his computer using some media player. If he/she plays any video on YouTube, then the m...
karun_r
3

votes
0

answer
31

Views

Updating a record with to_sql

I'm trying to use Pandas to compare a df from a text file against a df from a sql database. When an item is different in the text file df I wish to insert or if I already have it in the database update that field. # Text File # "Id","Stock_ID","Colour" # "298","203","Green" df1 = pd.read_table("data...
joshuahornby10
2

votes
0

answer
23

Views

Is there a way to modify Gtk.EntryCompletion to limit the number of completions displayed?

I've just begun exploring Gtk in Python after using Tkinter and the complexity is a bit overwhelming. I want to use EntryCompletion but I also want to limit the number of completion strings displayed and I have no idea how to go about this. I know from reading the Gtk documentation for EntryCompleti...
James
2

votes
0

answer
380

Views

Matplotlib - using imshow for transformed coordinates within meshgrid arrays

I am using a python script to calculate the stress fields (Z meshgrid array) for a defects within a metal. In order to do this, I have to transform the X and Y meshgrids (xtrans and ytrans). I am then using imshow to plot colour along with the contour lines. The problem I am having is that imshow as...
L. Menzies
7

votes
0

answer
50

Views

Purpose of assigning the return object to the function name after the function definition

I find the generated Python wrapper for a C++ function by swig has the following lines: def my_func(arg): return _cpp_mod.my_cpp_func(arg) my_func = _cpp_mod.my_cpp_func The source code in the .i file is as follows: %module cpp_mod ... ... %inline %{ MyObj& my_cpp_func(arg) { return *new MyObj(arg);...
Smith
0

votes
0

answer
3

Views

Handle Upload file pop up box using selenium python

I am trying to automate the process of sending audio files to my friend on whatsapp (web.whatsapp.com). Before I tried doing the same with text only and it works perfectly alright. Now i want to do it with audio/video/picture. from selenium import webdriver from selenium.webdriver.support.ui import...
user9181286
2

votes
0

answer
77

Views

Sporadic long response time for OpenShift gear [closed]

I have two Flask apps in OpenShift. Each one in a free small gear. Each one uses an own PostgreSQL cartridge. The code is quite simple: REST apps that do a query in the DB and return a JSON. The DB is almost empty and, in this test phase, they are accessed only by me and a response time recorder. Mo...
someone
2

votes
0

answer
48

Views

Populate Python dictionaries from .ini in RHEL5

I'm in the process of creating a script for dumpcap.exe that would add some more features to it. I am writing it to be multi-platform and most of the MSWindows version is complete. Currently I am moving what I have to REHL5 in order to start debugging and change what's needed in order to make the tr...
Googlesomething
2

votes
0

answer
185

Views

Making an independent RPC server with autobahn wamp (twisted)

I need to create an independent class that provides an RPC server running in its own Python process using wamp and autobahn. Following some guides found here, I managed to create this server in these classes saved into the file rpcwampserver.py: from twisted.internet.defer import inlineCallbacks fro...
link
3

votes
0

answer
306

Views

jupyter notebook resize plot to full cell width

I'd like to plot a line graph (in python) and have the plot size be set to the full width of the cell of the jupyter or jupyterlab notebook. (Also, if the cell width changes I'd like to be notified and have the opportunity to change the plot size) I am aware of matplotlib.rcParams['figure.figsize']...
paulperry
2

votes
0

answer
58

Views

How to extract data from xml file that is deep down the tag

true false PT2M21.835S 26.505801694441629 0.023379150593228679 -3.593643144 7.316485176 0.31103436 7.70408184 I am only interested in 'accelx' and 'accely' value in this data and need to create a csv out of it. Update: The code given below breaks when I change the second row with the following. No...
learner
0

votes
0

answer
3

Views

Accessing custom python modules defined in AWS::Lambda::LayerVersion

There is an AWS lambda with a layer defined. From the lambda I try to access a custom python package defined in the layer, but it doesn't seem to be there. Is it even possible to share code that is stored in the layer package? I would imagine something like this: /layer-dir /my-package /__init__.py...
dmigo
3

votes
0

answer
25

Views

Why are negative cube roots converting to complex numbers sometimes? [duplicate]

This question already has an answer here: Why is (-27)**(1.0/3.0) not -3.0 in Python? 3 answers Calculation error with pow operator 4 answers Python 3.6 using Jupyter Notebook, and I'm getting strange results from an equation. print(-8) print(-8**(1/3)) print(-64**(1/3)) print((-8*8)) print((-8*8)...
Yuri Sonovab
3

votes
0

answer
175

Views

Why does my TreeBuilder object not contain TreeBuilder's private attributes?

When I instantiate an xml.etree.ElementTree.TreeBuilder object, I cannot see any of TreeBuilder's private attributes. Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> >>> import xml.etree.ElementTree as etre...
tbhartman
2

votes
0

answer
119

Views

Method is hanging within function, not sure why

Okay, so I'm making a bot framework in python, and I'm having issues with creating a twitter command. I'm not sure how much sense this will make to anyone else, I think I did my best to explain this, so let me know if I can provide anymore information or code. So, my twitter command looks like this...
Jake
2

votes
0

answer
20

Views

strftime syntax while sending command with sshclient_exec_command

I am getting the current time from system with datetime and storing it as string(timenow), but there is some behaviour difference when i send it to set in linux through sshclient_exec_command. Below is my code: timenow = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") command = 'date -s %s'...
Santosh Sahu
2

votes
0

answer
24

Views

Picture doesn't show up while my python socket script trying to streaming a picture

import PIL import ImageGrab import socket import io import atexit def server(): while True: print('wait..') conn, addr = server_socket.accept() if conn: print(conn) print(addr) connection = conn.makefile('wb') break print('connecting..') try: stream = io.BytesIO() ImageGrab.grab().save('1.jpg','JPEG...
Shawn Xiao
3

votes
0

answer
444

Views

Fixing Memory Leak in Django + Scikit-learn

How do you diagnose and fix memory leaks involving Django and Scikit-learn? I'm working on a Django management command that trains several text classifiers implemented using scikit-learn. I'm using all the tricks I know to plug Django memory leaks, including: Setting DEBUG=False Use .iterator() for...
Cerin
3

votes
0

answer
170

Views

Hit a Wall Webscraping with Python

I am very new at this. I'm using Eclipse SDK with PyQt4 (to unearth any stuff obscured by javascript). I am attempting to discover links to results from a site. For example: http://www.mrtzcmp3.net/billy_jean_Bs.html import sys from PyQt4 import QtWebKit from PyQt4 import QtCore from PyQt4 import Qt...
lakecityransom
2

votes
0

answer
89

Views

Running Selenium browser inside linux server for Whitelisted URLs

We have provisioned for a Red Hat Linux Server to run the python api's for web scraping. This server is not open to all links outside the world. The URLs need to be white-listed to enable access on that site. We have whitelisted itunes, Vudu.com and Target.com When running the Selenium, we are able...
user3057556
2

votes
0

answer
43

Views

Install a python module without the package name in setuptools

I have the following project tree: project/ |-pkgOne/ | |- ... |-pkgTwo/ | |- ... |-classes/ | |-__init__.py | |-MyClass.py | |-MyOtherClass.py |-setup.py I wonder if there is a method to install my classes in a way that prevent this import form: from classes import MyClass But inste...
Knarfux
2

votes
0

answer
313

Views

Accessing Jira 4.4.5 via JSON-RPC on localhost http port

I am trying to get access to a local JIRA 4.4.5 installation using it's JSON-RPC service. Therefore I wrote a python script utilizing jsonrpclib and trying to connect to http://localhost:8080/jira/rpc/json-rpc/jirasoapservice-v2​ as described on https://developer.atlassian.com/display/JIRADEV/JIRA...
Sebastian K
2

votes
0

answer
101

Views

Create new column from matched list of words in dataframe

I have a dataframe with a column that contains a string with mixed delimiters (space vs. none) between words as well as numbers: 'Widgets' MakeOneModelx2000 MakeOneModelx Modely2000 MakeOneModelx Modely Modelz2000 Make123456ThreeModelfoo Make123456FourModelbar I want to separate the make and model a...
joe_slow
2

votes
0

answer
159

Views

Basemap quality map library for C++

Is there any map library available for C++ that produces python's Basemap quality results? My interest in this is primarily driven by slowness of basemap, because despite its great output, it is very very slow for high-resolution contour plotting.
deepak
3

votes
0

answer
37

Views

Why does cmp(unicode, np.int64) fails with UnicodeDecodeError?

Why does this fail in this way: import numpy as np cmp(u"Never", np.int64(500)) #UnicodeDecodeError: 'ascii' codec can't decode byte 0xf4 in position 0: ordinal not in range(128) while this succeeds: cmp(u"Never", int(np.int64(500))) I ran across this while trying to group a pandas dataframe conta...
user48956
2

votes
0

answer
133

Views

gcc.exe error while installing kerberos using the Anaconda distribution

New to python, trying to install kerberos. I am trying to use pip install kerberos on windows with the Anaconda 2.7 distribution, but am running into an error with the gcc compiler. I am having the same problem as someone before me, with the same output error code. The question went unresolved in th...
TKW
2

votes
0

answer
99

Views

Which python interpreter is ipdb using?

I am asking because I encounter something very strange. The following method throws an exception when called from within a script: def gaussian_blur(self, in_array, size): # expand in_array to fit edge of kernel padded_array = np.pad(in_array, (10,), 'reflect') # build kernel x, y = np.mgrid[-size:...
LarsVegas
2

votes
0

answer
967

Views

Scraping an HTML table with BeautifulSoup

I'm trying to scrape the data in a table on the FT website, but I cannot get my code to work. I've been through other similar questions here on Stack Overflow, and while they have helped, it's beyond my skill to get the code working. I'm looking to scrape the table and output to a list of dicts, or...
Obol