title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
import tensor with mat format to tensorflow | 37,620,330 | <p>I am new in tensorflow and Python. I have an image data set in Matlab in a tensor with size : 96*96*5000 (image size , number of images) and I need to import it to Tensorflow. I looked at the Tensorflow tutorial, which says I should use TFRecords or CSV formats but I think this means that I save each image separatel... | 1 | 2016-06-03T17:28:41Z | 37,623,913 | <p>As Olivier said in <a href="http://stackoverflow.com/questions/37620330/import-tensor-with-mat-format-to-tensorflow#comment62727615_37620330">his comment</a>, the easiest solution is to convert the data into a Numpy array, and use TensorFlow's <a href="https://www.tensorflow.org/versions/r0.8/how_tos/reading_data/in... | 1 | 2016-06-03T21:44:10Z | [
"python",
"matlab",
"tensorflow"
] |
Numpy: would vstack automatically detect an index is out of range and correct it? | 37,620,446 | <p>I'm puzzled as to why the in the code below (the section where I labeled "HERE"), would work because j+1 would make the list of list (which is the X_train_folds) go out of range when j reaches the end of the range. Why would this even work? Is it because vstack can automatically detect this change? I couldn't find a... | 0 | 2016-06-03T17:37:31Z | 37,621,507 | <p>No. <code>vstack</code> is not causing that, but the very powerful <a href="http://docs.scipy.org/doc/numpy-1.10.1/user/basics.indexing.html#other-indexing-options" rel="nofollow">indexation of numpy</a> is. The internals of numpy are complex and sometimes it returns a copy, other times a <a href="http://stackoverfl... | 1 | 2016-06-03T18:49:40Z | [
"python",
"numpy"
] |
Formatting a date and time with periods as separators | 37,620,450 | <p>I am trying to apply current time and date in a Windows application using Python. I used the following code:</p>
<pre><code>current_time = str(time.strftime("%m.%d.%Y %H:%M"))
type(waitForObject("{name='TextBoxSampleName'}"), "Test." + current_time)
</code></pre>
<p>but when I run the script I see the following ... | -2 | 2016-06-03T17:37:59Z | 37,620,562 | <p>Without knowing what <code>waitForObject</code> is, we can still get the output you desire.</p>
<p>First, there is a minor formatting mistake in your <code>current_time =</code> line:</p>
<pre><code>current_time = str(time.strftime("%m.%d.%Y.%H:%M"))
^-- Add this period to... | 0 | 2016-06-03T17:45:53Z | [
"python"
] |
Pygame, Tkinter or something else for TUI and responding to keyboard input? | 37,620,532 | <p>I'm quite new to programming and trying to write a fairly simple program that records the times in between different keyboard button presses (a bit like multiple reaction time tests) and prints these times on screen in an array, then terminates and saves the array after a certain period of time is up.</p>
<p>I've a... | 0 | 2016-06-03T17:43:52Z | 37,625,532 | <p>Using Tkinter, you can bind to <code><Any-KeyPress></code>. The function that is called is passed an event object that has a timestamp. You can use that to compute the time between events. </p>
<p>Here's a quick example that shows how to display the time between keypresses. You can of course add your own logi... | 0 | 2016-06-04T01:38:06Z | [
"python",
"tkinter",
"keyboard",
"pygame",
"tui"
] |
Quickly accessing/querying large delimited text file in python | 37,620,611 | <p>After searching for a while, I have found many related questions/answers to this problem but nothing that really addresses what I am looking for. Basically, I am implementing code in python to be able to query information from a star catalogue (in particular the tycho 2 star catalogue).</p>
<p>This data is stored ... | 4 | 2016-06-03T17:48:58Z | 37,621,940 | <p>As @wflynny has already mentioned PyTables (HDF5 store) - is much more efficient compared to text/CSV/etc. files. Beside that you can read from PyTables conditionally using <code>.read_hdf(where='<where condition>')</code>.</p>
<p>You may want to check <a href="http://stackoverflow.com/a/37012035/5741205">thi... | 1 | 2016-06-03T19:20:23Z | [
"python",
"database",
"numpy",
"pandas"
] |
check if robot is connected and disconnected to charging station | 37,620,629 | <p>I'm working with a Nao from Aldebaran and I want to write a python script to check if the battery is charging or not.</p>
<p>There is a documentation about the naoqi modules. I found this event <a href="http://doc.aldebaran.com/2-4/naoqi/sensors/albattery-api.html#BatteryPowerPluggedChanged" rel="nofollow">1</a>. B... | -1 | 2016-06-03T17:50:12Z | 37,620,816 | <p><a href="http://doc.aldebaran.com/2-4/family/nao_dcm/actuator_sensor_names.html#battery" rel="nofollow">This linked page</a> shows that there are Current and Charge% values available to read. I would test those and see if the sign of Current changes when charging, compared to running on battery. Alternately, chec... | 1 | 2016-06-03T18:02:24Z | [
"python",
"nao-robot"
] |
check if robot is connected and disconnected to charging station | 37,620,629 | <p>I'm working with a Nao from Aldebaran and I want to write a python script to check if the battery is charging or not.</p>
<p>There is a documentation about the naoqi modules. I found this event <a href="http://doc.aldebaran.com/2-4/naoqi/sensors/albattery-api.html#BatteryPowerPluggedChanged" rel="nofollow">1</a>. B... | -1 | 2016-06-03T17:50:12Z | 37,895,730 | <p>You can use ALMemory API to subscribe to the event "BatteryChargingFlagChanged" : <a href="http://doc.aldebaran.com/2-4/naoqi/core/almemory-api.html#ALMemoryProxy::subscribeToEvent__ssCR.ssCR.ssCR" rel="nofollow">http://doc.aldebaran.com/2-4/naoqi/core/almemory-api.html#ALMemoryProxy::subscribeToEvent__ssCR.ssCR.ssC... | 0 | 2016-06-18T10:03:21Z | [
"python",
"nao-robot"
] |
check if robot is connected and disconnected to charging station | 37,620,629 | <p>I'm working with a Nao from Aldebaran and I want to write a python script to check if the battery is charging or not.</p>
<p>There is a documentation about the naoqi modules. I found this event <a href="http://doc.aldebaran.com/2-4/naoqi/sensors/albattery-api.html#BatteryPowerPluggedChanged" rel="nofollow">1</a>. B... | -1 | 2016-06-03T17:50:12Z | 38,037,748 | <blockquote>
<p>In my opinion I can wait for an event, but I can't read it like a bool. Am I right?</p>
</blockquote>
<p>Not possible for battery. Each event that is published sends a signal, which "flips" a switch in ALMemory. You can only read the value or state of a quantity if such memory key exists for them. Ot... | 0 | 2016-06-26T10:52:39Z | [
"python",
"nao-robot"
] |
python visualize 4d data with surface plot and slider for 4th variable | 37,620,661 | <p>How can I visualize a 4d data (loaded from a csv file) set using 3-d surface plots of the first 3 variables and the fourth variable as a slider?</p>
| 0 | 2016-06-03T17:52:36Z | 37,634,314 | <p>I've written a very small example highlighting the way you can achieve this:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
nx = 100
ny = 100
nz = 100
data = np.random.rand(nx,ny,nz)
fig = plt.figure(1, figsize=(6,6))
main_ax = fig.add_axes([0.1,0.2,0.8,0... | 0 | 2016-06-04T19:41:56Z | [
"python",
"matplotlib",
"data-visualization"
] |
PIL: pixels mathematical properties | 37,620,666 | <p>I'm trying to do some mathematical operations on single pixels using PIL.</p>
<p>From the internet I could load an image into a 2d array like this:</p>
<pre><code>from PIL import Image
img_filename = "CNH.JPG"
im = Image.open(img_filename)
im = im.convert('L')
pix = im.load()
</code></pre>
<p>I did some changes ... | 0 | 2016-06-03T17:52:55Z | 37,624,549 | <p>It works fine here:</p>
<pre><code>In [15]: pix[i,j]
Out[15]: 145
In [16]: pix[i,j]+5
Out[16]: 150
In [17]: pix[i,j]/2
Out[17]: 72
In [18]: float(pix[i,j]/2)
Out[18]: 72.0
In [19]: pix[i,j] = float(pix[i,j]/2)
In [20]: pix[i,j]
Out[20]: 72
</code></pre>
<p>Of course, this is integer division (hence <code>145/2... | 0 | 2016-06-03T22:53:34Z | [
"python",
"python-imaging-library"
] |
Matching more than one word | 37,620,761 | <p>I've the following phrases and I'd like to match them:</p>
<blockquote>
<p>"De la Sota: Hello" -> "De la Sota"</p>
<p>"Guini: Hello" -> "Guini"</p>
<p>"Prat Gay: Hello" -> "Prat Gay"</p>
</blockquote>
<p>I'm using <code>r"(\w+):"</code> but it only matches the last word before <code>:</code>.</p... | 0 | 2016-06-03T17:59:12Z | 37,620,796 | <p>Simply use this pattern:</p>
<pre><code>/^(.*):/gm
</code></pre>
<p>Now <code>$1</code> is containing what you need.</p>
<h3><a href="https://regex101.com/r/qT5sJ4/2" rel="nofollow">Online Demo</a></h3>
<p>Noted that I'm pretty sure there is a better approach than regex for doing that. But I'm not a python exper... | 2 | 2016-06-03T18:01:11Z | [
"python",
"regex"
] |
Matching more than one word | 37,620,761 | <p>I've the following phrases and I'd like to match them:</p>
<blockquote>
<p>"De la Sota: Hello" -> "De la Sota"</p>
<p>"Guini: Hello" -> "Guini"</p>
<p>"Prat Gay: Hello" -> "Prat Gay"</p>
</blockquote>
<p>I'm using <code>r"(\w+):"</code> but it only matches the last word before <code>:</code>.</p... | 0 | 2016-06-03T17:59:12Z | 37,620,826 | <p>change \w+ to .+ or .*:</p>
<pre><code>input_text = ''' De la Sota: Hello
Guini: Hello
Prat Gay: Hello'''
print(re.findall(r'(.+):',input_text)
</code></pre>
| 0 | 2016-06-03T18:02:42Z | [
"python",
"regex"
] |
Matching more than one word | 37,620,761 | <p>I've the following phrases and I'd like to match them:</p>
<blockquote>
<p>"De la Sota: Hello" -> "De la Sota"</p>
<p>"Guini: Hello" -> "Guini"</p>
<p>"Prat Gay: Hello" -> "Prat Gay"</p>
</blockquote>
<p>I'm using <code>r"(\w+):"</code> but it only matches the last word before <code>:</code>.</p... | 0 | 2016-06-03T17:59:12Z | 37,620,834 | <p><code>str.split(":")[0]</code> should work, where <code>str</code> is your string you'd like to split.</p>
<pre><code>>>> str = "De la Sota: Hello"
>>> str.split(":")[0]
'De la Sota'
</code></pre>
<p>This works by splitting the string into a list, where the parameter is the delimiter. If you spe... | 2 | 2016-06-03T18:03:22Z | [
"python",
"regex"
] |
Matching more than one word | 37,620,761 | <p>I've the following phrases and I'd like to match them:</p>
<blockquote>
<p>"De la Sota: Hello" -> "De la Sota"</p>
<p>"Guini: Hello" -> "Guini"</p>
<p>"Prat Gay: Hello" -> "Prat Gay"</p>
</blockquote>
<p>I'm using <code>r"(\w+):"</code> but it only matches the last word before <code>:</code>.</p... | 0 | 2016-06-03T17:59:12Z | 37,623,888 | <pre><code>"Prat Gay: Hello" -> "Prat Gay"
</code></pre>
<p>If that is exactly what you have you can use a negation set to get rid of <code>:</code>, <code></code> (using <code>\s</code> -- or if it is a tab using <code>\t</code>) and Helo because it is a set. As for names, some last name contain <code>-</code>, or... | 0 | 2016-06-03T21:42:07Z | [
"python",
"regex"
] |
Ubuntu 16.04 python installing 3rd party module ffmpeg-3.0.2 | 37,620,941 | <p>Have tried installing this package multiple times. Initially I installed it to a directory where I am running scripts that call it but I get an error message "ImportError: No module named 'ffmpeg'".</p>
<p>I then tried putting it in one of my python paths listed in sys.path and again I got the same message.</p>
<p... | 0 | 2016-06-03T18:09:45Z | 37,622,128 | <p>If you allready use Conda, than I would recommend installing pyav via Conda. Pyav has the python bindings (small programms) to run ffmpeg. Best of all as conda also installs the needed binaries, it also installs an ffmpeg to use.</p>
<p>If you just want to split your movie into a series of images you can do this fr... | 0 | 2016-06-03T19:34:12Z | [
"python",
"module",
"ffmpeg",
"install"
] |
Load existing Excel file, change the zoom level for all sheets, and remove gridlines | 37,620,967 | <p>I'm using <code>win32com</code> to load an existing Excel doc. I'm currently able to loop through the sheets and remove text wrapping and autofit columns.</p>
<pre><code>import win32com.client
excel = win32com.client.Dispatch('Excel.Application')
excel.Visible = False # I want to keep it this way
path = "C:\\User... | 0 | 2016-06-03T18:11:11Z | 37,635,373 | <pre><code>import win32com.client
excel = win32com.client.Dispatch('Excel.Application')
excel.Visible = False # I want to keep it this way
path = "C:\\Users\\username\\Documents\\DDA"
wb_new = excel.Workbooks.Open(path + '\\new_file.xlsx')
# wb_new is a file with three tabs, with one value in cell A1 each...
# ...i... | 0 | 2016-06-04T21:51:57Z | [
"python",
"excel",
"python-2.7",
"win32com"
] |
get pandas value by another file python pandas | 37,620,975 | <p>I have a small sample dataset:</p>
<pre><code>import pandas as pd
df = {'ID': ['H576','H577','H578','H600', 'H700'],
'CD': ['AAAAAAA', 'BBBBB', 'CCCCCC','DDDDDD', 'EEEEEEE']}
df = pd.DataFrame(df)
</code></pre>
<p>it looks like:</p>
<pre><code>Out[76]:
CD ID
0 AAAAAAA H576
1 BBBBB H577
2 CCCCC... | 1 | 2016-06-03T18:11:36Z | 37,621,390 | <pre><code>import pandas as pd
df = {'ID': ['H576','H577','H578','H600', 'H700'],
'CD': ['AAAAAAA', 'BBBBB', 'CCCCCC','DDDDDD', 'EEEEEEE']}
df = pd.DataFrame(df)
keywords = pd.read_csv('file.txt', header=None)[0]
mask = df['CD'].isin(keywords)
result = df.loc[mask]
print(result[['ID', 'CD']].stack().to_csv(None... | 4 | 2016-06-03T18:41:49Z | [
"python",
"pandas"
] |
Convert python dict to json object with formatted keys and values | 37,620,980 | <p>So i have my dict from my form post</p>
<pre><code>post_dict = dict(request.POST)
item_data = {}
for key, value in post_dict.items():
if 'item_data' in key:
field = key.split('[')[1].replace(']', ' ')
item_data[key] = ' '.join(value)
data = json.dumps(item_data)
print(data)
</code></pre>
<p>Right ... | -1 | 2016-06-03T18:11:47Z | 37,621,011 | <p>Use <code>item_data[field] = ...</code> per Tadhg McDonald-Jensen's comment and replace</p>
<pre><code>data = json.dumps(item_data)
</code></pre>
<p>with</p>
<pre><code>data = json.dumps(item_data, indent=2, separators=(',', ': '))
</code></pre>
| 2 | 2016-06-03T18:14:47Z | [
"python",
"json"
] |
Tkinter add menu bar in Frames | 37,621,071 | <p>I was using the code posted in answer here <a href="http://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter">Switch between two frames in tkinter</a>
by Brayan. Now I want to add some menu bar. In Pageone I want to add menus <code>File</code> and <code>Help</code> and in Pagetwo I want to ad... | -1 | 2016-06-03T18:19:10Z | 37,624,524 | <p>The simplest solution is to add a method to every page that creates the menubar for that page, and then switch to that menu when you switch frames. </p>
<p>This will likely require you to have a bunch of duplicate code for all of the menu items that will be common between pages (eg: edit->cut, edit-copy, edit-paste... | 1 | 2016-06-03T22:50:44Z | [
"python",
"python-2.7",
"tkinter"
] |
Django model is saved twice after create | 37,621,106 | <p>I can't figure out how my model is being saved two times. The model is called <code>Job</code>. If customer creates an order, the <code>Job</code> instance is created. After creation, there is a signal, which alerts admin that new <code>Job</code> object has been created or edited. </p>
<pre><code>@receiver(post_sa... | 3 | 2016-06-03T18:22:27Z | 37,643,159 | <p>add <code>dispatch_uuid</code> while connecting receiver as per <a href="https://docs.djangoproject.com/en/1.9/topics/signals/#preventing-duplicate-signals" rel="nofollow">docs</a></p>
<pre><code>def create_delivery(sender, instance, created, **kwargs):
if created:
delivery,created_delivery = Delivery.o... | 0 | 2016-06-05T14:44:23Z | [
"python",
"django",
"django-models",
"django-views"
] |
Python not listening on any port that I specify | 37,621,193 | <p>I'm performing a <a href="https://pymotw.com/2/socket/tcp.html" rel="nofollow">simple Python socket tutorial.</a> I initialize the socket using
</p>
<pre><code>import socket
import sys
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to the port
server = socket.ge... | 1 | 2016-06-03T18:27:32Z | 37,621,308 | <p>As SergeyA and kindall mentioned, you forgot to bind your socket. Add</p>
<pre><code>sock.bind(server_address)
</code></pre>
<p>to the bottom of your program to bind your socket to a specific port.</p>
| 1 | 2016-06-03T18:36:01Z | [
"python",
"sockets",
"server",
"port"
] |
Python not listening on any port that I specify | 37,621,193 | <p>I'm performing a <a href="https://pymotw.com/2/socket/tcp.html" rel="nofollow">simple Python socket tutorial.</a> I initialize the socket using
</p>
<pre><code>import socket
import sys
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to the port
server = socket.ge... | 1 | 2016-06-03T18:27:32Z | 37,621,571 | <p>The actual bind part is only present in your comments, but not your code. Call <a href="https://docs.python.org/dev/library/socket.html#socket.socket.bind" rel="nofollow"><code>bind</code></a>:</p>
<pre><code>sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 8080
sock.bind(('', port)) # actually bind
... | 4 | 2016-06-03T18:54:35Z | [
"python",
"sockets",
"server",
"port"
] |
Overlap legends in matplotlib | 37,621,273 | <p>I'm making a linear regression and plotting the data points as well as the regression line.</p>
<p>The code I'm making it this way:</p>
<pre><code>x = np.r_[0.,3.15,5.39,7.29,11.55,14.4,19.8,23.4,25.7]
y = np.r_[0,0.13,0.2,0.27,0.42, 0.51,0.68,0.80,0.88]
model = linear_model.LinearRegression()
X = x.reshape(-1,1)
... | 2 | 2016-06-03T18:33:41Z | 37,622,468 | <p>The following seems to work:</p>
<pre><code>import matplotlib.pyplot as plt
from sklearn import linear_model
# Funky hack to change the number of "stars" in the legend to be 1,
# I feel like there has to be a better way to do this...
from pylab import *
rcParams['legend.numpoints'] = 1
x = np.r_[0.,3.15,5.39,7.29... | 2 | 2016-06-03T20:00:26Z | [
"python",
"matplotlib"
] |
Error with feed values for placeholders when running the merged summary op | 37,621,340 | <p>I'm new to tensorflow and try to learn how to visualize with tensorboard. I have the following code for a neural network with one hidden layer. When I tried to run the code in my jupyter notebook, it gave me the error like this:</p>
<p>StatusNotOK Traceback (most recent call last)
Stat... | 0 | 2016-06-03T18:38:19Z | 37,624,635 | <p>Following the discussion in the comments, I think the merged summary <code>merged = tf.merge_all_summaries()</code> is taking into account previous summaries (coming from I don't know where), which depend on placeholders not initialized.</p>
<p>The quickest way to fix that (apart from finding and removing these pre... | 2 | 2016-06-03T23:02:42Z | [
"python",
"tensorflow"
] |
Enumerating keys in Django Database Cache | 37,621,392 | <p>I'm caching some calculation results in a Django application using Django Database Cache (<a href="https://docs.djangoproject.com/en/1.8/topics/cache/#database-caching" rel="nofollow">https://docs.djangoproject.com/en/1.8/topics/cache/#database-caching</a>).</p>
<p>What is the way to enumerate all keys stored in th... | 2 | 2016-06-03T18:41:54Z | 37,624,215 | <p>Django's cache API doesn't offer what you are looking for, so none of the implementations will either. One solution would be to create your own backend. </p>
<p>You're still going to have to muck around some SQL queries, but you can subclass <a href="https://github.com/django/django/blob/master/django/core/cache/ba... | 1 | 2016-06-03T22:13:42Z | [
"python",
"django",
"caching",
"django-1.8"
] |
Enumerating keys in Django Database Cache | 37,621,392 | <p>I'm caching some calculation results in a Django application using Django Database Cache (<a href="https://docs.djangoproject.com/en/1.8/topics/cache/#database-caching" rel="nofollow">https://docs.djangoproject.com/en/1.8/topics/cache/#database-caching</a>).</p>
<p>What is the way to enumerate all keys stored in th... | 2 | 2016-06-03T18:41:54Z | 37,626,919 | <p>Assuming you are using MySQL as your DB backend this sub class of the DatabaseCache should work to return a dictionary of all the results from a LIKE type query on cache keys.</p>
<pre><code>class DatabaseCacheExtended(DatabaseCache):
def get_where(self, query, default=None, version=None):
db = router.d... | 1 | 2016-06-04T06:00:17Z | [
"python",
"django",
"caching",
"django-1.8"
] |
How do I keep previous data sets when plotting in a loop? | 37,621,418 | <p>I have data segments that I am loading in a loop and then plotting on a graph, and I want new data segments to be plotted over the previous segments, so that when I'm finished, all the data will be plotted on one graph. I've included the plotting segment below, and it currently just make 22 different plots for the 2... | 0 | 2016-06-03T18:43:23Z | 37,621,910 | <p>Assuming this is all inside a single loop, just don't call <code>fig = pl.figure()</code> every time. That is the process which is creating a new figure. When you call any plot commands, it will automatically plot to the figure in focus, which is always going to be the most recently created figure. You probably want... | 1 | 2016-06-03T19:18:14Z | [
"python",
"matplotlib"
] |
How to create custom classes that inherit from sqlalchemy models in external library | 37,621,423 | <p>Rather than creating mixin classes that models inherit from, I have a use case that requires me to configure classes the other way around. The classes that would normally be mixin classes need to be the classes that inherit from the models as well as the class that model objects are created from. This is because the... | 0 | 2016-06-03T18:43:40Z | 37,623,638 | <p>There are three problems here:</p>
<ol>
<li>When you write <code>foo_bar = relationship(FooBar, backref=backref("foos"))</code> the <code>FooBar</code> needs to refer to the subclass <code>FooBar</code>, not the <code>BaseFooBar</code>.</li>
<li><code>Bar</code> needs to inherit from <code>Foo</code> for the inheri... | 2 | 2016-06-03T21:23:04Z | [
"python",
"inheritance",
"sqlalchemy",
"polymorphism"
] |
pandas combining dataframe | 37,621,521 | <pre><code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pickle
java = pickle.load(open('JavaSafe.p','rb')) ##import 2d array
python = pickle.load(open('PythonSafe.p','rb')) ##import 2d array
javaFrame = pd.DataFrame(java,columns=['Town','Java Jobs'])
pythonFrame = pd.DataFrame(python,... | 2 | 2016-06-03T18:50:21Z | 37,621,594 | <pre><code>import pandas as pd
javaFrame = pd.DataFrame({'Java Jobs': [3593, 3585, 2080, 1920, 1571, 5, 5, 5, 5, 5],
'Town': ['York,NY', 'NewYork,NY', 'Seattle,WA', 'Chicago,IL', 'Boston,MA', 'Holland,MI', 'Manhattan,KS', 'Vernon,IL', 'Clayton,MO', 'Waukegan,IL']}, index=[435, 212, 584, 624, 301, 79, 38, 497, 30,... | 3 | 2016-06-03T18:55:48Z | [
"python",
"pandas"
] |
pandas combining dataframe | 37,621,521 | <pre><code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pickle
java = pickle.load(open('JavaSafe.p','rb')) ##import 2d array
python = pickle.load(open('PythonSafe.p','rb')) ##import 2d array
javaFrame = pd.DataFrame(java,columns=['Town','Java Jobs'])
pythonFrame = pd.DataFrame(python,... | 2 | 2016-06-03T18:50:21Z | 37,624,810 | <p>Use <code>pd.concat</code></p>
<pre><code>df = pd.concat([df.set_index('Town') for df in [javaFrame, pythonFrame]], axis=1)
Java Jobs Python Jobs
Boston,MA 1571.0 1117.0
Bulverde,TX NaN 5.0
Chicago,IL 1920.0 1312.0
Clayton,MO 5.0 NaN
Hanove... | 1 | 2016-06-03T23:25:17Z | [
"python",
"pandas"
] |
Recursive function is not defined inside itself | 37,621,623 | <p>I'm trying to write a program to solve the <a href="https://en.wikipedia.org/wiki/Eight_queens_puzzle" rel="nofollow">N Queens Puzzle</a>. I'm getting the error <code>name 'FindPosition' is not defined</code> when the code tries to call <code>FindPosition(finalArray, startArray)</code> recursively. How do I properly... | 0 | 2016-06-03T18:57:41Z | 37,621,672 | <p><code>FindPosition</code> is a method of the class <code>TheQueensAlgoritm</code> and does not exist by itself. You need to use:</p>
<pre><code>self.FindPosition(finalArray, startArray)
</code></pre>
| 0 | 2016-06-03T19:00:35Z | [
"python",
"recursion",
"nameerror"
] |
Returning database result arrays from database in python & flask | 37,621,749 | <p>I have this code I'm looking wondering about in an object. I pass itself to be sure scope is good.</p>
<pre><code>def myList(self):
results = []
self.c.execute('SELECT id,lister FROM listers ORDER BY lister')
for row in self.c.fetchall():
results.append({'id':row[0],'lister':row[1]})
return... | -1 | 2016-06-03T19:06:14Z | 37,660,097 | <p>@Morgan-Thrapp reminded me that directly returning the query would make it read only. Which is a disadvantage in some cases & does not matter in other cases.</p>
| 0 | 2016-06-06T14:30:50Z | [
"python",
"arrays",
"list",
"flask",
"return"
] |
How to pass list of RDDs to groupWith in Pyspark | 37,621,853 | <p>I am trying to pass a list of RDDs to groupWith instead of manually specifying them by index.</p>
<p>Here is the sample data</p>
<pre><code>w = sc.parallelize([("1", 5), ("3", 6)])
x = sc.parallelize([("1", 1), ("3", 4)])
y = sc.parallelize([("2", 2), ("4", 3)])
z = sc.parallelize([("2", 42), ("4", 43), ("5", 12)]... | 0 | 2016-06-03T19:14:52Z | 37,628,679 | <p>Since <code>groupWith</code> accepts varargs all you have to do is to unpack arguments:</p>
<pre><code>w.groupWith(*m[1:])
</code></pre>
| 0 | 2016-06-04T09:35:38Z | [
"python",
"apache-spark",
"pyspark",
"rdd"
] |
Seemingly quick filter field-lookup is slow | 37,621,933 | <p>My rough model:</p>
<pre><code>class m_Interaction(models.Model):
fk_ip = models.ForeignKey('m_IP', on_delete=models.SET_NULL, null=True, related_name="interactions")
fk_query = models.ForeignKey('m_Query', on_delete=models.SET_NULL, null=True, related_name="interactions")
</code></pre>
<p>Database used: S... | 1 | 2016-06-03T19:19:45Z | 37,629,500 | <p>The trouble with sqlite and mysql is that they can use only one index per table as mentioned at <a href="https://www.sqlite.org/optoverview.html" rel="nofollow">https://www.sqlite.org/optoverview.html</a></p>
<blockquote>
<p>Each table in the FROM clause of a query can use at most one index
(except when the OR-... | 1 | 2016-06-04T11:13:11Z | [
"python",
"django",
"sqlite",
"django-queryset",
"django-filter"
] |
GAE - Setting VM to true and shared libraries altogether | 37,621,987 | <p>I've been trying to use MySql when VM true flag is setted to true on my app.yaml</p>
<p>but this error is thrown: appcfg.py: error: Error parsing src/app.yaml: The "libraries:" directive has been deprecated for Managed VMs. Please delete this section from your app.yaml, use pip (<a href="https://pip.pypa.io/" rel="... | 1 | 2016-06-03T19:24:21Z | 37,623,437 | <p>If you're working with flexible environments (previously called Managed Virtual Machines) then you can't use the "libraries" directive in your app.yaml in order to activate third party libraries. Instead of that you should use pip to install your dependencies. From <a href="https://cloud.google.com/appengine/docs/fl... | 2 | 2016-06-03T21:08:00Z | [
"python",
"google-app-engine",
"virtual-machine"
] |
How to sort key names in ipywidgets interactive widgets (slider)? | 37,622,023 | <p>I am trying to make interactive sliders with ipywidgets on jupyter notebook to change the data of a plot when a user changes a slider Widget, which is simple and we can find example codes easily. The problem that I have is twofold: 1) when there are many parameters (= variables,sliders) in my function to be displaye... | 1 | 2016-06-03T19:27:01Z | 37,822,291 | <p>You will not be able to solve this using **kwargs. As stated in <a href="https://www.python.org/dev/peps/pep-0468/" rel="nofollow">PEP468</a>
"The only reason they [keyword arguments] don't work is because the interpreter throws that ordering information away."
"Starting in version 3.5 Python will preserve the order... | 1 | 2016-06-14T21:18:22Z | [
"python",
"jupyter-notebook",
"ipywidgets"
] |
How to add friction in pong by using python? | 37,622,039 | <p>I want to add friction in pong. When the ball hits the paddle and paddle is moving, the ball's speed can be changed and the ball's direction can be also changed. This is my idea. However, I don't know how to specifically do this. I hope my explanation is clear. Here is my code snippet:</p>
<pre><code>def moveDot(su... | 2 | 2016-06-03T19:28:09Z | 37,622,081 | <p>The original pong game use a system of detection of the collision point. If the ball collides the paddle, it will be moved toward 45° and it will be less if the ball hits the side of the paddle.
So, the relation between the input and the output incidence is <strong>a function of the collision point</strong> (you c... | 1 | 2016-06-03T19:31:18Z | [
"python",
"python-3.x",
"pygame",
"pong"
] |
How to add friction in pong by using python? | 37,622,039 | <p>I want to add friction in pong. When the ball hits the paddle and paddle is moving, the ball's speed can be changed and the ball's direction can be also changed. This is my idea. However, I don't know how to specifically do this. I hope my explanation is clear. Here is my code snippet:</p>
<pre><code>def moveDot(su... | 2 | 2016-06-03T19:28:09Z | 37,622,156 | <p>You'll want to convey some portion of the paddle's velocity to the ball's y velocity, the portion being expressed as a coefficient of friction.</p>
<p>Example:</p>
<pre><code>if left_paddle.collidepoint(center) and ball_speed[0] < 0:
ball_speed[0] = -ball_speed[0]
ball_speed[1] += 0.5 * left_paddle.spee... | 1 | 2016-06-03T19:36:24Z | [
"python",
"python-3.x",
"pygame",
"pong"
] |
capture information in a list using bs4 when a table is embedded in the list | 37,622,050 | <p>For this html code, </p>
<pre><code><ul><li>Include these codes as defined in http://unitsofmeasure.org
<table><tr><td><b>Code</b>
</td><td><b>Display</b></td></tr>
<tr><td>min</td><td>Minute<... | 0 | 2016-06-03T19:29:02Z | 37,622,719 | <p>You can use <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#extract" rel="nofollow">extract()</a> to remove the table.</p>
<pre><code>definition = [li.find('table').extract().get_text() for li in ul.findAll("li")]
</code></pre>
| 1 | 2016-06-03T20:18:06Z | [
"python",
"list",
"table",
"beautifulsoup"
] |
capture information in a list using bs4 when a table is embedded in the list | 37,622,050 | <p>For this html code, </p>
<pre><code><ul><li>Include these codes as defined in http://unitsofmeasure.org
<table><tr><td><b>Code</b>
</td><td><b>Display</b></td></tr>
<tr><td>min</td><td>Minute<... | 0 | 2016-06-03T19:29:02Z | 37,623,198 | <p>Try to move up from <strong>table</strong> tag using <strong><em>previousSibling</em></strong>, more info about available methods at <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#method-names" rel="nofollow">https://www.crummy.com/software/BeautifulSoup/bs4/doc/#method-names</a></p>
<pre><code>t =... | 0 | 2016-06-03T20:51:21Z | [
"python",
"list",
"table",
"beautifulsoup"
] |
Django save method called twice? | 37,622,071 | <p>I'm trying to override a save method so that on creation of one model, an instance of the second model is created. However, it looks like the secondary model that I'm trying to create (<code>Restaurant</code> in this example) is being created twice. Why is that?</p>
<p>models.py</p>
<pre><code>class Place(models.M... | 1 | 2016-06-03T19:30:41Z | 37,625,618 | <p>Your save method does not have proper indentation. I assume this was an error in cut and paste. With in that method.</p>
<pre><code>if Restaurant.objects.filter(place=self).count() == 0:
restaurant = Restaurant.objects.create(restaurant=self)
</code></pre>
<p>This is essentially what <a href="https://docs.dja... | 1 | 2016-06-04T01:57:03Z | [
"python",
"django"
] |
How can I scrape and save data in descending order i.e. -created | 37,622,073 | <p>I now have the ability to scrape data and save it to my database. But the problem is, it has the oldest first when I display it. I tried this:</p>
<pre><code>def scrape_and_store_world():
url = 'http://www.worldstarhiphop.com'
html = requests.get(url, headers=headers)
soup = BeautifulSoup(html.text, 'ht... | 1 | 2016-06-03T19:30:56Z | 37,623,813 | <p>Going by the tag on your question, you are using Django. And I'm also assuming that <code>Post</code> is a Django model. If that's correct and you want to define a default ordering when you lookup <code>Post</code> instances, then you have to do it in your model class, by using the <a href="https://docs.djangoprojec... | 0 | 2016-06-03T21:36:05Z | [
"python",
"django",
"database",
"web-scraping",
"beautifulsoup"
] |
How can I scrape and save data in descending order i.e. -created | 37,622,073 | <p>I now have the ability to scrape data and save it to my database. But the problem is, it has the oldest first when I display it. I tried this:</p>
<pre><code>def scrape_and_store_world():
url = 'http://www.worldstarhiphop.com'
html = requests.get(url, headers=headers)
soup = BeautifulSoup(html.text, 'ht... | 1 | 2016-06-03T19:30:56Z | 37,624,453 | <p>The <strong>reversed</strong>() method is what worked. </p>
<pre><code>reverse()
</code></pre>
<p>doesn't iterate</p>
<p>so my code went from this</p>
<pre><code>def scrape_and_store_world():
url = 'http://www.worldstarhiphop.com'
html = requests.get(url, headers=headers)
soup = BeautifulSoup(html.t... | 0 | 2016-06-03T22:41:13Z | [
"python",
"django",
"database",
"web-scraping",
"beautifulsoup"
] |
Creating folders by checking numbers at beginning of a string with python | 37,622,096 | <p>I have a list of strings which contains files like below</p>
<pre><code>filename = [ '000101 FL - Project Title Page.DOC',
'014200 FL - References.DOC',
'095446 FL - Fabric-Wrapped Ceiling Panels.DOC',
'142113 FL - ELECTRIC TRACTION FREIGHT ELEVATORS.DOC']
</code></pre>
<p>I want to check if a folder with a nam... | 2 | 2016-06-03T19:32:11Z | 37,622,168 | <p>Use <a href="https://docs.python.org/2/library/os.html#os.mkdir" rel="nofollow"><code>os.mkdir</code></a> to create a directory and <a href="https://docs.python.org/2/library/shutil.html#shutil.copy2" rel="nofollow"><code>shutil.copy2</code></a> to copy a file,</p>
<pre><code>import os
import shutil
filenames = [ ... | 1 | 2016-06-03T19:37:32Z | [
"python",
"folder"
] |
Creating folders by checking numbers at beginning of a string with python | 37,622,096 | <p>I have a list of strings which contains files like below</p>
<pre><code>filename = [ '000101 FL - Project Title Page.DOC',
'014200 FL - References.DOC',
'095446 FL - Fabric-Wrapped Ceiling Panels.DOC',
'142113 FL - ELECTRIC TRACTION FREIGHT ELEVATORS.DOC']
</code></pre>
<p>I want to check if a folder with a nam... | 2 | 2016-06-03T19:32:11Z | 37,622,201 | <p>You can just check if there is a folder and make it if it does not exist</p>
<pre><code>if not os.path.exists(dirName):
os.makedirs(dirName)
</code></pre>
| 1 | 2016-06-03T19:39:47Z | [
"python",
"folder"
] |
Creating folders by checking numbers at beginning of a string with python | 37,622,096 | <p>I have a list of strings which contains files like below</p>
<pre><code>filename = [ '000101 FL - Project Title Page.DOC',
'014200 FL - References.DOC',
'095446 FL - Fabric-Wrapped Ceiling Panels.DOC',
'142113 FL - ELECTRIC TRACTION FREIGHT ELEVATORS.DOC']
</code></pre>
<p>I want to check if a folder with a nam... | 2 | 2016-06-03T19:32:11Z | 37,622,314 | <p>Try something like this:</p>
<pre><code>import os
import shutil
for file in filenames
dir_name = "Div%s" % file[0:2]
if not os.path.isdir(dir_name)
os.makedirs(dir_name)
shutil.copy(file, dir_name)
</code></pre>
| 0 | 2016-06-03T19:48:46Z | [
"python",
"folder"
] |
LLDB: silently continue after python script is done executing | 37,622,150 | <p>I've written a python script that I am attaching to a watchpoint in LLDB, such as:</p>
<pre><code>def wpCallback(frame, wp, internal_dict):
...
</code></pre>
<p>and I am attaching the callback with:</p>
<pre><code>watchpoint command add -F commands.wpCallback watchpointID
</code></pre>
<p>I would like execut... | 1 | 2016-06-03T19:36:07Z | 37,735,183 | <p>You should be able to call SBProcess.Continue() on your process in your watchpoint callback. I.e. if you called the first argument to your callback <code>frame</code> do:</p>
<pre><code>frame.thread.process.Continue()
</code></pre>
<p>That works for breakpoints, but seems to be broken for watchpoints in current T... | 1 | 2016-06-09T20:03:31Z | [
"python",
"debugging",
"lldb"
] |
How to get all intersections of sets in python fast | 37,622,153 | <p>I would like to compute all (different) intersections of a collection of finite sets of integers (here implemented as a list of lists) in python (to avoid confusion, a formal definition is at the end of the question):</p>
<pre><code>> A = [[0,1,2,3],[0,1,4],[1,2,4],[2,3,4],[0,3,4]]
> all_intersections(A) # de... | 4 | 2016-06-03T19:36:14Z | 37,622,892 | <p>Here is a recursive solution. It is almost instantaneous on your test example:</p>
<pre><code>def allIntersections(frozenSets):
if len(frozenSets) == 0:
return []
else:
head = frozenSets[0]
tail = frozenSets[1:]
tailIntersections = allIntersections(tail)
newIntersecti... | 5 | 2016-06-03T20:31:23Z | [
"python",
"algorithm"
] |
How to get all intersections of sets in python fast | 37,622,153 | <p>I would like to compute all (different) intersections of a collection of finite sets of integers (here implemented as a list of lists) in python (to avoid confusion, a formal definition is at the end of the question):</p>
<pre><code>> A = [[0,1,2,3],[0,1,4],[1,2,4],[2,3,4],[0,3,4]]
> all_intersections(A) # de... | 4 | 2016-06-03T19:36:14Z | 37,623,627 | <p>Iterative solution that takes about 3.5 ms on my machine for your large test input:</p>
<pre><code>from itertools import starmap, product
from operator import and_
def all_intersections(sets):
# Convert to set of frozensets for uniquification/type correctness
last = new = sets = set(map(frozenset, sets))
... | 2 | 2016-06-03T21:22:27Z | [
"python",
"algorithm"
] |
While loop in Python not working out | 37,622,169 | <p>So I just started out with python recently and I tried using a while loop in the code but when I click run, the program just runs forever without printing anything. I did some research on while loops but I didn't find anything that would help me. Here is the code in its entirety:</p>
<pre><code>import random
Hero... | 0 | 2016-06-03T19:37:40Z | 37,622,257 | <p>In Python the assignment operation does not work that way. </p>
<p>It looks like when you write:</p>
<pre><code>if WitchHP > 0:
WitchStatus = Alive
</code></pre>
<p>You think that using <code>WitchStatus</code> in a future condition it will actually check the value of <code>WitchHP</code>. But that's n... | 2 | 2016-06-03T19:44:23Z | [
"python",
"variables",
"if-statement",
"while-loop"
] |
While loop in Python not working out | 37,622,169 | <p>So I just started out with python recently and I tried using a while loop in the code but when I click run, the program just runs forever without printing anything. I did some research on while loops but I didn't find anything that would help me. Here is the code in its entirety:</p>
<pre><code>import random
Hero... | 0 | 2016-06-03T19:37:40Z | 37,622,296 | <p>Change this:</p>
<pre><code>while WitchStatus == Alive and HeroStatus == Alive:
WitchHP = WitchHP - HeroATK
HeroHP = HeroHP - WitchATK
</code></pre>
<p>To an if statement:</p>
<pre><code>if WitchStatus == Alive.....
</code></pre>
<p>In the original, once WitchStatus == Alive, it will remain that way... | 0 | 2016-06-03T19:47:02Z | [
"python",
"variables",
"if-statement",
"while-loop"
] |
Convert list of list into one big list python | 37,622,180 | <p>I have a list like:</p>
<pre><code>list1 = [1 2 1 ... 1 399]
</code></pre>
<p>And another one:</p>
<pre><code>list2 = [5 4 3 4 2 0]
</code></pre>
<p>list1 has numbers from <code>0 to 399</code>, with duplicates and its length is <code>5000</code>, <code>list2</code> has length of <code>400</code>, the ind... | 2 | 2016-06-03T19:38:25Z | 37,622,336 | <p>You need to index into list2, based on the value in list1, for each value of list1. You can build this from a for-loop:</p>
<pre><code>new_list = []
for k in list1:
new_list.append(list2[k]) #lookup the value in list2 at the index given by list1
</code></pre>
<p>This is more Pythonically expressed with a list co... | 3 | 2016-06-03T19:50:09Z | [
"python",
"list",
"enumeration"
] |
Convert list of list into one big list python | 37,622,180 | <p>I have a list like:</p>
<pre><code>list1 = [1 2 1 ... 1 399]
</code></pre>
<p>And another one:</p>
<pre><code>list2 = [5 4 3 4 2 0]
</code></pre>
<p>list1 has numbers from <code>0 to 399</code>, with duplicates and its length is <code>5000</code>, <code>list2</code> has length of <code>400</code>, the ind... | 2 | 2016-06-03T19:38:25Z | 37,622,390 | <p>list comprehension.</p>
<pre><code>n_l = [list2[i] for i in list1]
</code></pre>
| 2 | 2016-06-03T19:54:30Z | [
"python",
"list",
"enumeration"
] |
Convert list of list into one big list python | 37,622,180 | <p>I have a list like:</p>
<pre><code>list1 = [1 2 1 ... 1 399]
</code></pre>
<p>And another one:</p>
<pre><code>list2 = [5 4 3 4 2 0]
</code></pre>
<p>list1 has numbers from <code>0 to 399</code>, with duplicates and its length is <code>5000</code>, <code>list2</code> has length of <code>400</code>, the ind... | 2 | 2016-06-03T19:38:25Z | 37,622,411 | <p>one of very fast and efficient solutions would be using of numpy module:</p>
<pre><code>In [46]: a1[l2]
Out[46]: array([4, 3, 1, 1, 1, 2])
</code></pre>
<p>setup:</p>
<pre><code>import numpy as np
l1 = [1,2,1,1,3,4,5,6,7,8,5,7,8,9]
l2 = [5,4,3,2,0,1]
a1 = np.array(l1)
</code></pre>
| 0 | 2016-06-03T19:56:04Z | [
"python",
"list",
"enumeration"
] |
Convert list of list into one big list python | 37,622,180 | <p>I have a list like:</p>
<pre><code>list1 = [1 2 1 ... 1 399]
</code></pre>
<p>And another one:</p>
<pre><code>list2 = [5 4 3 4 2 0]
</code></pre>
<p>list1 has numbers from <code>0 to 399</code>, with duplicates and its length is <code>5000</code>, <code>list2</code> has length of <code>400</code>, the ind... | 2 | 2016-06-03T19:38:25Z | 37,622,470 | <p>Build a dictionary from the index of the list2 item to the item itedelf and then pass the list 1 item through the dictionary:</p>
<pre><code>new_dict={}
for i,v in enumerate(list2):
new_dict[i]=v
new_list=[]
for i in list1:
new_list.append(new_dict[i])
print new_list
</code></pre>
| -1 | 2016-06-03T20:00:31Z | [
"python",
"list",
"enumeration"
] |
post_save.disconnect does not work at all | 37,622,183 | <p>I'm trying to make Django not to send signal in one case. When adding a new instance of model <code>Delivery</code> (right after creating a <code>Job</code>) as an attribute of model <code>Job</code>, I don't want to send signal because the signal should alert admin that <code>Job</code> has been edited. </p>
<p>Un... | 1 | 2016-06-03T19:38:28Z | 37,625,586 | <p>The problem is that you are listening to the same signal twice.</p>
<pre><code>@receiver(post_save,sender=Job) # When Job is created or edited
def alert_admin(sender,instance,created,**kwargs):
###
@receiver(post_save,sender=Job):
def create_delivery(sender,instance,created,**kwargs):
###
</code></pre>
<p>... | 1 | 2016-06-04T01:49:39Z | [
"python",
"django",
"django-models",
"django-signals"
] |
Why am I unable to connect to a mysql database using python and mysql.connector? | 37,622,192 | <p>I am trying to connect to a mysql database, but having issues. I am trying to use mysql connector (not sure if this is the most efficient library to use), but I am having an error.</p>
<p>Here is my basic script:</p>
<pre><code>import mysql.connector
def test_sql_query():
db = mysql.connector.connect(host='h... | 1 | 2016-06-03T19:39:16Z | 37,622,310 | <p>The parameter you are passing to <a href="https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html" rel="nofollow"><code>.connect()</code></a> is wrong. You are passing a string. Instead, each of those should be their own parameter.</p>
<pre><code>db = mysql.connector.connect(host='hos... | 1 | 2016-06-03T19:48:22Z | [
"python",
"mysql"
] |
Why am I unable to connect to a mysql database using python and mysql.connector? | 37,622,192 | <p>I am trying to connect to a mysql database, but having issues. I am trying to use mysql connector (not sure if this is the most efficient library to use), but I am having an error.</p>
<p>Here is my basic script:</p>
<pre><code>import mysql.connector
def test_sql_query():
db = mysql.connector.connect(host='h... | 1 | 2016-06-03T19:39:16Z | 37,622,311 | <p>You have the format of the connect incorrect, putting all of the variables inside of quotes makes the method treat it as a single, string input to the method.</p>
<pre><code>db = mysql.connector.connect("host='hostname' database='db' user='dbuser' password='dbpass' port='000'")
</code></pre>
<p>should be</p>
<pre... | 0 | 2016-06-03T19:48:23Z | [
"python",
"mysql"
] |
massive process on python with Pyserial | 37,622,365 | <p>I'm using Pyserial in a program to make a serial interface with RS232. And It already works, but the problem is My device, slave can comunicate any time and to solve that on my code I used</p>
<pre><code>while(ser.inWaiting() == 0):
#wait for some input the read it
ser.readline()
</code></pre>
<p>The pro... | 2 | 2016-06-03T19:52:09Z | 37,623,602 | <p>You can use threads. Here is a very simple example:</p>
<pre><code>#!/usr/bin/env python
import threading
import time
import sys
from subprocess import Popen, PIPE
import os
running = False
def Task1():
time.sleep(5)
count = 0
while running:
count += 1
print "Task1 - count is", count
time.sle... | 0 | 2016-06-03T21:20:56Z | [
"python",
"pyserial"
] |
massive process on python with Pyserial | 37,622,365 | <p>I'm using Pyserial in a program to make a serial interface with RS232. And It already works, but the problem is My device, slave can comunicate any time and to solve that on my code I used</p>
<pre><code>while(ser.inWaiting() == 0):
#wait for some input the read it
ser.readline()
</code></pre>
<p>The pro... | 2 | 2016-06-03T19:52:09Z | 37,623,902 | <p>In my experience, PySerial is too heavy to transfer big streams of data. You're better of dropping abstractions and using plain syscalls. </p>
<p>In my application, transmitting at 50 kilobauds with PySerial used 70-80% of a i5-3550 core. Later, the same application rewritten in C using plain <code>tcsetattr()</cod... | 0 | 2016-06-03T21:43:32Z | [
"python",
"pyserial"
] |
How to multiply integers in list with constant and overwrite list value | 37,622,378 | <p>I have a very basic problem. How can I multiply integers within a list with a constant? If the integer in the list passes a logical test, I want it's value to be multiplied by a constant. The problem is that when I print the list afterwards, the integers have not changed. Many thanks in advance. </p>
<pre><code>x =... | 1 | 2016-06-03T19:53:34Z | 37,622,397 | <p>You could use a list comprehension to do this</p>
<pre><code>>>> x = [10,25,66]
>>> x = [i*2 if i%5==0 else i for i in x]
>>> x
[20, 50, 66]
</code></pre>
| 3 | 2016-06-03T19:55:06Z | [
"python",
"list",
"for-loop",
"integer"
] |
How to multiply integers in list with constant and overwrite list value | 37,622,378 | <p>I have a very basic problem. How can I multiply integers within a list with a constant? If the integer in the list passes a logical test, I want it's value to be multiplied by a constant. The problem is that when I print the list afterwards, the integers have not changed. Many thanks in advance. </p>
<pre><code>x =... | 1 | 2016-06-03T19:53:34Z | 37,622,509 | <p>You can modify the same list by iterating through your list with <code>enumerate</code> and modifying indices that match your condition:</p>
<pre><code>x = [10,25,66]
def multiply(lst):
for index, value in enumerate(lst):
if value % 5 == 0:
lst[index] = value * 2
print lst[index... | 0 | 2016-06-03T20:03:11Z | [
"python",
"list",
"for-loop",
"integer"
] |
How to multiply integers in list with constant and overwrite list value | 37,622,378 | <p>I have a very basic problem. How can I multiply integers within a list with a constant? If the integer in the list passes a logical test, I want it's value to be multiplied by a constant. The problem is that when I print the list afterwards, the integers have not changed. Many thanks in advance. </p>
<pre><code>x =... | 1 | 2016-06-03T19:53:34Z | 37,622,532 | <p>numpy solution:</p>
<pre><code>In [56]: x = np.array([10,25,66])
In [57]: x[x % 5 == 0] *= 2 # solution from @Sven Marnach
In [58]: x
Out[58]: array([20, 50, 66])
</code></pre>
| 0 | 2016-06-03T20:05:27Z | [
"python",
"list",
"for-loop",
"integer"
] |
How to multiply integers in list with constant and overwrite list value | 37,622,378 | <p>I have a very basic problem. How can I multiply integers within a list with a constant? If the integer in the list passes a logical test, I want it's value to be multiplied by a constant. The problem is that when I print the list afterwards, the integers have not changed. Many thanks in advance. </p>
<pre><code>x =... | 1 | 2016-06-03T19:53:34Z | 37,622,535 | <p>well you are multiplying the item itself and not assigning to the list.</p>
<p>This will do it </p>
<pre><code>x = [10,25,66]
def multiply(list):
for i in range(len(list)):
if list[i]%5==0:
list[i] = list[i] * 2
multiply(x)
print x
</code></pre>
<p>So what I changed is that now you are g... | 1 | 2016-06-03T20:05:44Z | [
"python",
"list",
"for-loop",
"integer"
] |
Emulating a mouseclick using PostMessage | 37,622,438 | <p>I am using python's win32 module to create a simple click() method, which should emulate a mouse click, but unfortunately my approach is not working.</p>
<pre><code>def click(x, y):
hWnd = win32gui.FindWindow(None, "SomeWindowTitle")
lParam = win32api.MAKELONG(x, y)
win32gui.PostMessage(hWnd, WM_LBUTTO... | -2 | 2016-06-03T19:58:22Z | 37,624,160 | <p>I got it working now.. The above code is working well, the only thing I was not aware of was that I was getting my cursor position from <code>win32api.GetCursorPos()</code> in screen coordinates, but <code>win32gui.PostMessage()</code> needed the relative coordinates of the hWnd. Simply converting it with <code>Scre... | 0 | 2016-06-03T22:08:09Z | [
"python",
"winapi",
"pywin32"
] |
Finding Django source code based on import | 37,622,462 | <p>I found a package extending the <code>models.BigIntegerField</code> in Django and I'm running into a bug with it, so I'm trying to look at the <code>BigIntegerField</code>'s source code. Unfortunately the package imports <code>from django.db import models</code> and then calls <code>models.BigIntegerField</code>, bu... | 1 | 2016-06-03T20:00:05Z | 37,622,502 | <p>Check django doc about <a href="https://docs.djangoproject.com/en/1.9/ref/models/fields/#bigintegerfield" rel="nofollow"><code>BigIntegerField</code></a>, there's a <code>[source]</code> link beside it, which basically points you to the <a href="https://docs.djangoproject.com/en/1.9/_modules/django/db/models/fields/... | 4 | 2016-06-03T20:02:46Z | [
"python",
"django"
] |
Finding Django source code based on import | 37,622,462 | <p>I found a package extending the <code>models.BigIntegerField</code> in Django and I'm running into a bug with it, so I'm trying to look at the <code>BigIntegerField</code>'s source code. Unfortunately the package imports <code>from django.db import models</code> and then calls <code>models.BigIntegerField</code>, bu... | 1 | 2016-06-03T20:00:05Z | 37,622,560 | <p>You can search github repo, for example for a <a href="https://github.com/django/django/search?utf8=%E2%9C%93&q=%22class+BigIntegerField%22&type=Code" rel="nofollow">class definition</a>.</p>
<p>When importing <code>models</code> Python looks for a file named <code>models.py</code> or for a <code>models/__i... | 2 | 2016-06-03T20:07:17Z | [
"python",
"django"
] |
python: modify PerceptronTagger in nltk to recognize 'and/or' | 37,622,518 | <p>How can I modify <code>PerceptronTagger</code> in <code>nltk</code> module (or maybe add some temporary functionality to it) so that it recognizes 'and/or' as 'CC' tag?</p>
| 0 | 2016-06-03T20:04:11Z | 37,636,274 | <p>If this is the only thing you want to change, the simplest solution is to just post-process the tagged text:</p>
<pre><code>for sentence in tagged_sentences:
for n, (word,tag) in enumerate(sentence):
if word == 'and/or':
sentence[n] = (word, "CC")
</code></pre>
<p>But if your question is th... | 0 | 2016-06-05T00:20:58Z | [
"python",
"nltk",
"pos-tagger",
"perceptron"
] |
Get number of frames in clip with Moviepy | 37,622,544 | <p>You would think this would be such a simple operation, but there is nothing in the documentation about how to get the number of frames in a video clip. The only way I can think of is to use <code>iter_frames()</code> and just count the frames out one by one, but for some reason it takes almost a full second to itera... | 1 | 2016-06-03T20:06:21Z | 37,622,951 | <p>As it turns out moviepy doesn't save individual frame data, so it doesn't store the exact frame count. Here is the best way I found to get an approximation:</p>
<pre><code>frames = int(clip.fps * clip.duration)
</code></pre>
| 2 | 2016-06-03T20:35:44Z | [
"python",
"python-3.x",
"moviepy"
] |
Get number of frames in clip with Moviepy | 37,622,544 | <p>You would think this would be such a simple operation, but there is nothing in the documentation about how to get the number of frames in a video clip. The only way I can think of is to use <code>iter_frames()</code> and just count the frames out one by one, but for some reason it takes almost a full second to itera... | 1 | 2016-06-03T20:06:21Z | 37,624,498 | <p>Pretty fast for me using this code:</p>
<pre><code>clip = VideoFileClip('test.mp4')
n_frames = sum(1 for x in clip.iter_frames())
print n_frames
</code></pre>
| 1 | 2016-06-03T22:46:58Z | [
"python",
"python-3.x",
"moviepy"
] |
dictionary returns none when there should be a value python | 37,622,551 | <p>I have a small sample dataset:</p>
<pre><code>import pandas as pd
df = {'ID': ['H576','H577','H578','H600', 'H700'],
'CD': ['AAAAAAA', 'BBBBB', 'CCCCCC','DDDDDD', 'EEEEEEE']}
df = pd.DataFrame(df)
</code></pre>
<p>I read this in with pandas and transform these 2 columns into a dictionary with the 'ID' being t... | 1 | 2016-06-03T20:06:36Z | 37,622,624 | <p>From the docs about dict.pop():</p>
<blockquote>
<p><strong>pop(key[, default])</strong></p>
<p>If key is in the dictionary, remove it and return its value, else return default. If default is not given and key is not in the dictionary, a KeyError is raised.</p>
</blockquote>
<p>If you want to add a key-valu... | 2 | 2016-06-03T20:12:04Z | [
"python",
"dictionary",
"pandas"
] |
dictionary returns none when there should be a value python | 37,622,551 | <p>I have a small sample dataset:</p>
<pre><code>import pandas as pd
df = {'ID': ['H576','H577','H578','H600', 'H700'],
'CD': ['AAAAAAA', 'BBBBB', 'CCCCCC','DDDDDD', 'EEEEEEE']}
df = pd.DataFrame(df)
</code></pre>
<p>I read this in with pandas and transform these 2 columns into a dictionary with the 'ID' being t... | 1 | 2016-06-03T20:06:36Z | 37,622,687 | <p>Why not directly:</p>
<pre><code>reverseDict = {v:k for k,v in dictionary.iteritems()}
In [14]: reverseDict['AAAAAAA']
Out[14]: 'H576'
</code></pre>
| 3 | 2016-06-03T20:15:24Z | [
"python",
"dictionary",
"pandas"
] |
dictionary returns none when there should be a value python | 37,622,551 | <p>I have a small sample dataset:</p>
<pre><code>import pandas as pd
df = {'ID': ['H576','H577','H578','H600', 'H700'],
'CD': ['AAAAAAA', 'BBBBB', 'CCCCCC','DDDDDD', 'EEEEEEE']}
df = pd.DataFrame(df)
</code></pre>
<p>I read this in with pandas and transform these 2 columns into a dictionary with the 'ID' being t... | 1 | 2016-06-03T20:06:36Z | 37,622,698 | <p><code>pop()</code> returns the value for the <code>key</code> passed to it. The second parameter is default value which is returned if <code>key</code> is not present in the dictionary.</p>
<p>You can just do :</p>
<pre><code>reversedic[key] = value
</code></pre>
| 2 | 2016-06-03T20:16:06Z | [
"python",
"dictionary",
"pandas"
] |
dictionary returns none when there should be a value python | 37,622,551 | <p>I have a small sample dataset:</p>
<pre><code>import pandas as pd
df = {'ID': ['H576','H577','H578','H600', 'H700'],
'CD': ['AAAAAAA', 'BBBBB', 'CCCCCC','DDDDDD', 'EEEEEEE']}
df = pd.DataFrame(df)
</code></pre>
<p>I read this in with pandas and transform these 2 columns into a dictionary with the 'ID' being t... | 1 | 2016-06-03T20:06:36Z | 37,622,866 | <p>Since create first Dict this way</p>
<pre><code>dictionary = df.set_index('ID')['CD'].to_dict()
</code></pre>
<p>Why not? </p>
<pre><code>reversedic = df.set_index('CD')['ID'].to_dict()
</code></pre>
<p>Then: </p>
<pre><code>z = reversedic.get('AAAAAAA')
print(z)
</code></pre>
<p>or </p>
<pre><code>z = revers... | 1 | 2016-06-03T20:29:52Z | [
"python",
"dictionary",
"pandas"
] |
How to compute a 95% confidence interval around a continuous signal? | 37,622,610 | <p>I would like to compute and display in python a 95% CI around a continuous signal (voltage values as a function of time). This signal was recorded in the brain of 16 different subjects, and lasts 1300 ms. Sampling rate was 250 Hz (so one datapoint every 4 ms). How can I proceed? </p>
| -2 | 2016-06-03T20:10:59Z | 37,622,834 | <p>Here's a pythonic example of continuous error bar plotting:
<a href="https://tonysyu.github.io/plotting-error-bars.html#.V1HmMPkrJhE" rel="nofollow">https://tonysyu.github.io/plotting-error-bars.html#.V1HmMPkrJhE</a>. The example is for plotting errors, but just replace err with stdev.</p>
<p>Assuming that each sa... | 0 | 2016-06-03T20:27:34Z | [
"python",
"matplotlib",
"signal-processing",
"confidence-interval"
] |
Python - Show delete button only if user owns post | 37,622,715 | <p><strong>EDIT:</strong> Problem solved! Thank you to user limbo for your input. It was not the solution, but led me down right path: my LEFT JOIN was showing all null posts! I have also included the if-defined check, as a good back-up check. </p>
<p><strong>Goal:</strong> On a message post dashboard, only show del... | 5 | 2016-06-03T20:17:46Z | 37,622,975 | <p>I think what you need to do is check if the messages are real before displaying them. </p>
<p>Assuming you are using jinja2 you need to insert this <code>{% if messages is defined %}</code> before <code>{% for message in messages: %}</code> to check that the messages collection is not empty. </p>
<p>Of course d... | 0 | 2016-06-03T20:36:51Z | [
"python",
"mysql",
"button"
] |
Getting "not supported calendar message.ics" attachment with outlook email invite from Python | 37,622,750 | <p>Trying to write a python script to send an outlook email invite. Used instructions from here: <a href="http://www.baryudin.com/blog/sending-outlook-appointments-python.html" rel="nofollow">http://www.baryudin.com/blog/sending-outlook-appointments-python.html</a>
However, I keep getting a "not supported calendar mess... | 2 | 2016-06-03T20:21:27Z | 37,688,820 | <p>Ok figured out the problem I think. It only understands utc timezone. So if I changed the start and end datetimes to the following then the I get a proper calendar invite.</p>
<pre><code> start_dt = datetime(2016, 6, 3, 17, 0, 0, tzinfo=pytz.utc)
end_dt = datetime(2016, 6, 3, 18, 0, 0, tzinfo=pytz.utc)
</cod... | 0 | 2016-06-07T20:34:01Z | [
"python",
"email",
"outlook",
"icalendar"
] |
Group a List of Tuples by an identical tuple (timestamp) with pyhton itertools | 37,622,831 | <p>I got the following un-normalized list of tuples as result from a SQL-query. </p>
<pre><code>data = [(...) {u'timestamp': datetime.datetime(2016, 5, 25, 23, 55, 33), u'sensor': u'GP_PRES', u'value': u'96587'}, {u'timestamp': datetime.datetime(2016, 5, 25, 23, 56, 33), u'sensor': u'GP_NO2', u'value': u'0.221'}, {u... | 1 | 2016-06-03T20:27:14Z | 37,622,864 | <p>In your code, <code>operator.attrgetter('timestamp')</code> raises the error <code>AttributeError: 'dict' object has no attribute 'timestamp'</code>. </p>
<p>Replace it with <code>key=lambda d:d['timestamp']</code>, as shown below.</p>
<pre><code>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools
imp... | 1 | 2016-06-03T20:29:31Z | [
"python",
"mysql",
"collections",
"iterator"
] |
Can you use Popen and walk together in a loop in Python? | 37,622,906 | <p>I am trying to compress files in a directory and its sub-directories using an executable file compressor (7-Zip). I've set up a loop that automates the process, and the code does not produce any errors. However, it does not seem to compress anything. What I have written is:</p>
<pre><code>import subprocess, os
pat... | 0 | 2016-06-03T20:32:37Z | 37,623,984 | <p>You're not supplying the directory name of the file when you pass it to <code>7z.exe</code>, so it's looking for the file in the current directory. Use <code>os.path.join()</code> to combine the directory with the filename.</p>
<pre><code>p = subprocess.call(['C:\\Program Files (x86)\\7-Zip\\7z.exe', 'a', '-mx1', '... | 1 | 2016-06-03T21:51:15Z | [
"python",
"python-3.x",
"subprocess",
"os.walk"
] |
Python and BeautifulSoup - trouble specifying fields in a div with <dt> and <dd> tags | 37,622,945 | <p>I'm trying to use python3 and beautifulsoup4 to pull data from an online school listing. Here's how the data variable is defined:</p>
<pre><code>soup = BeautifulSoup(r.content, "html.parser")
g_data = soup.find_all("div", {"class": "school_data"})
</code></pre>
<p>And here's the structure of how each list element... | 2 | 2016-06-03T20:35:27Z | 37,624,629 | <p>If you want all the text from the children inside the <em>dl</em> tags that are siblings of the previous <em>h4 cyan_header</em> you can just extract the child tags from the dls:</p>
<pre><code>h = """<div class="school_data">
<h4 class="cyan_header">Coop Tech<br/></h4>
<dl>
... | 0 | 2016-06-03T23:02:09Z | [
"python",
"beautifulsoup"
] |
Python subprocess arbitrarily split output between files | 37,622,979 | <p>I have a multi-step process. Basically, I need to call subprocess.call (or the equivalent) in a way that it writes stdout to one file (for passing to a next step) and writes both stdout and stderr, properly chronologically interleaved, into another file (for displaying to a user).</p>
<p>I should be able to write ... | 0 | 2016-06-03T20:36:58Z | 37,631,779 | <p>I think what you're trying to do is not a problem you can solve generally for any subprocess that writes to <code>stderr</code> and <code>stdout</code> for any operating system. The fundamental problem is that <code>stdout</code> and <code>stderr</code> are independent at the system level.</p>
<p>Say you have the f... | 0 | 2016-06-04T15:13:06Z | [
"python",
"python-3.x",
"python-3.4"
] |
How to share dictionary between threads using multiprocessing.Pool? | 37,623,016 | <p>I'm trying to share a dictionary between threads of multiprocessing.Pool. However, I'm failed with current implementation. Test code:</p>
<pre><code>#!/usr/bin/env python
import multiprocessing
success_map = {"1": []}
def run_(input):
global success_map
successes = success_map.get(input);
successes.a... | 1 | 2016-06-03T20:39:30Z | 37,623,312 | <p>Multiprocessing uses separate <em>processes</em>, not <em>threads</em>. These processes do not share all memory like threads do.</p>
<p>To <a href="https://docs.python.org/3.5/library/multiprocessing.html#sharing-state-between-processes" rel="nofollow">share data</a> between processes you could use e.g. <code>multi... | 4 | 2016-06-03T20:58:49Z | [
"python",
"python-2.7",
"multiprocessing"
] |
how to sort dictionary keys based on the values inside a list | 37,623,036 | <p>I have a dictionary:</p>
<pre><code>my_dict = {
'key1': [v1,v2,v3],
'key2': [v1,v2,v3],
'key3': [v1,v2,v3]
}
</code></pre>
<p>How can I sort the keys inside the <code>my_dict</code> based on the <code>v3</code> item in the list.?<code>v3</code> is a floating point value.</p>
<p>My solution:
I created ... | -6 | 2016-06-03T20:40:32Z | 37,628,118 | <p>First, I must point out, since you're new to StackOverflow, that you need to make an attempt to solve the problem and show what you've tried. Secondly, <code>dict</code>s in Python don't really have an "order"--a <code>dict</code> is basically just a hash table.</p>
<p>However, a <a href="https://docs.python.org/2/... | 1 | 2016-06-04T08:29:41Z | [
"python",
"sorting",
"dictionary"
] |
Setting a pandas sub dataframe indexed with a MultiIndex | 37,623,160 | <p>I have a <code>pandas.DataFrame</code> with a Multi such as:</p>
<pre><code>In [298]: pd.DataFrame(index=pd.MultiIndex.from_tuples([['a', 1], ['a', 2], ['b', 1], ['b', 3]]), data={'x': 1})
Out[298]:
x
a 1 1
2 1
b 1 1
3 1
</code></pre>
<p>When i want to reassign a sub dataframe ie (<code>df.loc['a']</... | 1 | 2016-06-03T20:48:29Z | 37,623,564 | <p>You can use <code>[[..]]</code> (update the DataFrame rather than the Series):</p>
<pre><code>In [11]: df
Out[11]:
x
a 1 1
2 1
b 1 1
3 1
In [12]: df2 = pd.DataFrame(index=pd.MultiIndex.from_tuples([['a', 1], ['a', 2], ['b', 1], ['b', 3]]), data={'x': 2})
In [13]: df.loc[["a"]] = df2.loc[["a"]]
In [1... | 0 | 2016-06-03T21:18:30Z | [
"python",
"pandas",
"multi-index"
] |
Setting a pandas sub dataframe indexed with a MultiIndex | 37,623,160 | <p>I have a <code>pandas.DataFrame</code> with a Multi such as:</p>
<pre><code>In [298]: pd.DataFrame(index=pd.MultiIndex.from_tuples([['a', 1], ['a', 2], ['b', 1], ['b', 3]]), data={'x': 1})
Out[298]:
x
a 1 1
2 1
b 1 1
3 1
</code></pre>
<p>When i want to reassign a sub dataframe ie (<code>df.loc['a']</... | 1 | 2016-06-03T20:48:29Z | 37,624,729 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/advanced.html#using-slicers" rel="nofollow"><code>pd.IndexSlice</code></a> to represent slices of a <code>pd.MultiIndex</code></p>
<pre><code>df.loc[pd.IndexSlice['a', :], :] = 2
print df
a 1 2
2 2
b 1 1
3 1
</code></pre>
<p>Other examples</... | 0 | 2016-06-03T23:12:57Z | [
"python",
"pandas",
"multi-index"
] |
Subset sum for a list with dict | 37,623,194 | <p>Given <code>aList</code> as:</p>
<pre><code>[
{'name': 'Hailey', 'age': 20, 'id': 48479},
{'name': 'John', 'age': 40, 'id': 18021},
{'name': 'Asger', 'age': 18, 'id': 22281},
]
</code></pre>
<p>and a given target sum as <code>targetSum = 50</code>. </p>
<p>The problem is to look through <code>aList</code> w... | 0 | 2016-06-03T20:50:57Z | 37,623,573 | <p>As your function works for a list, so just extract a list of ages from the list of dicts <code>aList</code>, and then use your function.</p>
<pre><code>list_dicts = [{'name': 'Hailey', 'age': 20, 'id': 48479},
{'name': 'John', 'age': 40, 'id': 18021},
{'name': 'Asger', 'age': 18, 'id': 2... | 0 | 2016-06-03T21:19:11Z | [
"python",
"list",
"dictionary",
"subset-sum"
] |
Subset sum for a list with dict | 37,623,194 | <p>Given <code>aList</code> as:</p>
<pre><code>[
{'name': 'Hailey', 'age': 20, 'id': 48479},
{'name': 'John', 'age': 40, 'id': 18021},
{'name': 'Asger', 'age': 18, 'id': 22281},
]
</code></pre>
<p>and a given target sum as <code>targetSum = 50</code>. </p>
<p>The problem is to look through <code>aList</code> w... | 0 | 2016-06-03T20:50:57Z | 37,623,696 | <p>Your code will work as is, since aList is still a list. You just need to change the if condition to</p>
<pre><code> if sum(val['age'] for val in combo) == target:
</code></pre>
<p>This way your 'results' variable will consist of all combinations of the dictionary elements from aList for which age sums up to the ... | 2 | 2016-06-03T21:27:02Z | [
"python",
"list",
"dictionary",
"subset-sum"
] |
Unable to import caffe | 37,623,259 | <p>I executed <code>make pycaffe</code> in the caffe directory and it worked fine. I also did this:</p>
<pre><code>gsamaras@gsamaras-A15:~/caffe/python$ export PYTHONPATH=$PYTHONPATH:/home/gsamaras/caffe/python
</code></pre>
<p>but when I try to import caffe in another project, I get this:</p>
<blockquote>
<p>Impo... | 2 | 2016-06-03T20:55:01Z | 37,624,404 | <p>I had to use <code>sudo apt-get install -U scikit-image</code> after all! The reason is: <a href="http://askubuntu.com/questions/781572/didnt-work-with-pip-but-worked-with-apt-get">Didn't work with pip, but worked with apt-get?</a></p>
| 1 | 2016-06-03T22:36:44Z | [
"python",
"linux",
"scikit-learn",
"deep-learning",
"caffe"
] |
Unable to import caffe | 37,623,259 | <p>I executed <code>make pycaffe</code> in the caffe directory and it worked fine. I also did this:</p>
<pre><code>gsamaras@gsamaras-A15:~/caffe/python$ export PYTHONPATH=$PYTHONPATH:/home/gsamaras/caffe/python
</code></pre>
<p>but when I try to import caffe in another project, I get this:</p>
<blockquote>
<p>Impo... | 2 | 2016-06-03T20:55:01Z | 37,840,881 | <p><code>sudo apt-get install python-skimage</code> worked for me.</p>
| 4 | 2016-06-15T16:26:23Z | [
"python",
"linux",
"scikit-learn",
"deep-learning",
"caffe"
] |
Unable to import caffe | 37,623,259 | <p>I executed <code>make pycaffe</code> in the caffe directory and it worked fine. I also did this:</p>
<pre><code>gsamaras@gsamaras-A15:~/caffe/python$ export PYTHONPATH=$PYTHONPATH:/home/gsamaras/caffe/python
</code></pre>
<p>but when I try to import caffe in another project, I get this:</p>
<blockquote>
<p>Impo... | 2 | 2016-06-03T20:55:01Z | 38,070,294 | <p>I encountered similar error in my caffe installation when I try to import skimage.io. However, when I tried to install the skimage via pip, it fails with the same message posted above.</p>
<p>Then I tried using apt-get to install scikit-image. It finished successfully. Unfortunately, it installed outdated version w... | 1 | 2016-06-28T07:54:29Z | [
"python",
"linux",
"scikit-learn",
"deep-learning",
"caffe"
] |
Python 3.4+ Scripting regarding to Batch Editing JSON and Saving them | 37,623,311 | <p>I'm trying to Batch Edit all JSON files within a folder, and saving each of them as new JSON all at once, instead of doing each one.</p>
<pre><code> def new_json(filename):
with open(filename, 'r+') as f:
json_data = json.load(f)
somefunction()
f.seek(0)
base, ext = os.path.spl... | 0 | 2016-06-03T20:58:48Z | 37,623,386 | <p><a href="https://docs.python.org/2/library/os.html#os.listdir" rel="nofollow"><code>os.listdir</code></a> gives you a list of file <em>names</em>, not file paths. You can use <a href="https://docs.python.org/2/library/os.path.html#module-os.path" rel="nofollow"><code>os.path.join</code></a> to get the full file path... | 0 | 2016-06-03T21:05:23Z | [
"python",
"json",
"batch-file"
] |
Sympy Multi-Dimensional Set | 37,623,319 | <p>Does there exist a concept of a multi-dimensional set?</p>
<p>For example, all real numbers between 0, and 10 can be defined with the set:</p>
<pre><code>ExampleInterval = sympy.Interval(-10, 10)
</code></pre>
<p>What I want a set that describes all the coordinates (x, y, z...) where x is in one interval, y is in... | 2 | 2016-06-03T20:59:34Z | 37,623,658 | <p>From the <a href="http://docs.sympy.org/dev/modules/sets.html" rel="nofollow">Sympy Set documentation</a>, this would be a ProductSet. You could construct one with the ProductSet constructor, or by using the <code>*</code> operator on Intervals:</p>
<pre><code>from sympy import Interval, ProductSet
box = ProductSe... | 3 | 2016-06-03T21:24:27Z | [
"python",
"set",
"sympy"
] |
pure python implementation for calculating percentiles: what is the use of the lambda function here? | 37,623,346 | <p>I have stumbled upon this pure python implementation for calculating percentiles <a href="http://stackoverflow.com/a/2753343/6421279">here</a> and <a href="http://code.activestate.com/recipes/51" rel="nofollow">here</a>:</p>
<pre><code>import math
import functools
def percentile(N, percent, key=lambda x:x):
"""
Fi... | 3 | 2016-06-03T21:02:22Z | 37,623,384 | <p>It's a tie-breaker in case <code>f</code> ever equals <code>c</code>. You haven't come across such a case, so your code never blows up (since <code>key</code> now doesn't exist).</p>
| -4 | 2016-06-03T21:05:11Z | [
"python",
"lambda",
"median",
"percentile"
] |
pure python implementation for calculating percentiles: what is the use of the lambda function here? | 37,623,346 | <p>I have stumbled upon this pure python implementation for calculating percentiles <a href="http://stackoverflow.com/a/2753343/6421279">here</a> and <a href="http://code.activestate.com/recipes/51" rel="nofollow">here</a>:</p>
<pre><code>import math
import functools
def percentile(N, percent, key=lambda x:x):
"""
Fi... | 3 | 2016-06-03T21:02:22Z | 37,623,479 | <p>The answer is right there in the docstring (the string that starts on the line after the <code>def</code> statement):</p>
<pre><code>@parameter key - optional key function to compute value from each element of N.
</code></pre>
<p>This allows you to use a list of something other than numbers. For example, your lamb... | 6 | 2016-06-03T21:10:50Z | [
"python",
"lambda",
"median",
"percentile"
] |
pure python implementation for calculating percentiles: what is the use of the lambda function here? | 37,623,346 | <p>I have stumbled upon this pure python implementation for calculating percentiles <a href="http://stackoverflow.com/a/2753343/6421279">here</a> and <a href="http://code.activestate.com/recipes/51" rel="nofollow">here</a>:</p>
<pre><code>import math
import functools
def percentile(N, percent, key=lambda x:x):
"""
Fi... | 3 | 2016-06-03T21:02:22Z | 37,623,493 | <p>It's right there in the documentation of the function:</p>
<pre><code>@parameter key - optional key function to compute value from each element of N.
</code></pre>
<p>Basically, the <code>percentile</code> function allows the user to <em>optionally</em> pass a key function which will be applied to the elements of ... | 1 | 2016-06-03T21:12:12Z | [
"python",
"lambda",
"median",
"percentile"
] |
Extract specific bytes from a binary file in Python | 37,623,419 | <p>I have very large binary files with x number of int16 data points for y sensors, along with headers with some basic info. The binary file is written as y values for each sample time up to x samples, then another set of readings and so on. If I want all of the data, I am using <code>numpy.fromfile()</code> which work... | 3 | 2016-06-03T21:07:04Z | 37,623,851 | <p>I would definitely try <code>mmap()</code>:</p>
<p><a href="https://docs.python.org/2/library/mmap.html" rel="nofollow">https://docs.python.org/2/library/mmap.html</a></p>
<p>You're reading a lot of small bits which has a lot of <a href="http://stackoverflow.com/questions/23599074/system-calls-overhead">system cal... | 4 | 2016-06-03T21:39:22Z | [
"python",
"numpy",
"mmap",
"seek",
"fromfile"
] |
Calculate mean over values in lines of CSV file if month, week day, and time match a conditon | 37,623,427 | <p>I have a CSV file in this format:</p>
<p><code>date, month, weekday, hour, data
1/1/2016, January, Friday, 0, 0.003333</code></p>
<p>It has 1000s of lines and months range from jan to may, there are 7 week days and 24 values for hours.</p>
<p>Now I want to calculate mean over data values from a ... | 0 | 2016-06-03T21:07:18Z | 37,625,730 | <p>Consider creating a list of all possible combinations, then use it in iteration for row averaging. </p>
<p><strong>Data</strong> N=20 <em>(for illustration, notice first and last two repeat (month/day/hour combination)</em></p>
<pre><code>date month weekday hour data
1/1/2016 January Fri... | 1 | 2016-06-04T02:22:23Z | [
"python",
"python-3.x",
"csv"
] |
numpydoc conventions: method modifies class but returns nothing | 37,623,438 | <p>Question about numpydoc docstring conventions:</p>
<p>I have a class that contains a number of methods that return nothing, but add an attribute to the class. For example:</p>
<pre><code>class MyClass(object):
def __init__(self, a, b):
self.a = a
self.b = b
return
def a_mult(sel... | 0 | 2016-06-03T21:08:15Z | 37,668,577 | <p>Following the helpful suggestions of @mgilson and @user2357112, I realised my classes were poorly designed. I have altered the so all stages of data analysis are stored in a dict. Analysis functions now add elements to the dict, rather than adding new attributes to the class instance.</p>
<p>Thanks for the pointers... | 0 | 2016-06-07T00:02:06Z | [
"python",
"numpy",
"docstring"
] |
How to make a blank video with Moviepy | 37,623,471 | <p>How can I make a completely black video with no sound using moviepy? Preferrably with the size and duration of a base clip, eg 1280x720 and 5 seconds long at 30fps.</p>
| 1 | 2016-06-03T21:10:24Z | 37,624,414 | <p>This is a a way:</p>
<pre><code>from moviepy.editor import *
def color_clip(size, duration, fps=25, color=(0,0,0), output='color.mp4'):
ColorClip(size, color, duration=duration).write_videofile(output, fps=fps)
if __name__ == '__main__':
size = (200, 100)
duration = 5
color_clip(size, duration)
</... | 1 | 2016-06-03T22:37:41Z | [
"python",
"python-3.x",
"moviepy"
] |
when scraping my program halts because unique=True and won't scrape the non duplicates | 37,623,504 | <p>I have a function that scrapes and saves posts to my database.</p>
<pre><code>def scrape_and_store_world():
url = 'http://www.example.org'
html = requests.get(url, headers=headers)
soup = BeautifulSoup(html.text, 'html5lib')
titles = soup.find_all('section', 'box')[:9]
entries = [{'href': url + box.a.get(... | -3 | 2016-06-03T21:13:06Z | 37,625,391 | <p>I figured it out all I had to do was ad an if statement that queries the database to see if there is a matching title and if not then save. heres my code.</p>
<pre><code>def scrape_and_store_world():
url = 'http://www.worldstarhiphop.com'
html = requests.get(url, headers=headers)
soup = BeautifulSoup(html.tex... | 0 | 2016-06-04T01:09:53Z | [
"python",
"database",
"web-scraping",
"beautifulsoup"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.