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 |
|---|---|---|---|---|---|---|---|---|---|
Find personal Dropbox folder path with Python | 38,943,239 | <p>I have found <a href="http://stackoverflow.com/questions/12118162/how-can-i-get-the-dropbox-folder-location-programmatically-in-python">this thread</a>. The answer suggested there works on my Mac, but not my Windows machine.</p>
<p>The last comment on the accepted answer mentions that "The dropbox host.db file does... | 0 | 2016-08-14T14:33:32Z | 38,943,334 | <p>Either install the pip package: <a href="http://ginstrom.com/code/winpaths.html" rel="nofollow">winpaths</a> and then do:</p>
<pre><code>import winpaths
appdata_path = winpaths.get_local_appdata()
</code></pre>
<p>or, do:</p>
<pre><code>import os
appdata_path = os.getenv('LOCALAPPDATA')
</code></pre>
<p>and then... | 2 | 2016-08-14T14:46:20Z | [
"python",
"dropbox"
] |
Conditional List comprehension for tuples when length more than one | 38,943,315 | <p>I have a sentence with tuples which indicate the positions of where there is either a country or a number:</p>
<pre><code>sample = In the first 11 months of 2004 Hong Kong 's international airport at Chek Lap Kok handled daily an average of 592 flights , 92,630 passengers , and more than 7,734 tons of cargo.
</code... | -1 | 2016-08-14T14:44:05Z | 38,944,057 | <p>The code is treating each locationTokenID as a slot, when the locationTokenIDs really represent endpoints of a slice of tokens that should be treated as a slot. So we need to remove the <code>for locationTokenID in locationTokenIDs:</code> loop (which loops over each locationTokenID as if it were a slot), and replac... | 0 | 2016-08-14T16:08:40Z | [
"python",
"list",
"dictionary",
"tuples"
] |
Conditional List comprehension for tuples when length more than one | 38,943,315 | <p>I have a sentence with tuples which indicate the positions of where there is either a country or a number:</p>
<pre><code>sample = In the first 11 months of 2004 Hong Kong 's international airport at Chek Lap Kok handled daily an average of 592 flights , 92,630 passengers , and more than 7,734 tons of cargo.
</code... | -1 | 2016-08-14T14:44:05Z | 38,944,112 | <p>Consider using <code>str.replace()</code> instead of splitting and slicing the sentence string. In order to so do, you need to convert the elements in <code>tokenID2number</code> with thousands separator which as @JonClements comments can be handled with <code>format(int, ',')</code> for Python 2.7+:</p>
<pre><code... | 0 | 2016-08-14T16:16:17Z | [
"python",
"list",
"dictionary",
"tuples"
] |
Conditional List comprehension for tuples when length more than one | 38,943,315 | <p>I have a sentence with tuples which indicate the positions of where there is either a country or a number:</p>
<pre><code>sample = In the first 11 months of 2004 Hong Kong 's international airport at Chek Lap Kok handled daily an average of 592 flights , 92,630 passengers , and more than 7,734 tons of cargo.
</code... | -1 | 2016-08-14T14:44:05Z | 38,950,662 | <p>I have solved my use case but using a roundabout way.</p>
<p>I first allow for slot sentences which contain multiple <code>LOCATION_SLOT</code> or <code>NUMBER_SLOT</code> - if one tuple in the combo contains 2 or more slots, I fill in all:</p>
<pre><code>sentences2location2values = []
for locationTokenIDs, locat... | 0 | 2016-08-15T07:06:16Z | [
"python",
"list",
"dictionary",
"tuples"
] |
Python Rest API - looping through dictionary object | 38,943,339 | <p>Python newbie here</p>
<p>I am querying an API and get a json string like this:</p>
<pre><code>{
"human": [
{
"h": 310,
"prob": 0.9588886499404907,
"w": 457,
"x": 487,
"y": 1053
},
{
"h": 283,
"prob": 0.8738606572151184,
"w": 455,
"x": 1078,
... | 0 | 2016-08-14T14:46:53Z | 38,943,372 | <p>See the following examples:</p>
<pre><code>print json_data['human']
>> [
{
"h": 310,
"prob": 0.9588886499404907,
"w": 457,
"x": 487,
"y": 1053
},
{
"h": 283,
"prob": 0.8738606572151184,
"w": 455,
"x": 1078,
"y": ... | 1 | 2016-08-14T14:50:58Z | [
"python",
"json",
"rest",
"dictionary"
] |
Python Rest API - looping through dictionary object | 38,943,339 | <p>Python newbie here</p>
<p>I am querying an API and get a json string like this:</p>
<pre><code>{
"human": [
{
"h": 310,
"prob": 0.9588886499404907,
"w": 457,
"x": 487,
"y": 1053
},
{
"h": 283,
"prob": 0.8738606572151184,
"w": 455,
"x": 1078,
... | 0 | 2016-08-14T14:46:53Z | 38,943,399 | <p>I think you want to use iteritems to get the keys and values from your dictionary like this:</p>
<pre><code>for k, v in json_data.iteritems():
print "{0} : {1}".format(k, v)
</code></pre>
<p>If you instead meant to traverse the dictionary recursively, try something like this:</p>
<pre><code>def traverse(d):
... | 3 | 2016-08-14T14:54:20Z | [
"python",
"json",
"rest",
"dictionary"
] |
Download files from an FTP server containing given string using python | 38,943,398 | <p>I'm trying to download a large number of files that all share a common string ('DEM') from an ftp sever. These files are nested inside multiple directories. For example, 'Adair>DEM*' and 'Adams>DEM*' </p>
<p>The FTP sever is located here:<a href="ftp://ftp.igsb.uiowa.edu/gis_library/counties/" rel="nofollow">ftp:... | 1 | 2016-08-14T14:53:58Z | 38,943,548 | <p>Ok, seems to work. There may be issues if trying to download a directory, or scan a file. Exception handling may come handy to trap wrong filetypes and skip.</p>
<p><code>glob.glob</code> cannot work since you're on a remote filesystem, but you can use <code>fnmatch</code> to match the names</p>
<p>Here's the code... | 1 | 2016-08-14T15:11:39Z | [
"python",
"ftp",
"file-processing"
] |
Creating new numpy arrays based on condition | 38,943,403 | <p>I have 2 numpy arrays:</p>
<pre><code>aa = np.random.rand(5,5)
bb = np.random.rand(5,5)
</code></pre>
<p>How can I create a new array which has a value of 1 when both aa and bb exceed 0.5?</p>
| 2 | 2016-08-14T14:54:37Z | 38,943,482 | <p>What about this?</p>
<pre><code>import numpy as np
aa = np.random.rand(5, 5)
bb = np.random.rand(5, 5)
print aa
print bb
cc = 1 * ((aa > 0.5) & (bb > 0.5))
print cc
</code></pre>
| 3 | 2016-08-14T15:04:19Z | [
"python",
"performance",
"numpy",
"vectorization"
] |
Creating new numpy arrays based on condition | 38,943,403 | <p>I have 2 numpy arrays:</p>
<pre><code>aa = np.random.rand(5,5)
bb = np.random.rand(5,5)
</code></pre>
<p>How can I create a new array which has a value of 1 when both aa and bb exceed 0.5?</p>
| 2 | 2016-08-14T14:54:37Z | 38,943,530 | <p>when element of aa and bb at index i is exceed than 0.5 then new array
have 1 at index i </p>
<pre><code>aa = np.random.rand(5,5)
bb = np.random.rand(5,5)
new_arr = []
for i in range(5):
for j in range(5):
if aa[i] >0.5 and bb[i]>0.5:
new_arr[i] = 1
else:
new_a... | -3 | 2016-08-14T15:09:57Z | [
"python",
"performance",
"numpy",
"vectorization"
] |
Creating new numpy arrays based on condition | 38,943,403 | <p>I have 2 numpy arrays:</p>
<pre><code>aa = np.random.rand(5,5)
bb = np.random.rand(5,5)
</code></pre>
<p>How can I create a new array which has a value of 1 when both aa and bb exceed 0.5?</p>
| 2 | 2016-08-14T14:54:37Z | 38,988,035 | <p>With focus on performance and using two methods few aproaches could be added. One method would be to get the boolean array of valid ones and converting to <code>int</code> datatype with <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.astype.html" rel="nofollow"><code>.astype() method</code... | 4 | 2016-08-17T04:16:18Z | [
"python",
"performance",
"numpy",
"vectorization"
] |
Django forms selecting data based on request user | 38,943,555 | <p>I am developing a django application which has a form for creating ingredients. The form contains a dropdown for selecting Recipes. When a user creates an ingredient, in the dropdown, I want that only those recipes should appear that are created by the same user. </p>
<p>Here is my code:</p>
<pre><code>#forms.py
c... | 0 | 2016-08-14T15:12:24Z | 38,943,659 | <p>In the model form you can do this:</p>
<pre><code>class IngredientForm(ModelForm):
primal = forms.BooleanField()
class Meta:
model = Ingredient
fields = ('recipe_id', 'title', 'instructions', 'rules')
def __init__(self, current_user, *args, **kwargs):
super(IngredientForm, self)... | 1 | 2016-08-14T15:24:46Z | [
"python",
"django",
"django-forms"
] |
Append additional values to queryset in Django generic views before handing to template | 38,943,658 | <p>I have the following view:</p>
<pre><code>class AppointmentListView(LoginRequiredMixin, ListView):
queryset = Appointment.objects.prefetch_related('client','patients')
</code></pre>
<p>I need to be able to add an extra variable to each returned Appointment object based on the following:</p>
<pre><code>status... | 0 | 2016-08-14T15:24:30Z | 38,943,769 | <p>You should overload the get_queryset method of the ListView like so</p>
<pre><code>def get_queryset(self, **kwargs):
queryset = super(AppointmentListView, self).get_queryset(**kwargs)
# Add new elements here
...
return queryset
</code></pre>
| 1 | 2016-08-14T15:35:16Z | [
"python",
"django",
"django-templates",
"django-views"
] |
Append additional values to queryset in Django generic views before handing to template | 38,943,658 | <p>I have the following view:</p>
<pre><code>class AppointmentListView(LoginRequiredMixin, ListView):
queryset = Appointment.objects.prefetch_related('client','patients')
</code></pre>
<p>I need to be able to add an extra variable to each returned Appointment object based on the following:</p>
<pre><code>status... | 0 | 2016-08-14T15:24:30Z | 38,950,497 | <p>I got this working by overriding get_queryset() and giving the objects (i.e. each row in the db) an extra on-the-fly key/value:</p>
<pre><code>class AppointmentListView(LoginRequiredMixin,ListView):
#friendly template context
context_object_name = 'appointments'
template_name = 'appointments/appointment... | 0 | 2016-08-15T06:50:04Z | [
"python",
"django",
"django-templates",
"django-views"
] |
NotImplementedError when using Postgres search in Django 1.10 | 38,943,668 | <p>I'm using the full text search for Postgres offered by Django 1.10 and getting a NotImplementedError. The search query I'm using is:</p>
<pre><code>Application.objects.filter(applicant_data__search='test')
</code></pre>
<p>The error is:</p>
<pre><code>NotImplementedError: Add 'django.contrib.postgres' to settings... | 1 | 2016-08-14T15:25:41Z | 38,962,417 | <p>Figured out the cause of this error - the full text search operator does not work for JSON fields.</p>
| 1 | 2016-08-15T20:17:40Z | [
"python",
"django",
"postgresql"
] |
Write a dictionary containing lists in values into text file with keys repeated for each element in the list | 38,943,673 | <p>I am new to python and I am working on a project that needs to write a dictionary into a text file. The format is like: </p>
<pre><code>{'17': [('25', 5), ('23', 3)], '12': [('28', 3), ('22', 3)], '13': [('28', 3), ('23', 3)], '16': [('22', 3), ('21', 3)], '11': [('28', 3), ('29', 1)], '14': [('22', 3), ('23', 3)],... | 0 | 2016-08-14T15:25:55Z | 38,943,772 | <pre><code>>>> for k, v in data.items():
... for t in v:
... print "%s, %s, %s" % ((k,) +t)
...
11, 28, 3
11, 29, 1
13, 28, 3
13, 23, 3
12, 28, 3
12, 22, 3
15, 26, 2
15, 24, 2
14, 22, 3
14, 23, 3
17, 25, 5
17, 23, 3
16, 22, 3
16, 21, 3
>>>
</code></pre>
<p>First get each key and value (w... | 0 | 2016-08-14T15:35:32Z | [
"python",
"list",
"file",
"dictionary"
] |
Write a dictionary containing lists in values into text file with keys repeated for each element in the list | 38,943,673 | <p>I am new to python and I am working on a project that needs to write a dictionary into a text file. The format is like: </p>
<pre><code>{'17': [('25', 5), ('23', 3)], '12': [('28', 3), ('22', 3)], '13': [('28', 3), ('23', 3)], '16': [('22', 3), ('21', 3)], '11': [('28', 3), ('29', 1)], '14': [('22', 3), ('23', 3)],... | 0 | 2016-08-14T15:25:55Z | 38,943,809 | <p>Here's a working example showing you how to dump your dictionary to string, first without any particular order and then sorted by keys, pick up what you wish:</p>
<pre><code>data = {
'17': [('25', 5), ('23', 3)],
'12': [('28', 3), ('22', 3)],
'13': [('28', 3), ('23', 3)],
'16': [('22', 3), ('21', 3)... | 0 | 2016-08-14T15:40:51Z | [
"python",
"list",
"file",
"dictionary"
] |
Write a dictionary containing lists in values into text file with keys repeated for each element in the list | 38,943,673 | <p>I am new to python and I am working on a project that needs to write a dictionary into a text file. The format is like: </p>
<pre><code>{'17': [('25', 5), ('23', 3)], '12': [('28', 3), ('22', 3)], '13': [('28', 3), ('23', 3)], '16': [('22', 3), ('21', 3)], '11': [('28', 3), ('29', 1)], '14': [('22', 3), ('23', 3)],... | 0 | 2016-08-14T15:25:55Z | 38,943,874 | <p>Assuming values of the hash consist of list with tuple of size 2. </p>
<pre><code>>>> f = open('test.txt', 'w')
>>> for key,value in d.iteritems():
... for v in value:
... f.write(key + ' ' + v[0] + ' ' + str(v[1]) + '\n')
...
>>> f.close()
</code></pre>
<p>Values in test.txt will ... | 0 | 2016-08-14T15:48:32Z | [
"python",
"list",
"file",
"dictionary"
] |
Integration error in SymPy 1.0 | 38,943,702 | <p>I'm trying to write my mathcad model in python language, but I get some mistake.
The integration function should look like this:</p>
<p><a href="http://i.stack.imgur.com/hqmeQ.png" rel="nofollow"><img src="http://i.stack.imgur.com/hqmeQ.png" alt="http://iscr.ru/photo/1471186985_snimok.PNG"></a></p>
<p>In python I ... | 3 | 2016-08-14T15:29:36Z | 38,946,744 | <p>Sympy appears to have difficulties evaluating the integral with floating point coefficients (in this case). However, it can find the integral in closed form when the constants of the integrand expression are symbolic. </p>
<pre><code>a, b, c, t = sp.symbols('a,b,c,t', positive = True)
f = sp.Integral(a * sp.exp(-c*... | 2 | 2016-08-14T21:21:39Z | [
"python",
"python-2.7",
"integration",
"sympy"
] |
How to put all print result in a function into a variable? | 38,943,716 | <p>I have a function in Python:</p>
<pre><code>def f():
...
a lot of code
...
print "hello"
...
a lot of code
...
</code></pre>
<p>I want to call this function, however, the print result will be put into a variable instead print on the screen directly. How can I do this with Python?
ps:
pl... | -1 | 2016-08-14T15:30:54Z | 38,943,850 | <p>Assuming that <code>print</code> is writing to <code>sys.stdout</code>, you can temporarily replace that with something like a <code>StringIO</code> object.</p>
<pre><code>stdout = sys.stdout
sys.stdout = StringIO()
f()
x = sys.stdout.getvalue()
sys.stdout = stdout
</code></pre>
<p>Or, if you have a reference to t... | 3 | 2016-08-14T15:45:07Z | [
"python",
"python-2.7",
"printing",
"io-redirection"
] |
How to put all print result in a function into a variable? | 38,943,716 | <p>I have a function in Python:</p>
<pre><code>def f():
...
a lot of code
...
print "hello"
...
a lot of code
...
</code></pre>
<p>I want to call this function, however, the print result will be put into a variable instead print on the screen directly. How can I do this with Python?
ps:
pl... | -1 | 2016-08-14T15:30:54Z | 38,943,877 | <pre><code>def f():
#code
variable = 'hello\n'
#code
variable += 'hello2\n'
#code
...
print(variable)
</code></pre>
<p>or</p>
<pre><code>def f():
#code
variable = 'hello\n'
#code
variable += 'hello2\n'
#code
...
return(variable)
</code></pre>
<p>and then</p>
... | -1 | 2016-08-14T15:48:43Z | [
"python",
"python-2.7",
"printing",
"io-redirection"
] |
How to put all print result in a function into a variable? | 38,943,716 | <p>I have a function in Python:</p>
<pre><code>def f():
...
a lot of code
...
print "hello"
...
a lot of code
...
</code></pre>
<p>I want to call this function, however, the print result will be put into a variable instead print on the screen directly. How can I do this with Python?
ps:
pl... | -1 | 2016-08-14T15:30:54Z | 38,943,995 | <p>Use a decorator like below</p>
<pre><code>import sys
from StringIO import StringIO
s = StringIO()
def catch_stdout(user_method):
sys.stdout = s
def decorated(*args, **kwargs):
user_method(*args, **kwargs)
sys.stdout = sys.__stdout__
print 'printing result of all prints in one go'
... | 1 | 2016-08-14T16:01:29Z | [
"python",
"python-2.7",
"printing",
"io-redirection"
] |
How to put all print result in a function into a variable? | 38,943,716 | <p>I have a function in Python:</p>
<pre><code>def f():
...
a lot of code
...
print "hello"
...
a lot of code
...
</code></pre>
<p>I want to call this function, however, the print result will be put into a variable instead print on the screen directly. How can I do this with Python?
ps:
pl... | -1 | 2016-08-14T15:30:54Z | 38,944,004 | <p>You could also define your own context manager if you find you need to do this a lot so you can capture the output for a block of statements, eg:</p>
<pre><code>import contextlib
from StringIO import StringIO
import sys
@contextlib.contextmanager
def capture_stdout():
old_stdout = sys.stdout
sys.stdout = S... | 1 | 2016-08-14T16:02:22Z | [
"python",
"python-2.7",
"printing",
"io-redirection"
] |
Python - json comparison using sets only working occasionally | 38,943,727 | <p>I have a pretty peculiar problem on my hands. I'm not too experienced with python (my language of choice being swift for mobile development), but what I have to do for this project is to pull some csv files from a database, download them locally and upload them to Amazon's DynamoDB.</p>
<p>I have managed to get eve... | 0 | 2016-08-14T15:31:18Z | 38,943,841 | <p>Your code relies on the ordering of dictionaries. Dictionary order depends on <a href="https://stackoverflow.com/questions/15479928/why-is-the-order-in-python-dictionaries-and-sets-arbitrary">insertion and deletion history</a>, varies between Python interpreter runs thanks to hash randomisation and should not be rel... | 2 | 2016-08-14T15:44:03Z | [
"python",
"json",
"set"
] |
Choppy audio from separating and then joining .wav stereo channels | 38,943,778 | <p>I am currently working on processing .wav files with python, using Pyaudio for streaming the audio, and the python wave library for loading the file data.
I plan to later on include processing of the individual stereo channels, with regards to amplitude of the signal, and panning of the stereo signal, but for now i'... | 0 | 2016-08-14T15:36:28Z | 38,954,816 | <p>As it so often happens, i slept on it, and woke up the next day with a solution.<br>
The problem was in the combineChannels function.
Following is the working code:</p>
<pre><code> def combineChannels(self, left, right):
stereoData = left
for i in range(0, self.CHUNK):
index = i*2+1
stereo... | 0 | 2016-08-15T12:10:09Z | [
"python",
"audio",
"byte",
"wave",
"pyaudio"
] |
How to back check classification using sklearn | 38,943,884 | <p>I am running two different classification algorithms on my data logistic regression and naive bayes but it is giving me same accuracy even if I change the training and testing data ratio. Following is the code I am using </p>
<pre><code>import pandas as pd
from sklearn.cross_validation import train_test_split
from ... | 1 | 2016-08-14T15:49:11Z | 38,984,063 | <p>This is common phenomena occurring if the class frequencies are unbalanced, e.g. nearly all samples belong to one class. For examples if 80% of your samples belong to class "No", then classifier will often tend to predict "No" because such a trivial prediction reaches the highest overall accuracy on your train set. ... | 1 | 2016-08-16T20:38:50Z | [
"python",
"scikit-learn",
"classification",
"logistic-regression",
"naivebayes"
] |
Page not found (404) | 38,943,891 | <p>I looked at my files more than 50 times and i'm getting frustrated.
This is the error i'm getting:</p>
<pre><code>Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in project1.urls, Django tried these URL patterns, in this order:
^admin/
^music/
The current UR... | 0 | 2016-08-14T15:50:22Z | 38,943,946 | <p>Either try the below url </p>
<pre><code>http://127.0.0.1:8000/music/
</code></pre>
<p>or remove <code>music</code> from the url pattern</p>
<pre><code>urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('music.urls')),
]
</code></pre>
| 1 | 2016-08-14T15:57:01Z | [
"python",
"django",
"templates",
"http-status-code-404"
] |
Page not found (404) | 38,943,891 | <p>I looked at my files more than 50 times and i'm getting frustrated.
This is the error i'm getting:</p>
<pre><code>Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in project1.urls, Django tried these URL patterns, in this order:
^admin/
^music/
The current UR... | 0 | 2016-08-14T15:50:22Z | 38,943,979 | <p>Take a good look at what Django tells you, why it couldn't find a corresponding page for your request URL:</p>
<blockquote>
<p>Using the URLconf defined in project1.urls, Django tried these URL
patterns, in this order: </p>
<pre><code>^admin/
^music/
</code></pre>
<p>The current URL, , didn't match any ... | 2 | 2016-08-14T15:59:56Z | [
"python",
"django",
"templates",
"http-status-code-404"
] |
Using Pandas to Change Data in an entire Excel Workbook | 38,943,902 | <p>I have an excel workbook that is very large in size. Here is what I would
like to do using Python's pandas. I am running python 3.4. </p>
<ol>
<li>Open the workbook in pandas. </li>
<li>Change values in one cell to something different - for example,
change the string in cell A2 that is currently named "Jane Doe"... | -3 | 2016-08-14T15:52:14Z | 38,945,415 | <p>Read all sheets into a dictionary:</p>
<pre><code>dfs = pd.read_excel('filename.xlsx', sheetname=None)
</code></pre>
<p>Create a writer object and iterate over dictionary while replacing based on key-value pairs:</p>
<pre><code>repl_dict = {'a': 'b', 'c': 'd', 'e': 'f', 'g': 'h', 'i': 'j'}
writer = pd.ExcelWriter... | 0 | 2016-08-14T18:39:38Z | [
"python",
"pandas"
] |
plot arrays by row with matplotlib | 38,943,920 | <p>I have two numpy arrays (a and b) with shape (16, 850) each. I'm displaying them row by row, e.g.</p>
<pre><code>plt.figure()
plt.plot(a[0], b[0])
plt.plot(a[1], b[1])
plt.plot(a[2], b[2])
...
plt.show()
</code></pre>
<p>Should I have to use a for loop to do it in a more pythonic way?</p>
| 2 | 2016-08-14T15:54:19Z | 38,943,974 | <p>You can pass a multi-dimensional array to <code>plot</code> and each column will be created as a separate plot object. We transpose both inputs so that it will plot each row separately.</p>
<pre><code>a = np.random.rand(16, 850)
b = np.random.rand(16, 850)
plt.plot(a.T, b.T)
plt.show()
</code></pre>
| 2 | 2016-08-14T15:59:32Z | [
"python",
"matplotlib"
] |
plot arrays by row with matplotlib | 38,943,920 | <p>I have two numpy arrays (a and b) with shape (16, 850) each. I'm displaying them row by row, e.g.</p>
<pre><code>plt.figure()
plt.plot(a[0], b[0])
plt.plot(a[1], b[1])
plt.plot(a[2], b[2])
...
plt.show()
</code></pre>
<p>Should I have to use a for loop to do it in a more pythonic way?</p>
| 2 | 2016-08-14T15:54:19Z | 38,943,976 | <p>This will work:</p>
<pre><code>plt.figure()
for i in range(len(a)):
plt.plot(a[i], b[i])
plt.show()
</code></pre>
<p>But the way that Suever shows is much Pythonic. However, not every function has something like that built-in. </p>
| 0 | 2016-08-14T15:59:38Z | [
"python",
"matplotlib"
] |
Trouble creating multiple copies of folders and altering specific values on a certain line, on a unique file, in each copied folder | 38,944,085 | <p>I am trying to create multiple copies of a single folder. Then what I want to do is change some words in a specific line in a specific file, on all folders i.e.:</p>
<ol>
<li>copy folderX -> folder1, folder2, ..., folderN (N could be let's say 200)</li>
<li>find file ( the file has a specific extension, for example... | 1 | 2016-08-14T16:12:58Z | 38,953,184 | <p>For the first part: to count in a shell, you need to do a little more work. Assuming you are using <code>bash</code>, you can do the following (this is very similar to what you tried, but you needed double brackets):</p>
<pre><code> for ((n=0; n<=100; n++))
do
cp -r test test_$n
done
</code></pre>
<p>Not... | 0 | 2016-08-15T10:11:49Z | [
"python",
"terminal"
] |
how to pass variable value from c++ to python? | 38,944,172 | <p>I have a sensor value which can be read using the C++ only because it was implemented using it , I want to pass location value(two float variable ) of one sensor to python, I have been reading a lot and I found shared memory , piping and more any idea what is the best way to do it ?</p>
<p>any help will be much app... | 0 | 2016-08-14T16:23:10Z | 38,944,186 | <p>It's not clear from your question whether this is a standalone C++ program or a library.</p>
<p>If it's a standalone program, use the <a href="https://docs.python.org/3/library/subprocess.html" rel="nofollow">subprocess</a> module to invoke it and read its output.</p>
<p>If it's a library, use <a href="http://cyth... | 2 | 2016-08-14T16:25:56Z | [
"python",
"c++",
"subprocess",
"piping"
] |
how to pass variable value from c++ to python? | 38,944,172 | <p>I have a sensor value which can be read using the C++ only because it was implemented using it , I want to pass location value(two float variable ) of one sensor to python, I have been reading a lot and I found shared memory , piping and more any idea what is the best way to do it ?</p>
<p>any help will be much app... | 0 | 2016-08-14T16:23:10Z | 38,959,204 | <p>@ramtha Z28 with the limited information you provided... do you have access to the C++ code itself or are you calling a DLL? You can wrap a function in Cython easily to communicate between Python and C++ if you have the source code. Wrap all the C++ blocks in <code>cpdef</code> statements which are accessible from... | 0 | 2016-08-15T16:40:02Z | [
"python",
"c++",
"subprocess",
"piping"
] |
how to pass variable value from c++ to python? | 38,944,172 | <p>I have a sensor value which can be read using the C++ only because it was implemented using it , I want to pass location value(two float variable ) of one sensor to python, I have been reading a lot and I found shared memory , piping and more any idea what is the best way to do it ?</p>
<p>any help will be much app... | 0 | 2016-08-14T16:23:10Z | 38,959,725 | <p>I'm not familiar with python however, a simple approach is to use some communication protocols such as serial ports or udp which is a network protocol. For real-time applications, UDP protocol is a preferable choice. </p>
| 0 | 2016-08-15T17:14:54Z | [
"python",
"c++",
"subprocess",
"piping"
] |
Python Fabric Parallel Execution Failure on EC2: Updated | 38,944,236 | <p>So, background first. I was running Ubuntu 14.04 and running the following script without issue, where I <code>put</code> file on an EC2 instances. <strong>Note</strong>: I used the same IP's to illustrate both the success and failure, but pretend I had run this script from the start both times, generating new IP's ... | 0 | 2016-08-14T16:30:33Z | 38,948,451 | <p><strong>UPDATE</strong> This does not solve it. The only thing that solves the issue is to run the parallel command a second time.</p>
<p>Very embarrassing, but I have to post. As I mentioned, I was forced to completely reinstall Ubuntu, and lost my key-pair. What I overlooked was my <code>ssh_config</code> file. ... | 0 | 2016-08-15T02:15:13Z | [
"python",
"ssh",
"amazon-ec2",
"boto",
"fabric"
] |
Creating class in python tkinter (object is frame with things inside) | 38,944,265 | <p>I wanted to create a gui application in python consisting of multiple objects of a class i would define. Each object would be <strong>a frame</strong> with <strong>image</strong> and <strong>a label</strong> inside.</p>
<p>I tried this: </p>
<pre><code> `class MyClass:
def __init__(self)
self... | -2 | 2016-08-14T16:33:56Z | 38,991,683 | <p>I figured it myself:</p>
<p>Just add a path to the image to the <strong>init</strong> function:</p>
<pre><code>def __init__(self, imagepath)
</code></pre>
<p>Rest is the same, just define the image using this path.</p>
| 0 | 2016-08-17T08:30:07Z | [
"python",
"image",
"class",
"tkinter",
"frame"
] |
My Python Bot Can connect to the IRC server but doesnt join the channel | 38,944,275 | <p>so i made an IRC bot, this is the code:</p>
<pre><code>import socket
import sys
server = "irc.esper.net"
channel = "#stencyl"
botnick = "MrGutsy"
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "connecting to:"+server
irc.connect((server, 6667))
irc.send("USER "+ botnick +" "+ botnick +" "+ botnick ... | 0 | 2016-08-14T16:34:37Z | 38,944,575 | <p>As @spectras noticed, you have to wait a little bit before sending JOINs.</p>
<p>The key is this reply from the server:</p>
<pre><code>:stormlight.esper.net 451 * :You have not registered
</code></pre>
<p>Which means you sent a command (the PRIVMSG and/or the JOIN) before your completed the registration process, ... | 1 | 2016-08-14T17:09:31Z | [
"python",
"irc"
] |
Steps to Troubleshoot "django.db.utils.ProgrammingError: permission denied for relation django_migrations" | 38,944,551 | <p>What are some basic steps for troubleshooting and narrowing down the cause for the "django.db.utils.ProgrammingError: permission denied for relation django_migrations" error from Django?</p>
<p>I'm getting this message after what was initially a stable production server but has since had some changes to several asp... | 0 | 2016-08-14T17:06:54Z | 39,070,745 | <p>I was able to solve my issue based on instructions from this <a href="http://stackoverflow.com/questions/12233046/django-permission-denied-when-trying-to-access-database-after-restore-migratio">question</a>. Basically, postgres privileges needed to be re-granted to the db user. In my case, that was the user I had se... | 0 | 2016-08-22T02:50:14Z | [
"python",
"django",
"apache",
"postgresql",
"github"
] |
Detect grid nodes using OpenCV (or using something else) | 38,944,594 | <p>I have a grid on pictures (they are from camera). After binarization they look like this (red is 255, blue is 0):
<a href="http://i.stack.imgur.com/59Kz5.png"><img src="http://i.stack.imgur.com/59Kz5.png" alt="grid"></a></p>
<p>What is the best way to detect grid nodes (crosses) on these pictures?
Note: grid is di... | 10 | 2016-08-14T17:12:14Z | 39,003,571 | <p>I suppose that this can be a potential answer (actually mentioned in comments): <a href="http://opencv.itseez.com/2.4/modules/imgproc/doc/feature_detection.html?highlight=hough#houghlinesp" rel="nofollow">http://opencv.itseez.com/2.4/modules/imgproc/doc/feature_detection.html?highlight=hough#houghlinesp</a></p>
<p>... | 1 | 2016-08-17T18:09:20Z | [
"python",
"opencv",
"pattern-recognition"
] |
Detect grid nodes using OpenCV (or using something else) | 38,944,594 | <p>I have a grid on pictures (they are from camera). After binarization they look like this (red is 255, blue is 0):
<a href="http://i.stack.imgur.com/59Kz5.png"><img src="http://i.stack.imgur.com/59Kz5.png" alt="grid"></a></p>
<p>What is the best way to detect grid nodes (crosses) on these pictures?
Note: grid is di... | 10 | 2016-08-14T17:12:14Z | 39,099,412 | <p>In cases like this I first try to find the best starting point.
So, first I thresholded your image (however I could also skeletonize it and just then threshold. But this way some data is lost irrecoverably):</p>
<p><img src="http://i.imgur.com/3497JwU.png" alt="Imgur"></p>
<p>Then, I tried loads of tools to get th... | 2 | 2016-08-23T11:03:38Z | [
"python",
"opencv",
"pattern-recognition"
] |
Detect grid nodes using OpenCV (or using something else) | 38,944,594 | <p>I have a grid on pictures (they are from camera). After binarization they look like this (red is 255, blue is 0):
<a href="http://i.stack.imgur.com/59Kz5.png"><img src="http://i.stack.imgur.com/59Kz5.png" alt="grid"></a></p>
<p>What is the best way to detect grid nodes (crosses) on these pictures?
Note: grid is di... | 10 | 2016-08-14T17:12:14Z | 39,120,700 | <p>Maybe you cloud calculate <a href="https://en.wikipedia.org/wiki/Hough_transform" rel="nofollow">Hough Lines</a> and determine the intersections. An OpenCV documentation can be found <a href="http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html" rel="nofollow">here</a></p>
| 0 | 2016-08-24T10:25:19Z | [
"python",
"opencv",
"pattern-recognition"
] |
Pandas Timestamp - Cannot convert arg to a time error | 38,944,599 | <p>I am trying to find the <code>min()</code> value between two points using <code>between_time</code>. I have created two columns that I would like to use as my start and end time to find the minimum value and add the output to a new column:</p>
<p>This is a snip of the df: </p>
<pre><code>df[['Date_Time','d1_idx_... | 0 | 2016-08-14T17:12:59Z | 38,944,679 | <p><strong>UPDATE:</strong> using ugly method - <code>apply(..., axis=1)</code>: </p>
<pre><code>In [170]: df['subset_low'] = df.apply(lambda r: df.query('@r.Date_Time <= index <= @r.d1_idx_last').Low.min(), axis=1)
In [171]: df
Out[171]:
Date_Time d1_idx_last Low ... | 2 | 2016-08-14T17:21:21Z | [
"python",
"pandas"
] |
python: can't open file 'scriptbootstrap.py' | 38,944,608 | <p>I am trying to start the electron app on windows via <a href="https://github.com/electron/electron/blob/master/docs/development/build-instructions-windows.md" rel="nofollow">https://github.com/electron/electron/blob/master/docs/development/build-instructions-windows.md</a></p>
<p>I have completed the first two step... | 0 | 2016-08-14T17:13:48Z | 38,945,384 | <p>First, I would like to know whether the <code>python script\bootstrap.py -v</code> worked for you.</p>
<p>See sample output, on my machine, (using git bash)</p>
<pre><code>Anubhavs@DDSPL1392 MINGW64 /e/Projects/electron (master)
$ python script/bootstrap.py -v
Submodule 'vendor/boto' (https://github.com/boto/boto.... | 0 | 2016-08-14T18:35:50Z | [
"javascript",
"python",
"node.js",
"electron"
] |
Python import failure | 38,944,665 | <p>Got some strange import error which is as much strangely reported by interpreter.</p>
<p>I use CPython-3.5</p>
<p>Directory structure:</p>
<pre><code>.
+-- outer
| +-- inner
| | +-- __init__.py
| | +-- first.py
| | +-- second.py
| +-- __init__.py
+-- main.py
</code></pre>
<p>main.py:</p>
<pre><c... | 0 | 2016-08-14T17:19:41Z | 38,945,102 | <p>It's better to import relative paths, not absolute ones. I do not know what you are trying to achieve, but correct way to import something from a file on the same level is to use a dot <code>.</code> so In your <code>first</code> file use something like:</p>
<pre><code>from .second import var as second_var
var = se... | 0 | 2016-08-14T18:07:24Z | [
"python",
"python-3.x"
] |
How to Drop All The Rows Based on Multiple Values Found in the "Fruit "Column? | 38,944,673 | <p>I have this simple dataframe</p>
<pre><code>Num Fruit Price
1 Apple 1.00
1 Apple 1.00
2 Apple 1.50
2 Orange 1.50
3 Orange 1.00
3 Banana 0.50
</code></pre>
<p>I want to drop all the rows which have the fruit <code>Apple</code> or <code>Orange</code></p>
<p>The expected output s... | -1 | 2016-08-14T17:20:15Z | 38,944,700 | <p>You need to pass the indices of the rows to be dropped, but you are passing a boolean array. You can change it to:</p>
<pre><code>df.drop(df[df.Fruit.isin(["Apple", "Orange"])].index)
Out:
Num Fruit Price
5 3 Banana 0.5
</code></pre>
<p>Or you can select the rows that don't contain apple or orange:</... | 3 | 2016-08-14T17:24:45Z | [
"python",
"pandas",
"dataframe"
] |
Python - CSS Not Working in Embedded HTML | 38,944,721 | <p>I am having trouble getting the CSS to link properly. It's named correctly. It just doesn't want to work. I've tried every possible way to type it out. I've heard a bunch of different things. Some say you have to type the entire project URL out (simple-login/css/style.css). I've also heard you just have to go up one... | 1 | 2016-08-14T17:25:39Z | 39,115,229 | <p>I would like to suggest you to use <a href="https://cloud.google.com/appengine/docs/python/getting-started/generating-dynamic-content-templates" rel="nofollow">Jinja 2</a>. It will help you to organize your code. It is a template language which is really good to use with Webapp2.</p>
| 0 | 2016-08-24T05:41:47Z | [
"python",
"html",
"css"
] |
Trying to get lxml to print a specific number in python | 38,944,759 | <p>I'm trying to get lxml to print the selected in python:
<a href="http://imgur.com/a/joeql" rel="nofollow">http://imgur.com/a/joeql</a></p>
<p>The code I have isn't much but here it is</p>
<pre><code>from lxml import html
import requests
page = requests.get('https://www.pathofexile.com/forum/view-thread/1703834')... | 1 | 2016-08-14T17:29:47Z | 38,944,910 | <p>A syntax error means you are writing invalid python, and that does not necessarily mean there is something wrong with your logic/approach.</p>
<p>Make sure to surround the argument inside your invocation of tree.xpath with single quotes.</p>
<pre><code>winner = tree.xpath('//*[@id="eventView0"]/div[3]/table/tbody/... | 1 | 2016-08-14T17:45:55Z | [
"python",
"web-scraping",
"lxml"
] |
Trying to get lxml to print a specific number in python | 38,944,759 | <p>I'm trying to get lxml to print the selected in python:
<a href="http://imgur.com/a/joeql" rel="nofollow">http://imgur.com/a/joeql</a></p>
<p>The code I have isn't much but here it is</p>
<pre><code>from lxml import html
import requests
page = requests.get('https://www.pathofexile.com/forum/view-thread/1703834')... | 1 | 2016-08-14T17:29:47Z | 38,944,941 | <p>The syntax error you see is because you have not enclosed the XPath string into quotes, fix it:</p>
<pre><code>winner = tree.xpath('//*[@id="eventView0"]/div[3]/table/tbody/tr[1]/td[7]')
</code></pre>
<p>The <em>actual</em> problem is that the <em>table content is dynamically formed</em> via JavaScript that is exe... | 1 | 2016-08-14T17:49:04Z | [
"python",
"web-scraping",
"lxml"
] |
Filter out all lists of a dictionary based on a condition applied to one of the lists | 38,944,769 | <p>I have this dictionary:</p>
<pre><code>d={'names': ['Mark', 'Amir', 'Matt', 'Greg', 'Owen', 'Juan'], 'weight': [165, 189,
220, 141, 260, 174], 'height': [66, 71, 72, 68, 58, 62]}
</code></pre>
<p>And I want to filter out all its lists so that they contain only the items that correspond to a height of greater than... | -1 | 2016-08-14T17:30:36Z | 38,944,805 | <p>You can use dictionary comprehension.</p>
<pre><code>d = {
'names': ['Mark', 'Amir', 'Matt', 'Greg', 'Owen', 'Juan'],
'weight': [165, 189, 220, 141, 260, 174],
'height': [66, 71, 72, 68, 58, 62]
}
filtered_dict = {
key: [value for i, value in enumerate(d[key]) if d['height'][i] > 70]
for key... | 3 | 2016-08-14T17:35:00Z | [
"python",
"list",
"dictionary"
] |
Why do I get an AttributeError with Python3.4's `unittest` library? | 38,944,798 | <p>So here is my code:</p>
<pre><code>import unittest
class Primes:
@staticmethod
def first(n):
<python code here>
class Test(unittest.TestCase):
def __init__(self):
pass
def assert_equals(self, l, m):
self.assertEqual(l, m)
Test = Test()
Test.assert_equals(Primes.first(1),... | 0 | 2016-08-14T17:34:32Z | 38,944,921 | <p>You get the error because you're using <code>unittest</code> incorrectly. Per <a href="https://docs.python.org/3/library/unittest.html#basic-example" rel="nofollow">the example in the docs</a>, your tests should look like:</p>
<pre><code>import unittest
class TestPrimes(unittest.TestCase):
def test_singlePrim... | 1 | 2016-08-14T17:47:00Z | [
"python",
"python-unittest"
] |
How to add data-attribute to django modelform modelchoicefield | 38,944,814 | <p>I have a django modelform 'Recipe' with a foreignkey field to a model 'Ingredient'.</p>
<p>When rendering the form I get a SELECT list that have an ID matching the ingredients ID and text display equal to the string representation of the field.</p>
<p>However, I want to add a data-attribute to the select list that... | 0 | 2016-08-14T17:35:53Z | 38,945,002 | <p>Why not <a href="https://docs.djangoproject.com/en/dev/topics/forms/#rendering-fields-manually" rel="nofollow">render the fields manually</a>?<br>
It''ll be something like </p>
<pre><code><select>
{% for option in form.ingredient.choices %}
<option value="{{ option.id }}" data-ingredient-type={{ op... | 0 | 2016-08-14T17:54:26Z | [
"python",
"django",
"django-forms"
] |
Scipy: sparse matrix conditional removal of columns | 38,945,093 | <p>I have a large (79 000 x 480 000) sparse csr matrix. I am trying to remove all columns (within a certain range) for which each value < k.</p>
<p>In regular numpy matrices this is simply done by a mask:</p>
<pre><code>m = np.array([[0,2,1,1],
[0,4,2,0],
[0,3,4,0]])
mask = (arr <... | 2 | 2016-08-14T18:06:10Z | 38,945,428 | <p>If I do</p>
<pre><code>M = sparse.csr_matrix(m)
M < 2
</code></pre>
<p>I get an efficiency warning; all the 0 values of M satisfy the condition,</p>
<pre><code>In [1754]: print(M)
(0, 1) 2
(0, 2) 1
(0, 3) 1
(1, 1) 4
(1, 2) 2
(2, 1) 3
(2, 2) 4
In [1755]: print(M<2)
/usr/li... | 3 | 2016-08-14T18:40:33Z | [
"python",
"numpy",
"matrix",
"scipy",
"sparse-matrix"
] |
monitoring jboss process with icinga/nagios | 38,945,299 | <p>I want to monitor jboss if its running or not through Icinga.</p>
<p>I don't want to check <code>/etc/inid.d/jboss status</code> as sometimes service is up but some of the jboss is killed or hang & jboss doesn't work properly.</p>
<p>I would like to create a script to monitor all of its process from <code>ps</... | 0 | 2016-08-14T18:26:52Z | 38,962,513 | <p>Reading about the availability of plugins from a quick Google search led me to JMX. And obviously check_jmx4perl and Jolokia which have been a swiss army knife for monitoring java application servers. I've used it with tomcat and websphere but it should work with jboss as well.</p>
<p>In case you're using Icinga 2,... | 1 | 2016-08-15T20:25:56Z | [
"python",
"shell",
"jboss",
"nagios",
"icinga"
] |
monitoring jboss process with icinga/nagios | 38,945,299 | <p>I want to monitor jboss if its running or not through Icinga.</p>
<p>I don't want to check <code>/etc/inid.d/jboss status</code> as sometimes service is up but some of the jboss is killed or hang & jboss doesn't work properly.</p>
<p>I would like to create a script to monitor all of its process from <code>ps</... | 0 | 2016-08-14T18:26:52Z | 39,252,775 | <p>You can find it here : <a href="https://exchange.nagios.org/components/com_mtree/attachment.php?link_id=1274&cf_id=24" rel="nofollow">check_jmx</a>, this will monitor jboss process. You need to add some $JAVA_OPTS to enable this in jboss.</p>
| 0 | 2016-08-31T14:47:25Z | [
"python",
"shell",
"jboss",
"nagios",
"icinga"
] |
monitoring jboss process with icinga/nagios | 38,945,299 | <p>I want to monitor jboss if its running or not through Icinga.</p>
<p>I don't want to check <code>/etc/inid.d/jboss status</code> as sometimes service is up but some of the jboss is killed or hang & jboss doesn't work properly.</p>
<p>I would like to create a script to monitor all of its process from <code>ps</... | 0 | 2016-08-14T18:26:52Z | 39,367,798 | <p>I did this by monitored jboss process using <code>ps aux | grep "\-D\[Standalone\]</code>" for standalone mode and <code>ps aux | grep "\-D\[Server"</code> for domain mode.</p>
| 0 | 2016-09-07T10:46:33Z | [
"python",
"shell",
"jboss",
"nagios",
"icinga"
] |
Trying to make an apk file online with Python/Kivy, but it does not work. Why? | 38,945,376 | <p>I'm trying to learn to program in <code>Python2.7/Kivy</code> and build applications for Android platform.</p>
<p>So I uploaded a zip-file containing a <code>main.py</code> and a <code>kv</code> file to <a href="http://android.kivy.org" rel="nofollow">http://android.kivy.org</a>, but as I push the <code>submit</cod... | 0 | 2016-08-14T18:34:58Z | 38,945,406 | <p>if it's 500 internal server error, it's most probably from the server side not your fault.<br>
May be should try later.</p>
| 0 | 2016-08-14T18:38:22Z | [
"android",
"python",
"apk",
"kivy",
"internal-server-error"
] |
How to check if window is on Fullscreen in Tkinter? | 38,945,412 | <p>I made <strong>F11</strong> toggle fullscreen on. But how can I make it so that <strong>F11</strong> can both toggle fullscreen on and off ?</p>
<p>I tried to make an [if] statement so it will turn it off if the window was previously toggled to fullscreen but I couldn't find a way to check if the window was already... | -2 | 2016-08-14T18:39:19Z | 38,945,602 | <p>This is the method I mentioned in my comment above:</p>
<pre><code>from tkinter import *
root = Tk()
root.focus_set()
var = 0
def f(event):
global var
if var == 0:
root.attributes("-fullscreen", True)
var = 1
else:
root.attributes("-fullscreen", False)
var = 0
root.bi... | 1 | 2016-08-14T18:59:20Z | [
"python",
"tkinter",
"fullscreen"
] |
How to check if window is on Fullscreen in Tkinter? | 38,945,412 | <p>I made <strong>F11</strong> toggle fullscreen on. But how can I make it so that <strong>F11</strong> can both toggle fullscreen on and off ?</p>
<p>I tried to make an [if] statement so it will turn it off if the window was previously toggled to fullscreen but I couldn't find a way to check if the window was already... | -2 | 2016-08-14T18:39:19Z | 38,945,757 | <p><code>root.attributes</code> can be called with only a single argument to get the value of that argument. </p>
<pre><code>if (root.attribute('-fullscreen')):
...
else
...
</code></pre>
| 1 | 2016-08-14T19:18:57Z | [
"python",
"tkinter",
"fullscreen"
] |
How to put a " inside of a variable python | 38,945,413 | <p>I have been trying to make a encryption program recently, and I cant quite figure out how to place double quotes inside a variable, in this case 'alphabet'. Currently I have every character I need except for " and a tab key, keep in mind I'm just a beginner and help would be appreciated. - Thanks!</p>
<pre><code>w... | 0 | 2016-08-14T18:39:26Z | 38,945,444 | <p>You can use <code>\"</code></p>
<p>Sample:</p>
<pre><code>print ("Hello \"")
</code></pre>
<p>Output:</p>
<pre><code>Hello "
</code></pre>
| 2 | 2016-08-14T18:42:23Z | [
"python"
] |
Trying to flatten array in numpy | 38,945,499 | <p>I'm new to numpy and trying to flatten a 1000,1000 array created from a pandas dataframe. the code i've used is:</p>
<pre><code> lidor_array=lidor_df.values
print(lidor_array.shape)
lidor_array.flatten()
print(lidor_array.shape)
</code></pre>
<p>the shapes are output as (1000,1000) for both the pre ... | 0 | 2016-08-14T18:48:01Z | 38,945,549 | <p><code>flatten</code> is not performed in-place. It returns a copy:</p>
<p><a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flatten.html" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flatten.html</a></p>
<p>You could either do:</p>
<pre><code>lidor_arra... | 1 | 2016-08-14T18:52:52Z | [
"python",
"numpy"
] |
How does cv2.fitEllipse handle width/height with regards to rotation? | 38,945,695 | <p>An ellipse of width 50, height 100, and angle 0, would be identical to an ellipse of width 100, height 50, and angle 90 - i.e. one is the rotation of the other.</p>
<p>How does cv2.fitEllipse handle this? Does it return ellipses in some normalized form (i.e. angle is picked such that width is always < height), o... | 0 | 2016-08-14T19:11:03Z | 38,945,813 | <p>Empirically, I ran code matching thousands of ellipses, and I never got one return value where the returned width was greater than the returned height. So it seems OpenCV normalizes the ellipse such that <code>height >= width</code>.</p>
| 0 | 2016-08-14T19:27:44Z | [
"python",
"opencv",
"ellipse",
"data-fitting"
] |
How does cv2.fitEllipse handle width/height with regards to rotation? | 38,945,695 | <p>An ellipse of width 50, height 100, and angle 0, would be identical to an ellipse of width 100, height 50, and angle 90 - i.e. one is the rotation of the other.</p>
<p>How does cv2.fitEllipse handle this? Does it return ellipses in some normalized form (i.e. angle is picked such that width is always < height), o... | 0 | 2016-08-14T19:11:03Z | 38,947,299 | <p>You can see in the OpenCV source code for <a href="https://github.com/opencv/opencv/blob/2f4e38c8313ff313de7c41141d56d945d91f47cf/modules/imgproc/src/shapedescr.cpp#L435" rel="nofollow">fitEllipse</a> that the height of the ellipse is always larger than the width.</p>
<p>If the width is larger than the height, then... | 1 | 2016-08-14T22:50:16Z | [
"python",
"opencv",
"ellipse",
"data-fitting"
] |
Prevent input type url default behavior using Flask | 38,945,815 | <p>I have input type url in a form and Im trying to get the list of validation errors in the same page, but I want the form first send the data to the server and then render the error list but when the input type is set to url and I enter some other text It shows a popup and say Enter valid Url
It does it on the client... | 0 | 2016-08-14T19:27:55Z | 38,947,071 | <p>It depends on the browser support of HTML5 and It causes client-side validation and prevents data to passed to the server. You can overcome that default behavior of the HTML5 URL field by adding the tag <code>novalidate</code> to your form.</p>
<p>Your template will look like this</p>
<pre><code><form id='addUr... | 0 | 2016-08-14T22:12:43Z | [
"python",
"validation",
"flask",
"html-form",
"wtforms"
] |
How can I replace Python Pandas table text values with unique IDs? | 38,945,840 | <p>I am using Pandas to read a file in this format:</p>
<pre><code>fp = pandas.read_table("Measurements.txt")
fp.head()
"Aaron", 3, 5, 7
"Aaron", 3, 6, 9
"Aaron", 3, 6, 10
"Brave", 4, 6, 0
"Brave", 3, 6, 1
</code></pre>
<p>I want to replace each name with a unique ID so output looks like:</p>
<pre><code>"1", ... | 1 | 2016-08-14T19:31:28Z | 38,945,903 | <p>You can do that via a simple dictionary mapping.
Say for instance your data looks like this:</p>
<pre><code>col1, col2, col3, col4
"Aaron", 3, 5, 7
"Aaron", 3, 6, 9
"Aaron", 3, 6, 10
"Brave", 4, 6, 0
"Brave", 3, 6, 1
</code></pre>
<p>then simply do </p>
<pre><code>myDict = {"Aaron":"1", "Brave":"2"}
fp["co... | 3 | 2016-08-14T19:38:33Z | [
"python",
"python-3.x",
"pandas"
] |
How can I replace Python Pandas table text values with unique IDs? | 38,945,840 | <p>I am using Pandas to read a file in this format:</p>
<pre><code>fp = pandas.read_table("Measurements.txt")
fp.head()
"Aaron", 3, 5, 7
"Aaron", 3, 6, 9
"Aaron", 3, 6, 10
"Brave", 4, 6, 0
"Brave", 3, 6, 1
</code></pre>
<p>I want to replace each name with a unique ID so output looks like:</p>
<pre><code>"1", ... | 1 | 2016-08-14T19:31:28Z | 38,945,917 | <p>Why not using a hash on the name</p>
<pre><code>df["col0"] = df["col0"].apply(lambda x: hashlib.sha256(x.encode("utf-8")).hexdigest())
</code></pre>
<p>In this way you do not need to care about the names that occurring, i.e. you do not need to know them upfront to build a dictionary for mapping.</p>
| 0 | 2016-08-14T19:40:31Z | [
"python",
"python-3.x",
"pandas"
] |
How can I replace Python Pandas table text values with unique IDs? | 38,945,840 | <p>I am using Pandas to read a file in this format:</p>
<pre><code>fp = pandas.read_table("Measurements.txt")
fp.head()
"Aaron", 3, 5, 7
"Aaron", 3, 6, 9
"Aaron", 3, 6, 10
"Brave", 4, 6, 0
"Brave", 3, 6, 1
</code></pre>
<p>I want to replace each name with a unique ID so output looks like:</p>
<pre><code>"1", ... | 1 | 2016-08-14T19:31:28Z | 38,945,947 | <p>I would make use of <a href="http://pandas.pydata.org/pandas-docs/stable/categorical.html" rel="nofollow">categorical</a> dtype:</p>
<pre><code>In [97]: x['ID'] = x.name.astype('category').cat.rename_categories(range(1, x.name.nunique()+1))
In [98]: x
Out[98]:
name v1 v2 v3 ID
0 Aaron 3 5 7 1
1 Aar... | 2 | 2016-08-14T19:43:37Z | [
"python",
"python-3.x",
"pandas"
] |
How can I replace Python Pandas table text values with unique IDs? | 38,945,840 | <p>I am using Pandas to read a file in this format:</p>
<pre><code>fp = pandas.read_table("Measurements.txt")
fp.head()
"Aaron", 3, 5, 7
"Aaron", 3, 6, 9
"Aaron", 3, 6, 10
"Brave", 4, 6, 0
"Brave", 3, 6, 1
</code></pre>
<p>I want to replace each name with a unique ID so output looks like:</p>
<pre><code>"1", ... | 1 | 2016-08-14T19:31:28Z | 38,946,041 | <p>It looks like this <a href="http://stackoverflow.com/questions/25698710/replace-all-occurrences-of-a-string-in-a-pandas-dataframe-python">Replace all occurrences of a string in a pandas dataframe</a> might hold your answer. According to the documentation, <a href="http://pandas.pydata.org/pandas-docs/stable/generate... | 0 | 2016-08-14T19:55:22Z | [
"python",
"python-3.x",
"pandas"
] |
How to read specific multiple lines using for loop at the same time? | 38,945,848 | <p>contents are in <code>list[info]</code> from a text file:</p>
<pre><code>1,1,1703,385,157,339,1,-1,-1,-1
1,3,1293,455,83,213,1,-1,-1,-1
1,4,259,449,101,261,1,-1,-1,-1
1,5,1253,529,55,127,1,-1,-1,-1
2,1,1699,383,159,341,1,-1,-1,-1
2,3,1293,455,83,213,1,-1,-1,-1
2,4,261,447,101,263,1,-1,-1,-1
2,5,1253,529,55,1... | 0 | 2016-08-14T19:32:35Z | 38,945,966 | <p>You can create a dictionary of integer value to list of those four values you want to print:</p>
<pre><code>from collections import defaultdict
lines = [
'1,1,1703,385,157,339,1,-1,-1,-1',
'1,3,1293,455,83,213,1,-1,-1,-1',
'1,4,259,449,101,261,1,-1,-1,-1',
'1,5,1253,529,55,127,1,-1,-1,-1',
'2,1... | 2 | 2016-08-14T19:46:29Z | [
"python",
"for-loop"
] |
kivy on android and app engine? | 38,945,932 | <p>Is it possible to use google app engine with kivy on Android?</p>
<p>I've tried but after running buildozer I ve got an error in dowloading app-engine. I've got this error in log:</p>
<pre><code> ------------------------------------------------------------
/media/projekty/kiwi/.buildozer/venv/bin/pip run on Sun... | 0 | 2016-08-14T19:41:56Z | 38,961,357 | <p>It looks like <code>ez_setup.py</code> comes from <a href="https://pypi.python.org/pypi/setuptools" rel="nofollow"><code>setuptools</code></a>. Do you have setuptools installed on your machine?</p>
| 0 | 2016-08-15T19:04:58Z | [
"android",
"python",
"google-app-engine",
"kivy"
] |
How can I close a file handle while function exit with exception in Python? | 38,945,949 | <p>For instance, I have a function like:</p>
<pre><code>def example():
fp = open('example.txt','w+')
fp.write(str(1/0))
fp.close()
</code></pre>
<p>Then it will throw an exception because 1/0 is not defined. However, I can neither remove <code>example.txt</code> nor modify <code>example.txt</code>. But I ... | 0 | 2016-08-14T19:43:52Z | 38,945,980 | <p>You can wrap that in a try/except to handle the error and close the file reader before the program ends.</p>
<pre><code>def example():
fp = open('example.txt', 'w+')
try:
fp.write(str(1/0))
except ZeroDivisionError:
fp.close()
fp.close()
</code></pre>
<p>Edit: The answer by @IanAuld... | 2 | 2016-08-14T19:48:14Z | [
"python"
] |
How can I close a file handle while function exit with exception in Python? | 38,945,949 | <p>For instance, I have a function like:</p>
<pre><code>def example():
fp = open('example.txt','w+')
fp.write(str(1/0))
fp.close()
</code></pre>
<p>Then it will throw an exception because 1/0 is not defined. However, I can neither remove <code>example.txt</code> nor modify <code>example.txt</code>. But I ... | 0 | 2016-08-14T19:43:52Z | 38,946,031 | <pre><code>with open('example.txt','w+') as fp:
try:
fp.write(...)
except ZeroDivisionError as e:
print('there was an error: {}'.format(e))
</code></pre>
<p>Using the <code>with</code> context manager any files opened by it will be closed automatically once they go out of scope. </p>
| 3 | 2016-08-14T19:54:11Z | [
"python"
] |
Protocol Error on basket download request | 38,946,159 | <p>I am trying to download a Pypi package using basket. but the command shows "<strong><code>ProtocolError for pypi.python.org/pypi: 403 Must access using HTTPS instead of HTTP</code></strong>" message.</p>
<p>My command is : <code>sudo basket download unittest2</code></p>
<p>The response is : </p>
<pre><code>`Trace... | 0 | 2016-08-14T20:09:32Z | 39,277,908 | <p>You have to go into /path-to-python-site-packages/basket/main.py, and edit the following line:</p>
<pre><code>PYPI_ENDPOINT = 'http://pypi.python.org/pypi'
</code></pre>
<p>And Change it to "https":</p>
<pre><code>PYPI_ENDPOINT = 'https://pypi.python.org/pypi'
</code></pre>
<p>Then your downloads should work. Is... | 0 | 2016-09-01T17:48:04Z | [
"python",
"pip",
"pypi"
] |
Displaying Raspberry Pi clock on LCD display | 38,946,173 | <p>I have a Raspberry Pi running an LCD display. I found the Python script below which displays the time on the display, but I notice there's a delay of almost a second between the Pi's time and the LCD.</p>
<p>I tried removing the last line of the code (<b>sleep(1)</b>) and that removed the delay but the LCD flickers... | 2 | 2016-08-14T20:10:51Z | 38,946,200 | <p>The sleep(1) instructs the program to "sleep" for 1 second. This is actually very significant because that means that the while loop (which is always true) will then only run once every second. When you take away the sleep(1) line, that means the while loop never takes a break and continues running as fast as the co... | 1 | 2016-08-14T20:13:50Z | [
"python",
"time",
"raspberry-pi",
"lcd",
"adafruit"
] |
Append Numpy ndarray to pandas dataframe | 38,946,206 | <p>I have ten numpy ndarrys each having one row and 100 columns. Now I want to append them sequentially to a pandas dataframe (should have 10 rows and 100 columns in the end). How can I achieve that in python:</p>
<pre><code># create empty dataframe
data = pd.DataFrame()
# Loop
for i in range(1, 11):
# Simulate ... | -2 | 2016-08-14T20:14:30Z | 38,946,282 | <p>Create iteratively the array, to make it 10x100, then pass it to <code>DataFrame</code>.</p>
<p>You can use <code>np.insert</code> or <code>np.vstack</code> to create the 10x100 array.</p>
| 0 | 2016-08-14T20:23:12Z | [
"python",
"pandas",
"numpy"
] |
Get rid of unicode error | 38,946,269 | <p>I have the following code attempting to print the edge lists of graphs. It looks like the edges are cycled but it's my intention to test whether all edges are contained while going through the function for further processing.</p>
<pre><code>def mapper_network(self, _, info):
info[0] = info[0].encode('utf-8')
... | 0 | 2016-08-14T20:21:39Z | 38,946,410 | <p>I highly recommend reading this <a href="https://www.azavea.com/blog/2014/03/24/solving-unicode-problems-in-python-2-7/" rel="nofollow">article on unicode</a>. It gives a nice explanation of unicode vs. strings in Python 2.</p>
<p>For your problem specifically, when you call <code>unicodedata.normalize("NFKD", edge... | 0 | 2016-08-14T20:39:00Z | [
"python",
"unicode",
"encoding",
"networkx"
] |
How can I connect graphviz nodes that are in records with pygraphviz? | 38,946,271 | <p>I am working with pygraphviz to interface with dot/graphviz. I am creating records through labels but I am wondering how to connect ports that are in the records rather than record nodes themselves.</p>
<p>In dot it would look something like this:</p>
<pre><code> a00 [shape = "record" label="{{RecordThing1}|{&l... | 1 | 2016-08-14T20:22:07Z | 38,947,969 | <p>I found a solution: The headport and tailport attributes of edges can be used.
e.g.</p>
<pre><code> agraph.add_node('a00', 'a01', tailport=1, headport=1)
</code></pre>
<p>Read more at: <a href="http://www.graphviz.org/content/attrs#aheadport" rel="nofollow">http://www.graphviz.org/content/attrs#aheadport</a></p... | 1 | 2016-08-15T00:49:56Z | [
"python",
"graphviz",
"pygraphviz"
] |
python selenium choose random firefox profile | 38,946,361 | <p>In my script folder I have copied my firefox profiles folders</p>
<p>My code</p>
<pre><code>#Creating profile for browser
profile = webdriver.FirefoxProfile('.\profiles\profile1')
profile.set_preference("general.useragent.override", user_agent)
profile.update_preferences()
</code></pre>
<p>What I would like to do... | 0 | 2016-08-14T20:33:24Z | 38,963,122 | <p>The only modification I perform is 1) list profiles directory, 2) filter to keep only directories 3) apply random on the list</p>
<p>I hope it's what you want:</p>
<pre><code>import os,random
profile_dir="profiles"
# pick a directory
randdir = random.choice(list(filter(os.path.isdir,os.listdir(profile_dir))))
p... | 0 | 2016-08-15T21:10:18Z | [
"python",
"selenium",
"firefox"
] |
Django, url not found? | 38,946,371 | <p>I'm trying out Python Django. With eclipse pyDev. But I'm unable to simply get my first url to display.</p>
<p>This urls.py is from the Cr package.</p>
<pre><code>from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index')
]
</code></pre>
<p>This urls... | 0 | 2016-08-14T20:34:21Z | 38,946,409 | <p>Can we see your settings.py file? There is a place in there where you define your project's url file. I'm assuming it's right now either not there or it's pointing to the wrong place, because Django can't find your urls.py file.</p>
<p>For example, in my settings.py file for one of my projects, I have:</p>
<pre><c... | 0 | 2016-08-14T20:38:54Z | [
"python",
"django"
] |
Django, url not found? | 38,946,371 | <p>I'm trying out Python Django. With eclipse pyDev. But I'm unable to simply get my first url to display.</p>
<p>This urls.py is from the Cr package.</p>
<pre><code>from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index')
]
</code></pre>
<p>This urls... | 0 | 2016-08-14T20:34:21Z | 38,946,479 | <pre><code>from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'Crowd/', include('Cr.urls'))
</code></pre>
<p>]</p>
<p>just use this urls.py file </p>
| 0 | 2016-08-14T20:48:25Z | [
"python",
"django"
] |
Python 3.4 Dice Rolling Simulator Code Error | 38,946,377 | <p>So I have my code here for a dice rolling simulator game that I am creating using PyDev in Eclipse Neon Python 3.4. Where you guess a number and a number from 1-6 will randomly generate and if you get the number right, you move on, etc.</p>
<pre><code>guess1 = input("Enter your first guess as to which side the dice... | -1 | 2016-08-14T20:35:14Z | 38,946,400 | <p><code>print()</code> returns <code>None</code>. If you print <code>game</code> after that line you will see it's value. To fix:</p>
<pre><code>game = random.choice(dice_side)
</code></pre>
| 1 | 2016-08-14T20:37:56Z | [
"python",
"eclipse",
"python-3.4"
] |
Python 3.4 Dice Rolling Simulator Code Error | 38,946,377 | <p>So I have my code here for a dice rolling simulator game that I am creating using PyDev in Eclipse Neon Python 3.4. Where you guess a number and a number from 1-6 will randomly generate and if you get the number right, you move on, etc.</p>
<pre><code>guess1 = input("Enter your first guess as to which side the dice... | -1 | 2016-08-14T20:35:14Z | 38,946,571 | <p>In order to understand why your game isn't working you should try to understand first what's wrong with this line <code>game = print(random.choice(dice_side))</code>. Here's a modified version of your game which will give you some clues, try to run it and understand it, then just review your script:</p>
<pre><code>... | 0 | 2016-08-14T20:57:41Z | [
"python",
"eclipse",
"python-3.4"
] |
python selenium log number of times page refreshes | 38,946,423 | <p>I want to know if there is any way to log the number of times my page has refreshed in command prompt when running. </p>
<p>want it to tell me the number of times it has refreshed. Refresh is located between while true: and continue. thanks </p>
<pre><code>driver = webdriver.Chrome(chrome_path)
driver.get(link)
w... | 0 | 2016-08-14T20:40:46Z | 38,948,046 | <p>the answer to my question was very simple...</p>
<pre><code>driver = webdriver.Chrome(chrome_path)
driver.get(link)
count = 0
while True:
size = driver.find_elements_by_xpath(".//*[@id='atg_store_picker']/div/div[2]/div[1]/div[1]/span[2]/a[4]")
if len(size) <= 0:
count +=1
print 'Refresh ... | 1 | 2016-08-15T01:02:48Z | [
"python",
"selenium"
] |
Select Days from Pandas DataFrame | 38,946,472 | <p>I have a Pandas DataFrame like this:</p>
<pre>
ââââââââââââââ¦ââââââââ
â DATE â VALUE â
â âââââââââââââ¬ââââââââ£
â 2011-01-07 â 1 â
â âââââââââââââ¬ââââââââ£
â 2011-0... | -1 | 2016-08-14T20:47:23Z | 38,946,920 | <p>You can create a consecutive id column so that each date has a unique id which increases with the date and then subset based on the id column:</p>
<pre><code>import pandas as pd
# sort the `DATE` column and create an id for each date
df['DATE'] = pd.to_datetime(df.DATE).sort_values()
df['DateId'] = df.groupby('DATE... | 2 | 2016-08-14T21:50:00Z | [
"python",
"pandas",
"dataframe"
] |
Select Days from Pandas DataFrame | 38,946,472 | <p>I have a Pandas DataFrame like this:</p>
<pre>
ââââââââââââââ¦ââââââââ
â DATE â VALUE â
â âââââââââââââ¬ââââââââ£
â 2011-01-07 â 1 â
â âââââââââââââ¬ââââââââ£
â 2011-0... | -1 | 2016-08-14T20:47:23Z | 38,947,251 | <p>Try this using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.ix.html" rel="nofollow">pandas.ix</a>
Hint: <code>df.ix(start, stop)</code></p>
<pre><code>df['Date'] =pd.to_datetime(df['Date']).sort_values()
df.ix[df[df.Date =='2011-01-20'].index[0]-2: max(df[df.Date =='2011-01-20'].... | 0 | 2016-08-14T22:41:42Z | [
"python",
"pandas",
"dataframe"
] |
Pandas manipulate dataframe | 38,946,492 | <p>I am querying a database and populating a pandas dataframe. I am struggling to aggregate the data (via groupby) and then manipulate the dataframe index such that the dates in the table become the index.
Here is an example of how the data looks like before and after the groupby and what I ultimately am looking for.</... | 0 | 2016-08-14T20:50:35Z | 38,946,607 | <p>You can use <code>stack</code>(<code>unstack</code>) to transform data from long to wide(wide to long) format:</p>
<pre><code>import pandas as pd
# calculate the total received and sent grouped by dates
df1 = df.drop('firm', axis = 1).groupby('dates').sum().reset_index()
# add total category as the firm column
df1... | 0 | 2016-08-14T21:02:15Z | [
"python",
"datetime",
"pandas",
"data-manipulation"
] |
Referencing a table in web2py before defining it | 38,946,510 | <p>My code is the following im trying to assign a department to employees and also create a manager in a department table</p>
<pre><code>db = DAL(lazy_tables=True)
db.define_table('employee',
Field('fullname','string',label='Name'),
Field('email','string'),
Field('phone','string'),
... | 0 | 2016-08-14T20:52:07Z | 38,948,788 | <pre><code> Field('department', 'reference department',
requires=IS_IN_DB(db, db.department.id, '%(department_name)s')),
</code></pre>
<p>In the above line, you reference <code>db.department.id</code>, but the <code>department</code> table has not yet been defined, so the <code>db</code> object will not y... | 1 | 2016-08-15T03:07:42Z | [
"python",
"web2py"
] |
Referencing a table in web2py before defining it | 38,946,510 | <p>My code is the following im trying to assign a department to employees and also create a manager in a department table</p>
<pre><code>db = DAL(lazy_tables=True)
db.define_table('employee',
Field('fullname','string',label='Name'),
Field('email','string'),
Field('phone','string'),
... | 0 | 2016-08-14T20:52:07Z | 39,027,729 | <p>If you remove the 2nd <code>db = DAL(lazy_tables=True)</code>, you should be fine.</p>
<p>The problem you have is that you essentially overwrote the first db object by declaring/instantiating it again after the first table definition (employee). </p>
<p>This gives you a new db object (with no tables defined) in wh... | 0 | 2016-08-18T21:23:58Z | [
"python",
"web2py"
] |
AttributeError: 'tuple' object has no attribute 'copy' | 38,946,556 | <p>Can any one explain this error message to me?</p>
<pre><code># make a copy or hand is destroyed by your test
remaining = hand.copy()
</code></pre>
<p>Result:</p>
<pre><code>AttributeError: 'tuple' object has no attribute 'copy'
</code></pre>
<p>I can do this:</p>
<pre><code>remaining = copy.copy(hand)
</code></... | -1 | 2016-08-14T20:56:39Z | 38,946,578 | <p>The error is very clear: You have a tuple, on which you try to call <code>copy</code>. </p>
<p>It seems that the object you have in <code>hand</code> is not the object you intended, but a tuple, instead. </p>
| 1 | 2016-08-14T20:58:49Z | [
"python",
"copy",
"attributeerror"
] |
Python 2.7.10 Pygame 1.9.1. I'm trying to change the values of a list by 5 either increasing or decreasing | 38,946,599 | <pre><code>import pygame, sys, random, math, os
from random import randint, uniform
from pygame.locals import*
from locations import*
pygame.init()
brick=pygame.image.load("resources/images/brick.png")
cave_block=pygame.image.load("resources/images/cave_block1.jpg")
background=pygame.image.load("resources/images/bg.pn... | 0 | 2016-08-14T21:00:59Z | 38,961,242 | <p><code>cave_block1S_pos[0] -= 5</code> is the same as <code>cave_block1S_pos[0] = cave_block1S_pos[0] - 5</code>, which in your case is <code>cave_block1S_pos[0] = (0, 0) - 5</code>. You cannot subtract 5 from a tuple, hence gets the error <code>TypeError: unsupported operand type(s) for -=: 'tuple' and 'int'</code><... | 0 | 2016-08-15T18:57:00Z | [
"python",
"windows",
"pygame"
] |
Having trouble with a python bezier surface plot- keeps returning an empty plot | 38,946,639 | <p>I'm trying to plot a Bezier surface in matplotlib. I have my functions for x,y, and z (I didnt type them out, I had sympy automatically generate them) but whenever I run my code, I just get a blank plot. By the way, px, py, and pz refer to matrix of control points. Can anyone tell me what I did wrong and what I ne... | 0 | 2016-08-14T21:06:42Z | 38,946,791 | <p>Here's a couple of examples to plot bezier curves with matplotlib:</p>
<p><strong>EXAMPLE1</strong></p>
<p>From <a href="http://stackoverflow.com/a/12644499/3809375">stackoverflow</a></p>
<pre><code>import numpy as np
from scipy.misc import comb
from matplotlib import pyplot as plt
def bernstein_poly(i, n, t):
... | 0 | 2016-08-14T21:29:32Z | [
"python",
"matplotlib"
] |
Erase part of image on Tkinter canvas, exposing another image underneath | 38,946,666 | <p>(Python 2.7). I have a Tkinter canvas with two images that are both the height and width of the canvas, so they cover the whole window. One image is on top of the other. I want to, using the mouse, be able to erase part of the top image wherever I want, thus exposing the bottom image. Is this possible?</p>
<p>I'm c... | 1 | 2016-08-14T21:11:32Z | 38,957,833 | <p>Thanks to @martineau for the suggestions! Here is the working code.</p>
<pre><code>from PIL import Image, ImageTk
import Tkinter as tk
#Image 2 is on top of image 1.
IMAGE1_DIR = "C:/path/image1.PNG"
IMAGE2_DIR = "C:/path/image2.PNG"
#Brush size in pixels.
BRUSH = 5
#Actual size is 2*BRUSH
def create_image(filen... | 1 | 2016-08-15T15:11:18Z | [
"python",
"python-2.7",
"canvas",
"tkinter"
] |
re.sub not matching nested dictionary | 38,946,697 | <p>with the following dict:</p>
<pre><code>interfaces = {'A':{'568':'A1','590':'A2'},'B':{'590':'B2'}}
</code></pre>
<p>i what to replace the value='590' with A2 while setting the A element and B2 while setting the B element.</p>
<p>I've tried :</p>
<pre><code>pattern_interfaces = r'\b({})\b'.format('|'.join(sorted... | -1 | 2016-08-14T21:16:15Z | 38,946,875 | <p>You matched keys from <code>interfaces['A']</code>, not from <code>interfaces</code>. Use that nested dictionary if you are going to generate a regex from that keys :</p>
<pre><code>re_value = re.sub(
pattern_interfaces,
lambda m: interfaces['A'][m.group(0).upper()],
value, flags=re.IGNORECASE)
</code><... | 0 | 2016-08-14T21:43:06Z | [
"python",
"dictionary"
] |
Using Random to call a dictionary from a different class | 38,946,716 | <p>I'm making a small game and I'm trying to have the EncounterM class get a random Monster and Dmg from the monster class dictionary. (New at Python) </p>
<pre><code> class Monster:
monster_health = {'goblin': 15, 'giant': 50}
monster_damage = {'goblin': 3, 'giant': 1}
class EncounterM(Monster):... | -2 | 2016-08-14T21:18:09Z | 38,946,753 | <p>I'll ignore the not-working-at-all object constructions to focus on your question. Read more about object, instances, classes and post another question.
(Edit: I couldn't resist to change it a little to make it a little more object-like, but I won't go further)</p>
<p>With Python 3, <code>keys()</code> do not retur... | 1 | 2016-08-14T21:23:05Z | [
"python",
"dictionary"
] |
Python on Zapier issue | 38,946,834 | <p>Any Ideas what I am doing wrong it won't run!</p>
<p><a href="http://i.stack.imgur.com/pux3J.png" rel="nofollow"><img src="http://i.stack.imgur.com/pux3J.png" alt="enter image description here"></a></p>
| -4 | 2016-08-14T21:35:48Z | 39,008,787 | <p>Don't forget your <code>:</code> at the end of your if statement!</p>
| 0 | 2016-08-18T01:52:52Z | [
"python",
"zapier"
] |
Using shutil.rmtree() in a recursive function (Windows 10) | 38,947,001 | <p>I am encountering an error that can probably be worked around but conceptually confusing to me and wondering if someone could shed some light.</p>
<p>When I recurse through directory structure calling shutil.rmtree() under certain condition, I get an error that amounts to an attempt to delete an already deleted obj... | 1 | 2016-08-14T22:02:25Z | 38,949,679 | <p>I think, your problem can be linked with this one: <a href="http://stackoverflow.com/questions/16373747/permission-denied-doing-os-mkdird-after-running-shutil-rmtreed-in-python">Permission denied doing os.mkdir(d) after running shutil.rmtree(d) in Python</a></p>
<p><code>shutil.rmtree</code> on Windows happens to r... | 0 | 2016-08-15T05:20:54Z | [
"python",
"windows",
"python-2.7",
"recursion",
"shutil"
] |
Read data from qabstractitemmodel via qdatawidgetmapper with BackgroundRole | 38,947,141 | <p>I have the following question reagrding Qt (using PyQt 5):</p>
<p>I have modified one of the examples which I found for QDataWidgetMapper and QAbstractTableModel and added an additional if-clause for the role Qt.BackgroundRole to the data method.</p>
<p>The goal is to get different background colors depending on t... | 0 | 2016-08-14T22:22:26Z | 39,067,439 | <p>I have found the simple solution: I have to work with custom delegates to solve the problem.</p>
<pre><code>class LineDelegate(QStyledItemDelegate):
def __init__(self, parent = None):
QStyledItemDelegate.__init__(self, parent)
def createEditor(self, parent, option, index):
pass
def se... | 0 | 2016-08-21T18:18:18Z | [
"python",
"qt",
"pyqt",
"pyqt5"
] |
ImportError: cannot import name App | 38,947,154 | <p>I am trying to follow the tutorial on <a href="https://www.youtube.com/watch?v=CYNWK2GpwgA&list=PLQVvvaa0QuDe_l6XiJ40yGTEqIKugAdTy&index=1" rel="nofollow">this youtube video</a>.</p>
<p>But <code>from kivy import App</code> gives <code>ImportError: cannot import name App</code>. How can I fix this?</p>
<p>... | 0 | 2016-08-14T22:24:31Z | 38,947,166 | <p>Try <code>from kivy.app import App</code> (<a href="https://kivy.org/docs/api-kivy.app.html" rel="nofollow">documentation</a>).</p>
| 3 | 2016-08-14T22:26:31Z | [
"python",
"kivy"
] |
Why am I getting the error message name 'datestr' is not defined? Python 2.7 | 38,947,170 | <p>So datestr() is supposed to convert a number into a date. But I keep getting this Name error message. Am I not loading the correct module. I have searched the Matplotlib documenation but do not see any specific module that must be imported. </p>
<pre><code>import matplotlib.pyplot as plt
from matplotlib.dates ... | 0 | 2016-08-14T22:27:35Z | 38,947,356 | <p>Yes I was not using the correct function. I did a search on the problem and I ran into the soltution I tried above the correct format is below.</p>
<pre><code>from datetime import date
dte = 731613
print date.fromordinal(dte)
#out put is >> 2004-02-02
# (Year, Month, day)
</code></pre>
| 0 | 2016-08-14T22:58:48Z | [
"python",
"matplotlib"
] |
Why am I getting the error message name 'datestr' is not defined? Python 2.7 | 38,947,170 | <p>So datestr() is supposed to convert a number into a date. But I keep getting this Name error message. Am I not loading the correct module. I have searched the Matplotlib documenation but do not see any specific module that must be imported. </p>
<pre><code>import matplotlib.pyplot as plt
from matplotlib.dates ... | 0 | 2016-08-14T22:27:35Z | 38,947,358 | <p>It looks like you want the function <code>mathplotlib.dates.num2date()</code>. From there you can convert to a string with <code>str()</code> or <code>strftime()</code>:</p>
<pre><code>>>> from matplotlib.dates import num2date
>>> num2date(731613)
datetime.datetime(2004, 2, 2, 0, 0, tzinfo=<mat... | 1 | 2016-08-14T22:59:05Z | [
"python",
"matplotlib"
] |
df.mean is not the real mean of the Series? | 38,947,278 | <p>I'm debugging and run into the following strange behavior.
I'm calculating the mean of a pandas series which contains all exactly the same numbers. However, the <code>pd.mean()</code> gives a different number.</p>
<p>question1: why mean of this Series is a different number?</p>
<p>question2: <code>tmm[-1]== tmm.me... | 1 | 2016-08-14T22:46:30Z | 38,947,348 | <p>The answer to your 2 questions is basically this:</p>
<pre><code>import pandas as pd
import decimal
tmm = pd.Series(decimal.Decimal(14.9199999999999999289457264239899814128875732421875),
index=range(30))
for t in tmm:
print(decimal.Decimal(t))
print('mean is')
print(decimal.Decimal(tmm.mean()))... | 0 | 2016-08-14T22:57:18Z | [
"python",
"pandas"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.