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 |
|---|---|---|---|---|---|---|---|---|---|
Unexpected number of decimal places and Syntactical Query | 39,577,927 | <p>I'm trying to find the intersection between the curves $ y= x^2+3x+2 $ and $ y=x^2+2x+1$. For this, I have written the following python program:</p>
<pre><code>from numpy import *
import numpy as np
for x in np.arange(-100, 100, 0.0001):
y_1=x**2+3*x+2
y_2=x**2+2*x+1
if round(y_1, 5)==round(y_2,5):
... | 1 | 2016-09-19T16:33:45Z | 39,578,038 | <ol>
<li>Because the <code>y_1</code> and <code>y_2</code> lines are computing specific values, not defining functions. Plain Python does not have a built-in concept of symbolic equations. (Although you can implement symbolic equations various ways.)</li>
<li>Because binary floating-point, as used in Python, cannot e... | 2 | 2016-09-19T16:39:12Z | [
"python",
"numpy"
] |
Unexpected number of decimal places and Syntactical Query | 39,577,927 | <p>I'm trying to find the intersection between the curves $ y= x^2+3x+2 $ and $ y=x^2+2x+1$. For this, I have written the following python program:</p>
<pre><code>from numpy import *
import numpy as np
for x in np.arange(-100, 100, 0.0001):
y_1=x**2+3*x+2
y_2=x**2+2*x+1
if round(y_1, 5)==round(y_2,5):
... | 1 | 2016-09-19T16:33:45Z | 39,578,105 | <p>1) First you have (probably) redundant import statements:</p>
<pre><code>from numpy import *
import numpy as np
</code></pre>
<p>The first statement imports the <code>__all__</code> variable from the package the second statement imports the numpy package then aliases it as <code>np</code>. The normal convention is... | 1 | 2016-09-19T16:43:23Z | [
"python",
"numpy"
] |
Bokeh line graph looping | 39,577,944 | <p>Iâve been working on bokeh plots and Iâm trying to plot a line graph taking values from a database. But the plot kind of traces back to the initial point and I donât want that. I want a plot which starts at one point and stops at a certain point (and circle back). Iâve tried plotting it on other tools like S... | 0 | 2016-09-19T16:34:33Z | 39,578,847 | <p>Bokeh does not "auto-close" lines. You can see this is the case by looking at any number of examples in the docs and repository, but here is one in particular:</p>
<p><a href="http://bokeh.pydata.org/en/latest/docs/gallery/stocks.html" rel="nofollow">http://bokeh.pydata.org/en/latest/docs/gallery/stocks.html</a></p... | 0 | 2016-09-19T17:27:56Z | [
"python",
"bokeh"
] |
How to multiply without the * sign using recursion? | 39,577,950 | <p>so as homework for a programming class on python we're supposed to multiply to integers (n,m) with each other WITHOUT using the * sign (or another multiplication form). We're supposed to use recursion to solve this problem, so i tried just adding n with itself, m number of times. I think my problem is with using rec... | -4 | 2016-09-19T16:35:00Z | 39,578,224 | <p>I don't want to give you the answer to your homework here so instead hopefully I can provide an example of recursion that may help you along :-). </p>
<pre><code># Here we define a normal function in python
def count_down(val):
# Next we do some logic, in this case print the value
print(val)
# Now we c... | 1 | 2016-09-19T16:50:02Z | [
"python",
"recursion"
] |
How to multiply without the * sign using recursion? | 39,577,950 | <p>so as homework for a programming class on python we're supposed to multiply to integers (n,m) with each other WITHOUT using the * sign (or another multiplication form). We're supposed to use recursion to solve this problem, so i tried just adding n with itself, m number of times. I think my problem is with using rec... | -4 | 2016-09-19T16:35:00Z | 39,579,125 | <p>You have the right mechanics, but you haven't internalized the basics you found in your searches. A recursive function usually breaks down to two cases:</p>
<ol>
<li>Base Case --
How do you know when you're done? What do you want to do at that point?</li>
</ol>
<p>Here, you've figured out that your base case is ... | 0 | 2016-09-19T17:44:27Z | [
"python",
"recursion"
] |
How to multiply without the * sign using recursion? | 39,577,950 | <p>so as homework for a programming class on python we're supposed to multiply to integers (n,m) with each other WITHOUT using the * sign (or another multiplication form). We're supposed to use recursion to solve this problem, so i tried just adding n with itself, m number of times. I think my problem is with using rec... | -4 | 2016-09-19T16:35:00Z | 39,579,172 | <p>Thanks guys, i figured it out!!!
i had to return 0 instead of 1, otherwise the answer would always be one higher than what we wanted.
and i understand how you have to call upon the function, which is the main thing i missed.
Here's what i did:</p>
<pre><code> def mult(n,m):
""" mult outputs the product o... | 0 | 2016-09-19T17:47:12Z | [
"python",
"recursion"
] |
Raspberry LCD IP display format | 39,577,970 | <p>I'm working on a little project with a Raspberry Pi, and I need to display the IP adress of the PI on an LCD screen. </p>
<p>I followed this tutorial :
<a href="https://learn.adafruit.com/drive-a-16x2-lcd-directly-with-a-raspberry-pi/python-code" rel="nofollow">https://learn.adafruit.com/drive-a-16x2-lcd-directly-w... | 1 | 2016-09-19T16:35:55Z | 39,583,212 | <p>I found the <code>netifaces</code> package to be useful for obtaining the IP address. The link below explains well about its basic usage</p>
<p><a href="https://pypi.python.org/pypi/netifaces" rel="nofollow">https://pypi.python.org/pypi/netifaces</a></p>
<p>Below is an example to obtain the ip address in the pytho... | 0 | 2016-09-19T22:49:42Z | [
"python",
"raspberry-pi",
"ip",
"lcd"
] |
What is "pkg-resources==0.0.0" in output of pip freeze command | 39,577,984 | <p>When I run <code>pip freeze</code> I see (among other expected packages) <code>pkg-resources==0.0.0</code>. I have seen a few posts mentioning this package (including <a href="https://stackoverflow.com/questions/38992194/why-does-pip-freeze-list-pkg-resources-0-0-0">this one</a>), but none explaining what it is, or ... | 4 | 2016-09-19T16:36:39Z | 39,638,060 | <p>As for the part of your question "is it OK to remove this line":</p>
<p>I have the same issue here developing on an ubuntu 16.04 with that very line in the requirements. When deploying on a debian 8.5 running <code>"pip install -r requirements.txt"</code> pip complains that pkg-resources is "not found" but there i... | 1 | 2016-09-22T11:42:41Z | [
"python",
"python-3.x",
"pip",
"ubuntu-16.04"
] |
Dropdown menus in python / selenium | 39,578,022 | <p>Trying to autofill a form using python and selenium. Dropdown menu html is:</p>
<pre><code><select id="typeOfTeacher" class="chosen-select-no-single ng-untouched ng-dirty ng-valid-parse ng-valid ng-valid-required" required="" ng-class="{ 'has-error' : positionDetailForm.typeOfTeacher.$invalid && !positio... | 0 | 2016-09-19T16:38:25Z | 39,578,280 | <p>I have not used the python Select method, but I would guess that the error message means that the menu is not being opened, and therefore an element in the menu is still hidden and cannot be interacted with.</p>
<p>Try something like this:</p>
<pre><code>element = driver.find_element_by_id('typeOfTeacher').click()... | 0 | 2016-09-19T16:53:44Z | [
"python",
"selenium",
"selenium-webdriver"
] |
Dropdown menus in python / selenium | 39,578,022 | <p>Trying to autofill a form using python and selenium. Dropdown menu html is:</p>
<pre><code><select id="typeOfTeacher" class="chosen-select-no-single ng-untouched ng-dirty ng-valid-parse ng-valid ng-valid-required" required="" ng-class="{ 'has-error' : positionDetailForm.typeOfTeacher.$invalid && !positio... | 0 | 2016-09-19T16:38:25Z | 39,578,581 | <p>This would work</p>
<pre><code>element = driver.find_element_by_id('typeOfTeacher').click()
element.find_element_by_xpath(".//option[@value='1']").click()
</code></pre>
| 0 | 2016-09-19T17:12:19Z | [
"python",
"selenium",
"selenium-webdriver"
] |
Dropdown menus in python / selenium | 39,578,022 | <p>Trying to autofill a form using python and selenium. Dropdown menu html is:</p>
<pre><code><select id="typeOfTeacher" class="chosen-select-no-single ng-untouched ng-dirty ng-valid-parse ng-valid ng-valid-required" required="" ng-class="{ 'has-error' : positionDetailForm.typeOfTeacher.$invalid && !positio... | 0 | 2016-09-19T16:38:25Z | 39,579,423 | <p>It looks like timing issue. You should try using <a href="http://selenium-python.readthedocs.io/waits.html#waits" rel="nofollow">Waits</a>. </p>
<p>I would suggest you, use <code>WebDriverWait</code> to wait until dropdown visible before interaction as below :-</p>
<pre><code>from selenium import webdriver
from se... | 0 | 2016-09-19T18:02:25Z | [
"python",
"selenium",
"selenium-webdriver"
] |
How to delete existing file when user uploads a new one | 39,578,087 | <p>I've just successfully implemented a method similar to the one that Giles suggested for saving new images with a filename of the primary key of the model here:
<a href="http://stackoverflow.com/a/16574947/5884437">http://stackoverflow.com/a/16574947/5884437</a></p>
<p>Actual code used:</p>
<pre><code>class Asset(m... | 3 | 2016-09-19T16:42:20Z | 39,578,883 | <p>You can attempt to delete the old image when it doens't match the newly sumbitted image:</p>
<pre><code>class Asset(models.Model):
asset_id = models.AutoField(primary_key=True)
asset_image = models.ImageField(upload_to = 'images/temp', max_length=255, null=True, blank=True)
def save( self, *args, **kwa... | 2 | 2016-09-19T17:30:27Z | [
"python",
"django",
"django-models"
] |
Killing stdout in python breaks get_line_buffer() | 39,578,088 | <p>So I'm using some libraries that (unfortunately and much to my chagrin) print to stdout for certain debug info. Okay, no problem, I just disabled it with:</p>
<pre><code>import sys,os
sys.stdout = open(os.devnull,'wb')
</code></pre>
<p>I've recently added code for getting user input and printing output in the term... | 4 | 2016-09-19T16:42:21Z | 39,844,597 | <p>Its the <code>raw_input()</code> that stops working when you redirect the stdout.
If you try <code>sys.stdout = sys.__stdout__</code> just before the <code>raw_input()</code> it works again.
Both <code>stdin</code> and <code>stdout</code> need to be connected to the terminal in order for <code>raw_input</code> to w... | 1 | 2016-10-04T05:13:22Z | [
"python",
"multithreading",
"stdout",
"raw-input"
] |
Nested For Loop with Unequal Entities | 39,578,130 | <p>I would like to scrape the contents of a website with a similar structure to</p>
<p><a href="https://www.wellstar.org/locations/pages/default.aspx" rel="nofollow">https://www.wellstar.org/locations/pages/default.aspx</a></p>
<p>Using the provided website as a framework, I would like to extract the location's name ... | 0 | 2016-09-19T16:44:49Z | 39,578,499 | <p>You need a way to group the locations by name. For this, we separate each block, get the title and locations collected into a dictionary:</p>
<pre><code>from pprint import pprint
import requests
from bs4 import BeautifulSoup
url = "https://www.wellstar.org/locations/pages/default.aspx"
response = requests.get(url... | 1 | 2016-09-19T17:07:46Z | [
"python",
"web-scraping",
"beautifulsoup"
] |
Python How to print dictionary in one line? | 39,578,141 | <p>Hi I am new to Python and I am struggling regarding how to print dictionary.</p>
<p>I have a dictionary as shown below.</p>
<pre><code>dictionary = {a:1,b:1,c:2}
</code></pre>
<p>How can I print dictionary in one line as shown below?</p>
<pre><code>a1b1c2
</code></pre>
<p>I want to print keys and values in one ... | -1 | 2016-09-19T16:45:34Z | 39,578,258 | <p>With a dictionary, e.g. </p>
<pre><code>dictionary = {'a':1,'b':1,'c':2}
</code></pre>
<p>You could try:</p>
<pre><code>print ''.join(['{0}{1}'.format(k, v) for k,v in dictionary.iteritems()])
</code></pre>
<p>Resulting in</p>
<blockquote>
<p>a1c2b1</p>
</blockquote>
<p>If order matters, try using an <a href... | 1 | 2016-09-19T16:51:43Z | [
"python",
"python-2.7",
"dictionary",
"printing"
] |
Python How to print dictionary in one line? | 39,578,141 | <p>Hi I am new to Python and I am struggling regarding how to print dictionary.</p>
<p>I have a dictionary as shown below.</p>
<pre><code>dictionary = {a:1,b:1,c:2}
</code></pre>
<p>How can I print dictionary in one line as shown below?</p>
<pre><code>a1b1c2
</code></pre>
<p>I want to print keys and values in one ... | -1 | 2016-09-19T16:45:34Z | 39,578,281 | <p>If you want a string to contain the answer, you could do this:</p>
<pre><code>>>> dictionary = {'a':1,'b':1,'c':2}
>>> result = "".join(str(key) + str(value) for key, value in dictionary.items())
>>> print(result)
c2b1a1
</code></pre>
<p>This uses the join method on an empty string. Dict... | 1 | 2016-09-19T16:53:46Z | [
"python",
"python-2.7",
"dictionary",
"printing"
] |
Django return JSON with Logged in Cookie | 39,578,430 | <p>I want to design a simple Django "RESTful" API without the need of using django-rest-framework.</p>
<p>The endpoint is <code>/api/login</code> which accept only POST method with <code>username</code> and <code>password</code> in json. I want it to return <code>{"status" : 0}</code> for success with the session cook... | 0 | 2016-09-19T17:03:20Z | 39,581,113 | <p>I tested it out, that I can just use <code>return JsonResponse({'status' : 0})</code> because the cookies are registered with Django because of <code>authenticate</code>.</p>
| 0 | 2016-09-19T19:59:12Z | [
"python",
"json",
"django",
"cookies"
] |
pandas date to string | 39,578,466 | <p>i have a datetime <code>pandas.Series</code>. One column called "dates". I want to get 'i' element in loop like string.</p>
<p><code>s.apply(lambda x: x.strftime('%Y.%m.%d'))</code> or
<code>astype(str).tail(1).reset_index()['date']</code> or many other solutions don't work.</p>
<p>I just want a string like <code>... | 1 | 2016-09-19T17:05:50Z | 39,578,549 | <p>In order to extract the value, you can try:</p>
<pre><code>ss = series_of_dates.astype(str).tail(1).reset_index().loc[0, 'date']
</code></pre>
<p>using <code>loc</code> will give you the contents just fine.</p>
| 1 | 2016-09-19T17:10:42Z | [
"python",
"datetime",
"pandas",
"time-series"
] |
pandas date to string | 39,578,466 | <p>i have a datetime <code>pandas.Series</code>. One column called "dates". I want to get 'i' element in loop like string.</p>
<p><code>s.apply(lambda x: x.strftime('%Y.%m.%d'))</code> or
<code>astype(str).tail(1).reset_index()['date']</code> or many other solutions don't work.</p>
<p>I just want a string like <code>... | 1 | 2016-09-19T17:05:50Z | 39,578,709 | <p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.strftime.html" rel="nofollow"><code>strftime</code></a> for convert <code>datetime</code> column to <code>string</code> column:</p>
<pre><code>import pandas as pd
start = pd.to_datetime('2015-02-24 10:00')
rng = pd.... | 1 | 2016-09-19T17:19:39Z | [
"python",
"datetime",
"pandas",
"time-series"
] |
Using `apply` on datetime64 series in pandas | 39,578,495 | <p>I have a Series of <code>datetime64[ns]</code> objects. I would like to apply <code>strftime('%d-%m-%Y')</code> to all of them, for reversing the order of year,day,month. I tried using:</p>
<pre><code>series.apply(time.strftime('%d-%m-%Y'))
</code></pre>
<p>But I get the error:</p>
<blockquote>
<p>TypeError: 's... | 2 | 2016-09-19T17:07:31Z | 39,578,511 | <p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.strftime.html" rel="nofollow"><code>Series.dt.strftime</code></a>:</p>
<pre><code>series.dt.strftime('%d-%m-%Y')
</code></pre>
<p>Or if is necessary convert <code>Series</code> <a href="http://pandas.pydata.org/pand... | 3 | 2016-09-19T17:08:25Z | [
"python",
"python-3.x",
"pandas",
"numpy",
"strftime"
] |
issue with create_user.py in django-cms | 39,578,498 | <p>I just started using django-cms and am facing issues. I used virtualenv.please help.The following is the error:</p>
<pre><code>Traceback (most recent call last):
File "create_user.py", line 4, in <module>
from django.contrib.auth import get_user_model
File "/home/mayankmodi/SSAD18/Source/env/local/l... | 2 | 2016-09-19T17:07:45Z | 39,608,259 | <p>Try running this command instead:</p>
<pre><code>djangocms -w web
</code></pre>
<p>This will start the djangocms-installer wizard and run you through various settings, dependencies, and create a superuser for you to log in with. When it finishes, you should have a running instance of django-cms within <code>./web/... | 1 | 2016-09-21T05:35:00Z | [
"python",
"django",
"virtualenv",
"django-cms"
] |
issue with create_user.py in django-cms | 39,578,498 | <p>I just started using django-cms and am facing issues. I used virtualenv.please help.The following is the error:</p>
<pre><code>Traceback (most recent call last):
File "create_user.py", line 4, in <module>
from django.contrib.auth import get_user_model
File "/home/mayankmodi/SSAD18/Source/env/local/l... | 2 | 2016-09-19T17:07:45Z | 39,628,304 | <p>I have same problem from a few week ago. I assume the new version(djangocms-installer==0.9.x) have problem because when I created a project using default djangocms-installer(==0.9.0) like "djangcms -p . mysite", there was no questions about DB, django version, or etc, then error...</p>
<p>Try old version "pip insta... | 1 | 2016-09-22T00:09:17Z | [
"python",
"django",
"virtualenv",
"django-cms"
] |
Parallel random distribution | 39,578,568 | <p>I have two iterators in python and both should follow the same "random" distribution <strong>(both should run in parallel)</strong>. For instance:</p>
<pre><code>class Iter1(object):
def __iter__(self):
for i in random_generator():
yield i
class Iter2(object):
def __iter__(self):
for ... | 0 | 2016-09-19T17:11:39Z | 39,578,737 | <p>There is no way to control the random generation number in this way. If you want to do that you should create your own random function. But as another pythonic and simpler way you can just create one object and use <code>itertools.tee</code> in order to copy your iterator object to having the same result for your ra... | 0 | 2016-09-19T17:20:49Z | [
"python",
"random",
"iterator",
"generator"
] |
Parallel random distribution | 39,578,568 | <p>I have two iterators in python and both should follow the same "random" distribution <strong>(both should run in parallel)</strong>. For instance:</p>
<pre><code>class Iter1(object):
def __iter__(self):
for i in random_generator():
yield i
class Iter2(object):
def __iter__(self):
for ... | 0 | 2016-09-19T17:11:39Z | 39,579,168 | <p>Specify the same seed to each call of <code>random_generator</code>:</p>
<pre><code>import random
def random_generator(l, seed=None):
r = random.Random(seed)
for i in range(l):
yield r.random()
class Iter1(object):
def __init__(self, seed):
self.seed = seed
def __iter__(self):
... | 2 | 2016-09-19T17:46:59Z | [
"python",
"random",
"iterator",
"generator"
] |
Update Pandas dataframe value based on present value | 39,578,656 | <p>I have a Pandas dataframe with values which should lie between, say, <code>11-100</code>. However, sometimes I'll have values between <code>1-10</code>, and this is because the person who was entering that row used a convention that the value in question should be multiplied by 10. So what I'd like to do is run a Pa... | 1 | 2016-09-19T17:16:47Z | 39,578,688 | <p>I think you can use:</p>
<pre><code>my_dataframe[my_dataframe['column_name']<10] *= 10
</code></pre>
| 3 | 2016-09-19T17:18:35Z | [
"python",
"pandas",
"indexing",
"dataframe",
"multiplying"
] |
Python Battleship random number generator | 39,578,807 | <p>I'm fairly new to classes in Python. While coding a battleship game I ran into a problem with choosing random x,y coordinates for the locations of computer's ships and the computer's attack coordinates. I am confused about whether to generate random numbers as a local variable in one of the functions or as Class att... | 0 | 2016-09-19T17:25:38Z | 39,579,079 | <p>To get a random number maybe you could import the random library.</p>
<p>You could use it to initialize your (X, Y) coordenates on an instance of your class.</p>
<pre><code>import random
Battleship(size, numberships, random.randint(0, WIDTH), random.randint(0, HEIGHT))
</code></pre>
<p>I'm assuming you have the ... | 0 | 2016-09-19T17:41:58Z | [
"python"
] |
Python Battleship random number generator | 39,578,807 | <p>I'm fairly new to classes in Python. While coding a battleship game I ran into a problem with choosing random x,y coordinates for the locations of computer's ships and the computer's attack coordinates. I am confused about whether to generate random numbers as a local variable in one of the functions or as Class att... | 0 | 2016-09-19T17:25:38Z | 39,579,293 | <p>I think it's because you're calling <code>random.choice</code> with <code>size</code> and not <code>self.size</code>.</p>
<p>i.e.</p>
<pre><code>rand_x = random.choice(range(self.size))
</code></pre>
<p>Also, where are you defining <code>self.rand</code>? Surely you're getting problems in the constructor trying t... | 2 | 2016-09-19T17:54:26Z | [
"python"
] |
how to add a row to a Datetime Multiindex Panda Dataframe | 39,578,866 | <blockquote>
<p>How would I go about adding a row to the top of this dataframe. This
is downloaded data. I cannot use a specific row index in the formula
because the first Datetime indice changes all the time. I cannot also use a
specific label for the inner index as it could be Datetime. Is there a
way to g... | 1 | 2016-09-19T17:29:14Z | 39,580,332 | <p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_index.html" rel="nofollow"><code>sort_index</code></a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sortlevel.html" rel="nofollow"><code>sortlevel</code></a> for me does <strong>not</strong> wo... | 1 | 2016-09-19T19:04:28Z | [
"python",
"pandas",
"dataframe",
"append",
"multi-index"
] |
Calculation/manipulation of numpy array | 39,578,974 | <p>Looking to make the this calculation as quickly as possible. I have X as n x m numpy array. I want to define Y to be the following:</p>
<p><code>Y_11 = 1 / (exp(X_11-X_11) + exp(X_11-X_12) + ... exp(X_11 - X_1N) ).</code></p>
<p>or for Y_00</p>
<p><code>1/np.sum(np.exp(X[0,0]-X[0,:]))</code></p>
<p>So basically,... | 3 | 2016-09-19T17:35:25Z | 39,580,554 | <p>Here's a first step at reducing the double loop:</p>
<pre><code>def foo2(X):
Y = np.zeros_like(X)
for k in range(X.shape[1]):
Y[:,k]=1/np.exp(X[:,[k]]-X[:,:]).sum(axis=1)
return Y
</code></pre>
<p>I suspect I can also remove the <code>k</code> loop, but I have to spend more time figuring out ju... | 2 | 2016-09-19T19:20:26Z | [
"python",
"performance",
"numpy",
"sum",
"numpy-einsum"
] |
Calculation/manipulation of numpy array | 39,578,974 | <p>Looking to make the this calculation as quickly as possible. I have X as n x m numpy array. I want to define Y to be the following:</p>
<p><code>Y_11 = 1 / (exp(X_11-X_11) + exp(X_11-X_12) + ... exp(X_11 - X_1N) ).</code></p>
<p>or for Y_00</p>
<p><code>1/np.sum(np.exp(X[0,0]-X[0,:]))</code></p>
<p>So basically,... | 3 | 2016-09-19T17:35:25Z | 39,580,804 | <p>Here are few fully vectorized approaches -</p>
<pre><code>def vectorized_app1(X):
return 1/np.exp(X[:,None] - X[...,None]).sum(1)
def vectorized_app2(X):
exp_vals = np.exp(X)
return 1/(exp_vals[:,None]/exp_vals[...,None]).sum(1)
def vectorized_app3(X):
exp_vals = np.exp(X)
return 1/np.einsum('... | 5 | 2016-09-19T19:37:40Z | [
"python",
"performance",
"numpy",
"sum",
"numpy-einsum"
] |
ret2libc strcpy not working | 39,578,987 | <p>I am trying to solve a CTF challenge in wich I need to use ret2libc. The problem is that when I try to use strcpy to put some text inside a buffer for latter use, it does not seems to work.
The challenge box still vulnerable to "ulimit -s unlimited" so we can fix libc addresses. Here is my current python code:</p>
... | 0 | 2016-09-19T17:36:12Z | 39,579,993 | <p>I <em>think</em> the code you're seeing at glibc's <code>strncpy</code> symbol does the runtime CPU dispatching during lazy dynamic linking. It looks like the asm in <a href="http://repo.or.cz/glibc.git/blob/1850ce5a2ea3b908b26165e7e951cd4334129f07:/sysdeps/i386/i686/multiarch/strcpy.S" rel="nofollow"><code>sysdeps... | 0 | 2016-09-19T18:41:03Z | [
"python",
"assembly",
"exploit"
] |
How to use pytmx in pygame? | 39,579,000 | <p>There was a question similar to this but the persons question wasn't regarding the same way I'm trying to implement <code>pytmx</code>, so this is the first time I've worked with <code>tiled</code>, or <code>pytmx</code> and I'm having trouble with the docs on <code>pytmx</code>.</p>
<p>I just cannot get the code t... | 0 | 2016-09-19T17:37:11Z | 39,584,184 | <p>There are a lot of things wrong with this code. - did you write it or get it from somewhere else? It may be that you need to make sure you understand Pygame better before you try to do something as advanced as using a Tiled map. Also, is this the whole code, or did you leave some out?</p>
<p>To address the biggest... | 0 | 2016-09-20T00:58:59Z | [
"python",
"python-3.x",
"pygame"
] |
How do I request a zipfile, extract it, then create pandas dataframes from the csv files? | 39,579,073 | <p>Load in these CSV files from the Sean Lahman's Baseball Database. For this assignment, we will use the 'Salaries.csv' and 'Teams.csv' tables. Read these tables into a pandas DataFrame and show the head of each table.</p>
<pre><code> #Here's the code I have so far:
import requests
import io
import zipfile
url = ... | 0 | 2016-09-19T17:41:45Z | 39,579,321 | <p>Request returns a bytes file, so first convert bytes to zip file:</p>
<pre><code>mlz = zipfile.ZipFile(io.BytesIO(r.content))
</code></pre>
<p>To see what's in the zipfile, type:</p>
<pre><code>mlz.namelist()
</code></pre>
<p>Then you can extract and read the CSV corresponding to the index, x:</p>
<pre><code>df... | 0 | 2016-09-19T17:56:14Z | [
"python",
"csv",
"pandas",
"python-requests",
"zipfile"
] |
Django: Where should I put queries about User which is in relation with other models | 39,579,145 | <p>I am writing a Django app which define groups of user. A user can be part of many groups.</p>
<p>I want to be able to retrieve, from a list of groups, users which are members of at least one of those groups and with no duplicate.</p>
<p>So i wrote a query to accomplish that. That method will take a list of group_i... | 0 | 2016-09-19T17:46:02Z | 39,580,629 | <p>I assume there is a <code>ManyToManyField</code> relation from <code>User</code> to <code>Group</code>, like the following?</p>
<pre><code>class Group(models.Model):
users = models.ManyToManyField('auth.User')
</code></pre>
<p>I don't think there's a reason to write a method to achieve this, it's just a one-li... | 0 | 2016-09-19T19:25:54Z | [
"python",
"django",
"django-models",
"django-orm",
"django-managers"
] |
Django: Where should I put queries about User which is in relation with other models | 39,579,145 | <p>I am writing a Django app which define groups of user. A user can be part of many groups.</p>
<p>I want to be able to retrieve, from a list of groups, users which are members of at least one of those groups and with no duplicate.</p>
<p>So i wrote a query to accomplish that. That method will take a list of group_i... | 0 | 2016-09-19T17:46:02Z | 39,581,002 | <p>In your views.py you can use the below function and call it in your view:</p>
<pre><code>def get_groups_users(*groups):
users = User.objects.filter(groups__name__in=list(groups))
return list(set(users))
</code></pre>
| 0 | 2016-09-19T19:51:22Z | [
"python",
"django",
"django-models",
"django-orm",
"django-managers"
] |
How do I create a directory to assign values to similar items in a list. | 39,579,265 | <p>I need to create a dictionary where I can assign a value that classifies the same object in the list. Note that I don't have a preexisting value, I want python to assign one. Here is what I have:</p>
<pre><code> In [38]: post_title_list
Out[38]: [u'the rfe master list',
u'the rfe master list',
... | 0 | 2016-09-19T17:52:55Z | 39,580,000 | <p>As it was already pointed out in the comments to your question, you can't have multiple entries for the same key in a dictionary.</p>
<p>One way to go would be a dictionary in which every title occurs only once and maps to the corresponding number:</p>
<pre><code>d = {}
next_id = 1
for title in post_title_list:
... | 1 | 2016-09-19T18:41:23Z | [
"python",
"dictionary"
] |
How do I create a directory to assign values to similar items in a list. | 39,579,265 | <p>I need to create a dictionary where I can assign a value that classifies the same object in the list. Note that I don't have a preexisting value, I want python to assign one. Here is what I have:</p>
<pre><code> In [38]: post_title_list
Out[38]: [u'the rfe master list',
u'the rfe master list',
... | 0 | 2016-09-19T17:52:55Z | 39,580,010 | <p>As stated in the comments, dictionaries need to have unique keys. So I would suggest a list of tuples.
To generate a similar form of the desired output, I suggest something like:</p>
<pre><code>ctr = 1
l = [
'a',
'a',
'a',
'a',
'a',
'a',
'a',
'a',
'b',
'b',
'b',
'b',... | 1 | 2016-09-19T18:42:09Z | [
"python",
"dictionary"
] |
How to read contents of a large csv file and write them to another file with an operator in Python? | 39,579,292 | <p>I have a csv file of data from a LiDAR sensor that looks like this, but with a bagillion more lines:</p>
<pre><code>scan_0,scan_1,scan_2
timestamp_0,timestamp_1,timestamp_2
7900200,7900225,7900250
logTime_0,logTime_1,logTime_2
27:46.8,27:46.8,27:46.8
distance_0,distance_0,distance_0
132,141,139
136,141,155
139,141,... | 3 | 2016-09-19T17:54:23Z | 39,579,464 | <p>I am not sure why this isn't blowing up on you. csv.writer objects don't have a write function. Try thedatawriter.writerow(row) instead.</p>
| 1 | 2016-09-19T18:05:01Z | [
"python"
] |
How to read contents of a large csv file and write them to another file with an operator in Python? | 39,579,292 | <p>I have a csv file of data from a LiDAR sensor that looks like this, but with a bagillion more lines:</p>
<pre><code>scan_0,scan_1,scan_2
timestamp_0,timestamp_1,timestamp_2
7900200,7900225,7900250
logTime_0,logTime_1,logTime_2
27:46.8,27:46.8,27:46.8
distance_0,distance_0,distance_0
132,141,139
136,141,155
139,141,... | 3 | 2016-09-19T17:54:23Z | 39,579,531 | <p>When running your code, I get the following error: </p>
<pre><code>AttributeError: '_csv.writer' object has no attribute 'write'
</code></pre>
<p>Are you sure you are not getting the same kind of error? Because based on <a href="https://docs.python.org/3/library/csv.html#csv.writer" rel="nofollow">the documentatio... | 2 | 2016-09-19T18:09:13Z | [
"python"
] |
Maximum Recursion in LCS Recursive Function | 39,579,361 | <p>I'm trying to execute an LCS function that utilizes recursion to give me the number of positions the LCS is valid, along with the place of LCS depicted here:</p>
<pre><code>input: LCS("smile", "tile")
output: [3, "##ile", "#ile"]
</code></pre>
<p>Whenever I try and execute it, it tells me that there is a recursion... | 2 | 2016-09-19T17:58:32Z | 39,579,472 | <p>In your first recursive call (<code>count = 1 + LCS(s1[1:], s2[1:])</code>), since you just added an element to the end of each of <code>s1</code> and <code>s2</code>, the sizes of strings being passed are the same as in the call, so you are making no progress towards termination</p>
<p>Inside of <code>max</code>, ... | 1 | 2016-09-19T18:05:33Z | [
"python",
"recursion",
"lcs"
] |
Maximum Recursion in LCS Recursive Function | 39,579,361 | <p>I'm trying to execute an LCS function that utilizes recursion to give me the number of positions the LCS is valid, along with the place of LCS depicted here:</p>
<pre><code>input: LCS("smile", "tile")
output: [3, "##ile", "#ile"]
</code></pre>
<p>Whenever I try and execute it, it tells me that there is a recursion... | 2 | 2016-09-19T17:58:32Z | 39,579,543 | <p>I'm not at all clear about your logic: on each iteration, you either move the first character to the end of the string, or you drop it and append a <strong>#</strong>.
The <em>only</em> reduction step in this is shortening s2 in the lower branch, but you'll get caught in infinite recursion before you get there. I a... | 0 | 2016-09-19T18:09:53Z | [
"python",
"recursion",
"lcs"
] |
Maximum Recursion in LCS Recursive Function | 39,579,361 | <p>I'm trying to execute an LCS function that utilizes recursion to give me the number of positions the LCS is valid, along with the place of LCS depicted here:</p>
<pre><code>input: LCS("smile", "tile")
output: [3, "##ile", "#ile"]
</code></pre>
<p>Whenever I try and execute it, it tells me that there is a recursion... | 2 | 2016-09-19T17:58:32Z | 39,579,914 | <p>As stated by others you are adding a character to your string variable, and chop one off in the next recursive call. This way there will always be recursive calls with a string that has the initial length, leading to infinite recursion.</p>
<p>And with a closer look, this does not make sense:</p>
<pre><code> if... | 0 | 2016-09-19T18:35:24Z | [
"python",
"recursion",
"lcs"
] |
extract div tag entries that are part of a table using python scrapy | 39,579,386 | <p>Im trying to extract some data on a webpage using python scrapy. I don't know enough HTML/CSS to know if this is well formatted, but it doesn't appear to be. The target information I am interested in has a pattern as shown below. A Table contains a set of entries (Name, Year, Int1, Int2) that I am interested in extr... | 2 | 2016-09-19T18:00:16Z | 39,579,524 | <p>You can get the texts of every inner <code>div</code> and then <a href="http://stackoverflow.com/q/9671224/771848">split the extracted list into chunks</a>:</p>
<pre><code>In [1]: data = response.xpath("//table/tr/td/div/text()").extract()
In [2]: [data[x+1:x+5] for x in xrange(0, len(data), 5)]
Out[2]:
[[u'Mr. R... | 1 | 2016-09-19T18:08:49Z | [
"python",
"xpath",
"scrapy"
] |
Matplotlib python animation not showing line | 39,579,419 | <p>The windows for plotting shows up but nothing appears and i get this ValueError: x and y must have same first dimension </p>
<pre><code>import psutil
import matplotlib.pyplot as plt
import matplotlib.animation as animation
a = [i for i in range(1000)]
ram_avaliable = []
fig, ax = plt.subplots()
def update(n):
... | 2 | 2016-09-19T18:02:09Z | 39,579,636 | <p>Your code as posted runs without errors for me. The only change I had to make for points to show up was add a marker style to the <code>plot</code> command.</p>
<p>This is because when you call <code>plot</code> you are plotting a <em>new line</em>. The reason it wasn't showing up before is because the default line... | 0 | 2016-09-19T18:16:11Z | [
"python",
"matplotlib"
] |
Counting frequencies in two lists, Python | 39,579,431 | <p>I'm new to programming in python so please bear over with my newbie question...</p>
<p>I have one initial list (list1) , which I have cleaned for duplicates and ended up with a list with only one of each value (list2): </p>
<p>list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16],</p>
<p>list2 = [13, ... | 4 | 2016-09-19T18:02:41Z | 39,579,465 | <pre><code>visited = []
for i in list2:
if i not in visited:
print "Number", i, "is presented", list1.count(i), "times in list1"
visited.append(i)
</code></pre>
| 6 | 2016-09-19T18:05:03Z | [
"python",
"list",
"frequency",
"counting"
] |
Counting frequencies in two lists, Python | 39,579,431 | <p>I'm new to programming in python so please bear over with my newbie question...</p>
<p>I have one initial list (list1) , which I have cleaned for duplicates and ended up with a list with only one of each value (list2): </p>
<p>list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16],</p>
<p>list2 = [13, ... | 4 | 2016-09-19T18:02:41Z | 39,579,512 | <p>The easiest way is to use a counter:</p>
<pre><code>from collections import Counter
list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16]
c = Counter(list1)
print(c)
</code></pre>
<p>giving</p>
<pre><code>Counter({2: 1, 5: 1, 6: 1, 13: 4, 16: 2, 19: 3, 20: 2, 21: 1})
</code></pre>
<p>So you can acces... | 7 | 2016-09-19T18:08:11Z | [
"python",
"list",
"frequency",
"counting"
] |
Counting frequencies in two lists, Python | 39,579,431 | <p>I'm new to programming in python so please bear over with my newbie question...</p>
<p>I have one initial list (list1) , which I have cleaned for duplicates and ended up with a list with only one of each value (list2): </p>
<p>list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16],</p>
<p>list2 = [13, ... | 4 | 2016-09-19T18:02:41Z | 39,579,549 | <p><strong>Simplest</strong>, <strong>easiest</strong> to understand, <strong>no-magic-approach</strong> is to create an object(associative array) and just count the numbers in list1:</p>
<pre><code>list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16]
frequency_list = {}
for l in list1:
if l in freq... | 1 | 2016-09-19T18:10:18Z | [
"python",
"list",
"frequency",
"counting"
] |
Counting frequencies in two lists, Python | 39,579,431 | <p>I'm new to programming in python so please bear over with my newbie question...</p>
<p>I have one initial list (list1) , which I have cleaned for duplicates and ended up with a list with only one of each value (list2): </p>
<p>list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16],</p>
<p>list2 = [13, ... | 4 | 2016-09-19T18:02:41Z | 39,579,633 | <p>You can also use operator</p>
<pre><code>>>> list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16],
>>> list2 = [13, 19, 2, 16, 6, 5, 20, 21]
>>> import operator
>>> for s in list2:
... print s, 'appearing in :', operator.countOf(list1, s)
</code></pre>
| 0 | 2016-09-19T18:16:03Z | [
"python",
"list",
"frequency",
"counting"
] |
Counting frequencies in two lists, Python | 39,579,431 | <p>I'm new to programming in python so please bear over with my newbie question...</p>
<p>I have one initial list (list1) , which I have cleaned for duplicates and ended up with a list with only one of each value (list2): </p>
<p>list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16],</p>
<p>list2 = [13, ... | 4 | 2016-09-19T18:02:41Z | 39,579,635 | <p>In technical terms, <code>list</code> is a "type" of "object". Python has a number of built in types like strings (<code>str</code>), integers (<code>int</code>), and a few others that can be easily found on google. The reason this is important is because each object type has its own "methods". You can think of thes... | 0 | 2016-09-19T18:16:07Z | [
"python",
"list",
"frequency",
"counting"
] |
Counting frequencies in two lists, Python | 39,579,431 | <p>I'm new to programming in python so please bear over with my newbie question...</p>
<p>I have one initial list (list1) , which I have cleaned for duplicates and ended up with a list with only one of each value (list2): </p>
<p>list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16],</p>
<p>list2 = [13, ... | 4 | 2016-09-19T18:02:41Z | 39,581,682 | <p>You don't need to remove duplicates. When you add to a dictionary, automatically, the duplicates will be considered as single values.</p>
<pre><code>list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16]
counts = {s:list1.count(s) for s in list1}
print counts
{2: 1, 5: 1, 6: 1, 13: 4, 16: 2, 19: 3, 20: ... | 0 | 2016-09-19T20:35:56Z | [
"python",
"list",
"frequency",
"counting"
] |
TypeError: unsupported operand type(s) for +: 'function' and 'int' | 39,579,448 | <p>Why this function call is giving me the above error?</p>
<pre><code>count=0
def returncall():
for i,j in enumerate(range(count,count+3),0):
print i,j
return j
count=returncall
print count()
</code></pre>
| -3 | 2016-09-19T18:03:41Z | 39,579,571 | <p>The problem is here:</p>
<pre><code>for i,j in enumerate(range(count,count+3),0):
</code></pre>
<p><code>count</code> is another name for <code>returncall</code> because you have done <code>count = returncall</code>. <code>returncall</code> is a function; in fact, it's the very function that statement is in. You c... | 4 | 2016-09-19T18:11:24Z | [
"python",
"python-2.7"
] |
visit all elements in nested lists and dicts without recursion | 39,579,513 | <p>I have a structure consisting of nested lists and dicts. I want to apply a
function to every element. How to do it without recursion.</p>
<pre><code>def visit(data, func):
if isinstance(data, dict):
for k, v in data.items():
data[k] = visit(v, func)
return data
elif isinstance(da... | 2 | 2016-09-19T18:08:11Z | 39,579,995 | <p>This approach will work. For the record, though, I agree with Sven Marnach that there is something <em>definitely fishy</em> going on with your data structures if you have nesting that is breaking the recursion limit. If as Sven conjectures,you have cycles in your data, this approach will also break. </p>
<pre><cod... | 2 | 2016-09-19T18:41:03Z | [
"python",
"recursion",
"data-structures"
] |
Check for Dead Links on soundcloud using text file with Python | 39,579,517 | <p>Python 2.7</p>
<h2>Windows 10 x64</h2>
<p>I have a .txt file full of soundcloud links and was wondering how I can use this txt file as input and loop through the links checking for the error that the header displays. And then printing those that do not give the error.</p>
<p>This what I have but it keeps gi... | 1 | 2016-09-19T18:08:29Z | 39,579,845 | <p>The problem is caused by carriage return / line feed at the end of your row variable.</p>
<p>Use</p>
<pre><code>r = requests.get(row.strip())
</code></pre>
<p>to get rid of blanks and the beginning and end of your url. You may also have to handle exceptions:</p>
<pre><code># Test Dead Link
# https://soundcloud.c... | 1 | 2016-09-19T18:30:27Z | [
"python",
"testing",
"hyperlink"
] |
Align ListBox in Frame wxpython | 39,579,580 | <p>I'm trying to figure out how to align a ListBox properly. As soon as i insert the lines of ListBox, the layout transforms into a mess.</p>
<pre><code>#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
oplist=[]
with open("options.txt","r") as f:
for line in f:
oplist.append(line.rstrip('\n'))
print(op... | 2 | 2016-09-19T18:12:01Z | 39,580,647 | <p>The listbox is being parented to the frame by using self.</p>
<pre><code>self.flistbox= wx.ListBox(
self,choices=oplist, size=(100,100), name="Field", wx.ALIGN_CENTER_HORIZONTAL)
</code></pre>
<p>It should be parented to the panel by using p like the other controls.</p>
<pre><code>self.flistbox= wx.ListBox(
... | 1 | 2016-09-19T19:27:38Z | [
"python",
"listbox",
"wxpython",
"boxsizer"
] |
Imagemagick Draw text, draws past the border of the image. How to fix? | 39,579,655 | <p>When I use Imagemagick's draw function to write text it will write beyond the border of the image. For example if the image is 200px width and the text I need to write will take up 300px, it continues off the edge and the rest of the text isn't shown.</p>
<p>I checked the manual and didnt find anything on how to se... | 1 | 2016-09-19T18:17:30Z | 39,581,603 | <p>If you have a known area which you want to put text in, you should probably use <code>caption:</code> and not specify a font size, then ImageMagick will use the largest font commensurate with that size:</p>
<pre><code>convert -size 200x100 -background blue -fill white caption:"Here is some funky text." result.png
<... | 0 | 2016-09-19T20:30:45Z | [
"python",
"image",
"imagemagick"
] |
Flask background-image not showing | 39,579,666 | <p>My background-image works only for this template that has @app.route('/').</p>
<pre><code> <header class="intro-header" style="background-image: url('static/img/home.jpg')">
</code></pre>
<p>This works perfectly fine when:</p>
<pre><code>@app.route('/')
def home():
return render_template('post.html')
</... | 3 | 2016-09-19T18:18:14Z | 39,579,747 | <blockquote>
<p>Partial URLs are interpreted relative to the source of the style sheet, not relative to the document - <a href="https://www.w3.org/TR/REC-CSS1/#url" rel="nofollow">w3 CSS</a> </p>
</blockquote>
<p>This means that you need to change your <code>url()</code> a bit, to include the leading <code>/</code>.... | 1 | 2016-09-19T18:24:25Z | [
"python",
"html",
"css",
"flask"
] |
Flask background-image not showing | 39,579,666 | <p>My background-image works only for this template that has @app.route('/').</p>
<pre><code> <header class="intro-header" style="background-image: url('static/img/home.jpg')">
</code></pre>
<p>This works perfectly fine when:</p>
<pre><code>@app.route('/')
def home():
return render_template('post.html')
</... | 3 | 2016-09-19T18:18:14Z | 39,579,810 | <p><a href="http://flask.pocoo.org/docs/0.11/quickstart/#static-files" rel="nofollow">This is a simple problem can solved by Flask documentation</a></p>
<p>Anyway, you should use something like this in your template:</p>
<pre><code>background-image: url({{ url_for('static', filename='img/home.jpg') }})
</code></pre>
... | 4 | 2016-09-19T18:28:33Z | [
"python",
"html",
"css",
"flask"
] |
Execute python script with output from php | 39,579,673 | <p>Is there any special permission or setting in order to execute a python script that create a new file or image?
This is my code:</p>
<pre><code><?
function py(){
exec( 'python my_script.py');
echo "ok";
}
py();
?>
</code></pre>
<p>And this is my python script (an example):</p>
<pre><code>#!/usr/bi... | 3 | 2016-09-19T18:18:49Z | 39,581,371 | <p>You need to call <code>shell_exec()</code> not <code>exec()</code> if you want to be able to capture the output:</p>
<p><a href="http://php.net/manual/en/ref.exec.php" rel="nofollow">Refernce: PHP Manual</a></p>
| 0 | 2016-09-19T20:16:04Z | [
"php",
"python"
] |
Execute python script with output from php | 39,579,673 | <p>Is there any special permission or setting in order to execute a python script that create a new file or image?
This is my code:</p>
<pre><code><?
function py(){
exec( 'python my_script.py');
echo "ok";
}
py();
?>
</code></pre>
<p>And this is my python script (an example):</p>
<pre><code>#!/usr/bi... | 3 | 2016-09-19T18:18:49Z | 39,588,384 | <p>Setting the right permissions to file and folders did the trick.</p>
<p><a href="http://i.stack.imgur.com/fuXCb.png" rel="nofollow"><img src="http://i.stack.imgur.com/fuXCb.png" alt="enter image description here"></a></p>
<p>On Mac OS: Alt + Click on "+", then search for _www and add World Wide Web Server to users... | 1 | 2016-09-20T07:42:35Z | [
"php",
"python"
] |
Python Script Error in Windows 7 | 39,579,713 | <p>I am trying to run this following script in here and getting this NameError. I have added path variable in Windows 7. </p>
<pre><code>C:\Users\myname>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more inf... | 1 | 2016-09-19T18:21:38Z | 39,579,741 | <p>You need to do <code>python script.py</code> instead, from the command prompt <em>not</em> from the Python interpreter. </p>
<p>However, if you are in the Python interactive interpretor in the same directory as your script, as <strong>@Tuan333</strong> points out, you can do:</p>
<pre><code>>>> import scr... | 4 | 2016-09-19T18:24:19Z | [
"python",
"python-3.x"
] |
Python Script Error in Windows 7 | 39,579,713 | <p>I am trying to run this following script in here and getting this NameError. I have added path variable in Windows 7. </p>
<pre><code>C:\Users\myname>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more inf... | 1 | 2016-09-19T18:21:38Z | 39,579,744 | <p>You need to call the script all on one line</p>
<pre><code>C:\Users\myname>python C:\path\to\script.py
</code></pre>
| 1 | 2016-09-19T18:24:23Z | [
"python",
"python-3.x"
] |
Python Script Error in Windows 7 | 39,579,713 | <p>I am trying to run this following script in here and getting this NameError. I have added path variable in Windows 7. </p>
<pre><code>C:\Users\myname>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more inf... | 1 | 2016-09-19T18:21:38Z | 39,579,765 | <p>you have to run your script by using this command in command prompt <br /> <em>python [Address of your script]</em></p>
| 1 | 2016-09-19T18:25:16Z | [
"python",
"python-3.x"
] |
Obtain device path from pyudev with python | 39,579,727 | <p>Using pydev with <code>python-2.7</code>, I wish obtain the device path of connected devices. </p>
<p>Now I use this code:</p>
<pre><code>from pyudev.glib import GUDevMonitorObserver as MonitorObserver
def device_event(observer, action, device):
print 'event {0} on device {1}'.format(action, device)
</code></... | 1 | 2016-09-19T18:22:53Z | 39,885,881 | <p><code>Device(u'/sys/devices/pci0000:00/pci0000:00:01.0/0000.000/usb1/1-2')</code> is a <em>USB device</em> (i.e. <code>device.device_type == 'usb_device'</code>). At the time of its enumeration the <code>/dev/tty*</code> file does not exist yet as it gets assigned to its <em>child</em> <em>USB interface</em> later d... | 1 | 2016-10-06T00:57:10Z | [
"python",
"usb",
"glib",
"pyudev"
] |
Obtain device path from pyudev with python | 39,579,727 | <p>Using pydev with <code>python-2.7</code>, I wish obtain the device path of connected devices. </p>
<p>Now I use this code:</p>
<pre><code>from pyudev.glib import GUDevMonitorObserver as MonitorObserver
def device_event(observer, action, device):
print 'event {0} on device {1}'.format(action, device)
</code></... | 1 | 2016-09-19T18:22:53Z | 39,897,510 | <p>I find this solution:</p>
<pre><code>def device_event (observer, action, device):
if action == "add":
last_dev = os.popen('ls -ltr /dev/ttyUSB* | tail -n 1').read()
print "Last device: " + last_dev
</code></pre>
<p>I know... is horrible. </p>
| 0 | 2016-10-06T13:34:31Z | [
"python",
"usb",
"glib",
"pyudev"
] |
Checking if string contains unicode using standard Python | 39,579,745 | <p>I have some strings of roughly 100 characters and I need to detect if each string contains an unicode character. The final purpose is to check if some particular emojis are present, but initially I just want a filter that catches all emojis (as well as potentially other special characters). This method should be fas... | 0 | 2016-09-19T18:24:24Z | 39,579,944 | <p>There is no point is testing 'if a string contains Unicode characters', because <strong>all</strong> characters in a string are Unicode characters. The Unicode standard encompasses all codepoints that Python supports, including the ASCII range (Unicode codepoints U+0000 through to U+007F).</p>
<p>If you want to tes... | 1 | 2016-09-19T18:37:34Z | [
"python",
"regex",
"unicode"
] |
Can't get program to print "not in sentence" when word not in sentence | 39,579,770 | <p>I have a program that asks for input of a sentence, then asks for a word, and tells you the position of that word:</p>
<pre><code>sentence = input("enter sentence: ").lower()
askedword = input("enter word to locate position: ").lower()
words = sentence.split(" ")
for i, word in enumerate(words):
if askedword ... | 1 | 2016-09-19T18:25:35Z | 39,579,838 | <p>Lists are sequences, as such you can use <a href="https://docs.python.org/3.5/library/stdtypes.html#common-sequence-operations" rel="nofollow">the <code>in</code> operation</a> on them to test for membership in the <code>words</code> list. If inside, find the position inside the sentence with <code>words.index</code... | 5 | 2016-09-19T18:30:05Z | [
"python",
"python-3.x",
"words",
"enumerate",
"sentence"
] |
Can't get program to print "not in sentence" when word not in sentence | 39,579,770 | <p>I have a program that asks for input of a sentence, then asks for a word, and tells you the position of that word:</p>
<pre><code>sentence = input("enter sentence: ").lower()
askedword = input("enter word to locate position: ").lower()
words = sentence.split(" ")
for i, word in enumerate(words):
if askedword ... | 1 | 2016-09-19T18:25:35Z | 39,580,062 | <p>Jim's answerâcombining a test for <code>askedword in words</code> with a call to <code>words.index(askedword)</code>âis the best and most Pythonic approach in my opinion.</p>
<p>Another variation on the same approach is to use <code>try</code>-<code>except</code>:</p>
<pre><code>try:
print(words.index(aske... | 3 | 2016-09-19T18:46:05Z | [
"python",
"python-3.x",
"words",
"enumerate",
"sentence"
] |
Create wheel without building dependencies | 39,579,804 | <p>I have a sample project:</p>
<pre><code>test/
- __init__.py
- module.py
- setup.py
</code></pre>
<p>setup.py is just</p>
<pre><code>from setuptools import setup
setup(name='test', install_requires=['numpy'])
</code></pre>
<p>Then when I call <code>pip wheel .</code>, it automatically makes a wheel f... | 2 | 2016-09-19T18:28:19Z | 39,579,922 | <p>That's just the way that pip rolls, but if you wheely want to omit the numpy build then you can turn around and give this command a spin:</p>
<pre><code>pip wheel --no-deps .
</code></pre>
<p><em>Note:</em> if the correct numpy wheel was already existing, it would be skipped anyway. No need to reinvent the thing.... | 1 | 2016-09-19T18:36:06Z | [
"python",
"setup.py",
"python-wheel"
] |
Combine multiple time-series rows into one row with Pandas | 39,579,875 | <p>I am using a recurrent neural network to consume time-series events (click stream). My data needs to be formatted such that a each row contains all the events for an id. My data is one-hot encoded, and I have already grouped it by the id. Also I limit the total number of events per id (ex. 2), so final width will al... | 3 | 2016-09-19T18:32:54Z | 39,580,051 | <p>The idea here is to <code>reset_index</code> within each group of <code>'id'</code> to get a count which row of that particular <code>'id'</code> we are at. Then follow that up with <code>unstack</code> and <code>sort_index</code> to get columns where they are supposed to be.</p>
<p>Finally, flatten the multiindex... | 3 | 2016-09-19T18:45:25Z | [
"python",
"pandas",
"numpy"
] |
Combine multiple time-series rows into one row with Pandas | 39,579,875 | <p>I am using a recurrent neural network to consume time-series events (click stream). My data needs to be formatted such that a each row contains all the events for an id. My data is one-hot encoded, and I have already grouped it by the id. Also I limit the total number of events per id (ex. 2), so final width will al... | 3 | 2016-09-19T18:32:54Z | 39,580,054 | <p>You can first create new column with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.cumcount.html" rel="nofollow"><code>cumcount</code></a> for new column name, then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofoll... | 2 | 2016-09-19T18:45:33Z | [
"python",
"pandas",
"numpy"
] |
wxPython - "Uknown accel modifier: num/numpad" on Ubuntu | 39,579,954 | <p>I am trying to hookup some keybindings for a program I am developing on Ubuntu. The keybindings themselves are working, however the wxPython menu cannot seem to map the Numpad keys to the accelerator table so that the hotkey combination appears next to the menu item.</p>
<p>I have tried the few logical variations o... | 1 | 2016-09-19T18:38:43Z | 39,857,678 | <p>Just in case anyone comes across this and was wondering, a list of all the different label accelerators can be found at the bottom of the following page:</p>
<p><a href="http://docs.wxwidgets.org/trunk/classwx_menu_item.html" rel="nofollow">http://docs.wxwidgets.org/trunk/classwx_menu_item.html</a></p>
| 0 | 2016-10-04T16:44:01Z | [
"python",
"ubuntu",
"wxpython"
] |
MariaDB SQL syntax near error paranthesis ')' for python | 39,579,996 | <p>I am trying to insert some data into my MariaDB using python script.
when I do the following in console it works perfectly.</p>
<pre><code>INSERT INTO `Failure` (`faillure_id`, `testrun_id`, `failed_at`, `log_path`, `node`)
VALUES (2, 1, 'STEP8:RUN:RC=1', '/var/fail_logs','NodeA')
</code></pre>
<p>show... | 2 | 2016-09-19T18:41:06Z | 39,581,444 | <p>As a work-around I'm building the query string like this </p>
<pre><code>sql_query = "INSERT INTO `Failure` (`testrun_id`, `failed_at`, `log_path`, `node`) VALUES " + "( '" + str(testrun_id) + "', '" + str(failed_at) + "', '"+ log_path + "', '" + node + "')"
cursor.execute(sql_query)
</code></pre>
<p>not very effi... | 0 | 2016-09-19T20:19:53Z | [
"python",
"mysql",
"mariadb"
] |
Writing a list of lists to a seperate text file, one file per a list with in that list | 39,580,015 | <p>so I am trying to write a list of lists to seperate files.
Each list contains 100 string objects or less. The goal is keep a text file less than 100 lines no more than that.</p>
<p>To do that, i split a list but now i am having an issue writing them to a file.
So essentialy write a list within a list to its own sep... | 0 | 2016-09-19T18:42:29Z | 39,580,289 | <p>Something like this would work. I had to use <code>random</code> to generate some data, into a list that was 275 elements long. </p>
<pre><code>import random
def chunks(l, n):
n = max(1, n)
return [l[i:i + n] for i in range(0, len(l), n)]
data = [random.randint(0, 10) for x in range(275)]
chunked_data = ... | 1 | 2016-09-19T19:01:04Z | [
"python"
] |
Remove the first N items that match a condition in a Python list | 39,580,063 | <p>If I have a function <code>matchCondition(x)</code>, how can I remove the first <code>n</code> items in a Python list that match that condition?</p>
<p>One solution is to iterate over each item, mark it for deletion (e.g., by setting it to <code>None</code>), and then filter the list with a comprehension. This requ... | 58 | 2016-09-19T18:46:05Z | 39,580,319 | <p>Write a generator that takes the iterable, a condition, and an amount to drop. Iterate over the data and yield items that don't meet the condition. If the condition is met, increment a counter and don't yield the value. Always yield items once the counter reaches the amount you want to drop.</p>
<pre><code>def i... | 31 | 2016-09-19T19:03:49Z | [
"python",
"list",
"list-comprehension"
] |
Remove the first N items that match a condition in a Python list | 39,580,063 | <p>If I have a function <code>matchCondition(x)</code>, how can I remove the first <code>n</code> items in a Python list that match that condition?</p>
<p>One solution is to iterate over each item, mark it for deletion (e.g., by setting it to <code>None</code>), and then filter the list with a comprehension. This requ... | 58 | 2016-09-19T18:46:05Z | 39,580,552 | <p>If mutation is required:</p>
<pre><code>def do_remove(ls, N, predicate):
i, delete_count, l = 0, 0, len(ls)
while i < l and delete_count < N:
if predicate(ls[i]):
ls.pop(i) # remove item at i
delete_count, l = delete_count + 1, l - 1
else:
i += 1
r... | 4 | 2016-09-19T19:20:12Z | [
"python",
"list",
"list-comprehension"
] |
Remove the first N items that match a condition in a Python list | 39,580,063 | <p>If I have a function <code>matchCondition(x)</code>, how can I remove the first <code>n</code> items in a Python list that match that condition?</p>
<p>One solution is to iterate over each item, mark it for deletion (e.g., by setting it to <code>None</code>), and then filter the list with a comprehension. This requ... | 58 | 2016-09-19T18:46:05Z | 39,580,621 | <p>One way using <a href="https://docs.python.org/3/library/itertools.html#itertools.filterfalse"><code>itertools.filterfalse</code></a> and <a href="https://docs.python.org/3/library/itertools.html#itertools.count"><code>itertools.count</code></a>:</p>
<pre><code>from itertools import count, filterfalse
data = [1, 1... | 59 | 2016-09-19T19:25:17Z | [
"python",
"list",
"list-comprehension"
] |
Remove the first N items that match a condition in a Python list | 39,580,063 | <p>If I have a function <code>matchCondition(x)</code>, how can I remove the first <code>n</code> items in a Python list that match that condition?</p>
<p>One solution is to iterate over each item, mark it for deletion (e.g., by setting it to <code>None</code>), and then filter the list with a comprehension. This requ... | 58 | 2016-09-19T18:46:05Z | 39,580,831 | <p>The accepted answer was a little too magical for my liking. Here's one where the flow is hopefully a bit clearer to follow:</p>
<pre><code>def matchCondition(x):
return x < 5
def my_gen(L, drop_condition, max_drops=3):
count = 0
iterator = iter(L)
for element in iterator:
if drop_condi... | 24 | 2016-09-19T19:39:12Z | [
"python",
"list",
"list-comprehension"
] |
Remove the first N items that match a condition in a Python list | 39,580,063 | <p>If I have a function <code>matchCondition(x)</code>, how can I remove the first <code>n</code> items in a Python list that match that condition?</p>
<p>One solution is to iterate over each item, mark it for deletion (e.g., by setting it to <code>None</code>), and then filter the list with a comprehension. This requ... | 58 | 2016-09-19T18:46:05Z | 39,596,598 | <p>Straightforward Python:</p>
<pre><code>N = 3
data = [1, 10, 2, 9, 3, 8, 4, 7]
def matchCondition(x):
return x < 5
c = 1
l = []
for x in data:
if c > N or not matchCondition(x):
l.append(x)
else:
c += 1
print(l)
</code></pre>
<p>This can easily be turned into a generator if desi... | 1 | 2016-09-20T14:19:19Z | [
"python",
"list",
"list-comprehension"
] |
Remove the first N items that match a condition in a Python list | 39,580,063 | <p>If I have a function <code>matchCondition(x)</code>, how can I remove the first <code>n</code> items in a Python list that match that condition?</p>
<p>One solution is to iterate over each item, mark it for deletion (e.g., by setting it to <code>None</code>), and then filter the list with a comprehension. This requ... | 58 | 2016-09-19T18:46:05Z | 39,630,844 | <p>Using list comprehensions:</p>
<pre><code>n = 3
data = [1, 10, 2, 9, 3, 8, 4, 7]
count = 0
def counter(x):
global count
count += 1
return x
def condition(x):
return x < 5
filtered = [counter(x) for x in data if count < n and condition(x)]
</code></pre>
<p>This will also stop checking the co... | 1 | 2016-09-22T05:22:55Z | [
"python",
"list",
"list-comprehension"
] |
how to insert new row in pandas data frame at desired index | 39,580,066 | <p>I have a data frame which has missing dates </p>
<pre><code>print data
Date Longitude Latitude Elevation Max Temperature \
4/11/1979 83.75 24.197701 238 44.769 20.007
4/12/1979 83.75 24.197701 238 41.967 18.027
4/13/1979 83.75 24.197701 238 43.053... | 4 | 2016-09-19T18:46:10Z | 39,580,178 | <p>First convert column <code>Date</code> <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow"><code>to_datetime</code></a>, then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow"><code>set_index</code></a> fo... | 3 | 2016-09-19T18:53:46Z | [
"python",
"pandas",
"dataframe",
null,
"resampling"
] |
How to Skip Numbers In Each Iteration Loop String in Python? | 39,580,069 | <p>I'm very new to this: but I have this string:</p>
<pre><code>urls = ['http://example.com/page_%s.html' % page for page in xrange(0,50)]
</code></pre>
<p>which runs from 0,1,2,3 ... 50. </p>
<p>The question is how can i make run by skipping 5 number in each iteration? </p>
<p>The number should run like this: 0, 5... | 0 | 2016-09-19T18:46:24Z | 39,580,094 | <p>Just adding the 5 as another argument to xrange should do that</p>
<pre><code>urls = ['http://example.com/page_%s.html' % page for page in xrange(0,50,5)]
</code></pre>
| 3 | 2016-09-19T18:48:14Z | [
"python"
] |
How to Skip Numbers In Each Iteration Loop String in Python? | 39,580,069 | <p>I'm very new to this: but I have this string:</p>
<pre><code>urls = ['http://example.com/page_%s.html' % page for page in xrange(0,50)]
</code></pre>
<p>which runs from 0,1,2,3 ... 50. </p>
<p>The question is how can i make run by skipping 5 number in each iteration? </p>
<p>The number should run like this: 0, 5... | 0 | 2016-09-19T18:46:24Z | 39,580,111 | <p>You can try this:</p>
<pre><code>urls = map('http://example.com/page_{}.html'.format, range(0, 50, 5))
</code></pre>
<p><code>range</code> and <code>xrange</code> take an optional <code>step</code> argument as the third parameter.</p>
| 3 | 2016-09-19T18:49:13Z | [
"python"
] |
Can't print contents after scraping site | 39,580,090 | <p>I am unable to print contents after scraping a website using selenium. I need to scrape a table. Here's what I am trying to do:</p>
<pre><code>table = driver.find_element_by_xpath('//div[@class="line-chart"]/div/div[1]/div/div/table/tbody')
print table.text
</code></pre>
<p>But I am just getting a blank line!! </... | 0 | 2016-09-19T18:47:31Z | 39,584,950 | <p>It's hard to say, why <code>.text</code> is not working in your case, may be its designing issue. But you can try also using <code>get_attribute()</code> to scrap text as below :-</p>
<pre><code>table.get_attribute("textContent")
</code></pre>
| 0 | 2016-09-20T02:47:47Z | [
"python",
"selenium",
"web-scraping",
"html-table"
] |
numpy binary notation quick generation | 39,580,110 | <p>Suppose, I have a <code>numpy</code> vector with <code>n</code> elements, so I'd like to encode numbers in this vector as a binary notation, so resulting shape will be <code>(n,m)</code> where <code>m</code> is <code>log2(maxnumber)</code> for example:</p>
<pre><code>x = numpy.array([32,5,67])
</code></pre>
<p>Be... | 3 | 2016-09-19T18:49:12Z | 39,580,269 | <p>Here us one way using <code>np.unpackbits</code> and broadcasting:</p>
<pre><code>>>> max_size = np.ceil(np.log2(x.max())).astype(int)
>>> np.unpackbits(x[:,None].astype(np.uint8), axis=1)[:,-max_size:]
array([[0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 1],
[1, 0, 0, 0, 0, 1, 1]], dtyp... | 3 | 2016-09-19T19:00:08Z | [
"python",
"numpy"
] |
numpy binary notation quick generation | 39,580,110 | <p>Suppose, I have a <code>numpy</code> vector with <code>n</code> elements, so I'd like to encode numbers in this vector as a binary notation, so resulting shape will be <code>(n,m)</code> where <code>m</code> is <code>log2(maxnumber)</code> for example:</p>
<pre><code>x = numpy.array([32,5,67])
</code></pre>
<p>Be... | 3 | 2016-09-19T18:49:12Z | 39,580,272 | <p>You can use numpy byte string.</p>
<p>For the case you have in hand:</p>
<pre><code>res = numpy.array(len(x),dtype='S7')
for i in range(len(x)):
res[i] = numpy.binary_repr(x[i])
</code></pre>
<p>Or more compactly</p>
<pre><code>res = numpy.array([numpy.binary_repr(val) for val in x])
</code></pre>
| 1 | 2016-09-19T19:00:18Z | [
"python",
"numpy"
] |
Constructing an edge list from the second column of a two columnar file with relationships derived from the first column | 39,580,130 | <p>I have a problem, I have a file with several million lines arranged like so:</p>
<pre><code>1 Protein_A
1 Protein_B
2 Protein_A
3 Protein_C
4 Protein_A
4 Protein_B
4 Protein_C
4 Protein_D
5 Protein_C
5 Protein_D
</code></pre>
<p>Where column 1 indicates an interaction pathway and col... | 1 | 2016-09-19T18:49:54Z | 39,580,297 | <p>Rather easy using python and some smart modules. I have embedded the file contents in a string. Just replace by <code>data = open("input.txt")</code> to read from a file (iterable as well).</p>
<p>I create a dictionary with number as key and list of proteins matching the number as values.</p>
<p>Once built, I use ... | 1 | 2016-09-19T19:01:41Z | [
"python",
"bash",
"shell",
"unix"
] |
Elasticsearch-py date malformed | 39,580,217 | <p>I am trying to index some data but I keep getting the error </p>
<pre><code>error: reason: failed to parse [date] type: mapper_parsing_exception, caused_by: Invalid format: 2016-08-12\t17:35:26 is malformed at \t17:35:26
</code></pre>
<p>My mapping looks like</p>
<pre><code>'date': { 'type': 'date', 'format': 'da... | 1 | 2016-09-19T18:56:37Z | 39,603,908 | <p>Before adding the date to hashtable or before u feed it to json, convert the date "2016-02-10\t10:25:30" to this "2016-02-10T10:25:30" </p>
<p>If you give elasticsearch this format, you should be able to use the original mapping - dateOptionalTime. </p>
| 1 | 2016-09-20T21:20:49Z | [
"python",
"elasticsearch"
] |
doc2vec - How to infer vectors of documents faster? | 39,580,232 | <p>I have trained paragraph vectors for around 2300 paragraphs(between 2000-12000 words each) each with vector size of 300. Now, I need to infer paragraph vectors of around 100,000 sentences which I have considered as paragraphs(each sentence is around 10-30 words each corresponding to the earlier 2300 paragraphs alrea... | 1 | 2016-09-19T18:57:36Z | 39,715,902 | <p>You might get a slight speedup from calling <code>infer_vector()</code> from multiple threads, on different subsets of the new data on which you need to infer vectors. There would still be quite a bit of thread-contention, preventing full use of all cores, due to the Python Global Interpreter Lock ('GIL'). </p>
<p... | 1 | 2016-09-27T04:19:40Z | [
"python",
"gensim",
"word2vec",
"doc2vec"
] |
Recognizing cx_Oracle install within PyDev | 39,580,275 | <p>I am on Windows 10 Pro 64-bit Anniversary Edition using Python 3.5.2 (Anaconda 4.1.1). I download the latest Oracle 12c Instant Client <code>instantclient-basic-windows.x64-12.1.0.2.0.zip</code> and <code>instantclient-sdk-windows.x64-12.1.0.2.0.zip</code> into <code>C:\instantclient</code> and put <code>C:\instantc... | 6 | 2016-09-19T19:00:21Z | 39,778,288 | <p>You can try this (after the steps that you already report in your question)</p>
<ol>
<li><p>Check if the installation in PyDev is ok (besides showing an error marker for <code>import cx_Oracle</code>)</p>
<pre><code>import cx_Oracle
conn = cx_Oracle.connect('hr/hr@pdborcl')
cur = conn.cursor()
cur.execute('select... | 1 | 2016-09-29T19:15:22Z | [
"python",
"windows",
"anaconda",
"pydev",
"cx-oracle"
] |
py2neo.database.status.Unauthorized in Neo4j 3.0.3 | 39,580,406 | <p>I've tried to access from a python program to the Neo4j 3.0 database but the following error is shown: </p>
<p>File "C:\Python27\lib\py2neo\database\http.py", line 157, in get raise Unauthorized(self.uri.string)
py2neo.database.status.Unauthorized: <a href="http://localhost:7474/db/data/" rel="nofollow">http://loca... | 0 | 2016-09-19T19:09:27Z | 39,581,177 | <p>Access the database through the web interface (<a href="http://localhost:7474/browser/" rel="nofollow">http://localhost:7474/browser/</a>), you have to set a new password at the first log in.</p>
<p>Then, this should work:</p>
<pre><code>from py2neo
g = Graph('http://localhost:7474/db/data', user='neo4j', password... | 1 | 2016-09-19T20:02:57Z | [
"python",
"neo4j",
"py2neo"
] |
How does TensorFlow calculate the gradients for the tf.train.GradientDescentOptimizer? | 39,580,427 | <p>I am trying to understand how TensorFlow computes the gradients for the <code>tf.train.GradientDescentOptimizer</code>.</p>
<p>If I understand section 4.1 in the TensorFlow whitepaper correct, it computes the gradients based on backpropagation by adding nodes to the TensorFlow graph which compute the derivation of ... | 0 | 2016-09-19T19:10:42Z | 39,583,022 | <p>Each node gets corresponding method that computes backprop values (registered using something like @ops.RegisterGradient("Sum") in Python)</p>
<p>You can visualize the graph using method <a href="http://stackoverflow.com/questions/38189119/simple-way-to-visualize-a-tensorflow-graph-in-jupyter">here</a></p>
<p>Howe... | 1 | 2016-09-19T22:27:34Z | [
"python",
"optimization",
"tensorflow",
"gradient"
] |
Pyglet Player.seek() function not working? | 39,580,438 | <p>I am trying to build a simple media tool in Pyglet, which requires a seek feature. Files are loaded, paused, and then told to seek to a specific time; however, the file does not seek when Player.seek() is called. Below is the test code I am using:</p>
<pre><code>import os
import pyglet
from os.path import abspath, ... | 2 | 2016-09-19T19:10:51Z | 39,745,404 | <p>First of all, the error you're getting is quite important.<br>
But I'll assume it's a <code>Segmentation fault (core dumped)</code> on the row:</p>
<pre><code>music.seek(12)
</code></pre>
<p>Another quick note, fix your indentation! You're using 3 spaces and whether you are a space guy or a tab guy - 3 spaces is j... | 0 | 2016-09-28T10:52:12Z | [
"python",
"python-3.x",
"media",
"pyglet"
] |
Pandas/python and working with a column, in a dataframe, with a date | 39,580,450 | <p>I am currently working on a Python/Pandas data science project for fun. The data that I am looking at has a Date column where the date looks like the following: 2016-07-16. The data type is also an object. What I want to do is go through each date and pull data from across that row. Now, some rows may have the same ... | 1 | 2016-09-19T19:11:54Z | 39,581,149 | <p>IMO there is no need to add a new column:</p>
<pre><code>In [132]: df
Out[132]:
Date Deaths Country
0 2002-01-01 2 India
1 2002-01-02 0 Pakistan
2 2001-01-02 1 France
In [217]: df.groupby(df.Date.dt.year)['Deaths'].sum()
Out[217]:
Date
2001 1
2002 2
Name: Deaths, dtype: i... | 1 | 2016-09-19T20:01:12Z | [
"python",
"date",
"pandas"
] |
Pandas/python and working with a column, in a dataframe, with a date | 39,580,450 | <p>I am currently working on a Python/Pandas data science project for fun. The data that I am looking at has a Date column where the date looks like the following: 2016-07-16. The data type is also an object. What I want to do is go through each date and pull data from across that row. Now, some rows may have the same ... | 1 | 2016-09-19T19:11:54Z | 39,582,046 | <p>Another way of dealing with the problem is through a dictionary</p>
<pre><code># Get column with the dates
dates = df.iloc[:,0].values
year_attacks = {}
for date in dates:
# Get year from the date
year=str(date).split('-')[0]
# If year is already in the dictionary increase number of attacks by 1
if... | 0 | 2016-09-19T21:02:04Z | [
"python",
"date",
"pandas"
] |
calculate the totall number of uniqe words of the first column of a list | 39,580,452 | <p>I have a file that consists of many Persian sentences. each line contains a sentence, then a "tab", then a word, again a "tab" and then an English word. I have to know just the number of unique words of the sentences (the words after tabs should not be in calculation). For that I changed the file to a list, so I hav... | 0 | 2016-09-19T19:11:59Z | 39,580,583 | <p>There is a simple solution. As you said you have list of lines. So the following code should get you what you want</p>
<pre><code>sample_data = """This is One sentence word1 word2
This is Second sentence word1 word2"""
lines = sample_data.split("\n")
word_list = []
for line in lines:
line = line.split("\t... | 1 | 2016-09-19T19:22:35Z | [
"python",
"nlp"
] |
calculate the totall number of uniqe words of the first column of a list | 39,580,452 | <p>I have a file that consists of many Persian sentences. each line contains a sentence, then a "tab", then a word, again a "tab" and then an English word. I have to know just the number of unique words of the sentences (the words after tabs should not be in calculation). For that I changed the file to a list, so I hav... | 0 | 2016-09-19T19:11:59Z | 39,580,682 | <p>You an use <code>collections.Counter</code> in order to count the number of words after splitting:</p>
<pre><code>from collections import Counter
from itertools import chain
def WordsProbs (file_name):
with open (file_name, encoding = "utf-8") as f1:
all_words = chain.from_iterable(word_tokenizer(line.... | 0 | 2016-09-19T19:29:58Z | [
"python",
"nlp"
] |
calculate the totall number of uniqe words of the first column of a list | 39,580,452 | <p>I have a file that consists of many Persian sentences. each line contains a sentence, then a "tab", then a word, again a "tab" and then an English word. I have to know just the number of unique words of the sentences (the words after tabs should not be in calculation). For that I changed the file to a list, so I hav... | 0 | 2016-09-19T19:11:59Z | 39,581,184 | <p>Assuming tmp[0] contains the sentence from each line, the individual words in the sentence can be counted without building a corpus.</p>
<pre><code>from hazm import*
def WordsProbs (file):
words = set()
with open (file, encoding = "utf-8") as f1:
normalizer = Normalizer()
for line in f1:
... | 0 | 2016-09-19T20:03:16Z | [
"python",
"nlp"
] |
PyQt - Dialog in another thread | 39,580,473 | <p>my program has a main window and in this window it runs a thread to read the power from a photodetector then it sends a signal, which is captured by a slot in the main window that updates the main window's gui. </p>
<p>Then I have another widget (let's call it programming widget) that pops from the main window, whi... | 0 | 2016-09-19T19:13:28Z | 39,583,114 | <p>Generally, the way this is done is to create a class derived from <code>QObject</code> that handles all the non-Qt data collection and move that into a separate thread using the <a href="http://stackoverflow.com/a/38003561/1547004">worker model</a>.</p>
<p>Then, you can use signals to pass data back and forth betwe... | 0 | 2016-09-19T22:38:11Z | [
"python",
"multithreading",
"qt",
"dialog",
"pyqt"
] |
PyQt - Dialog in another thread | 39,580,473 | <p>my program has a main window and in this window it runs a thread to read the power from a photodetector then it sends a signal, which is captured by a slot in the main window that updates the main window's gui. </p>
<p>Then I have another widget (let's call it programming widget) that pops from the main window, whi... | 0 | 2016-09-19T19:13:28Z | 39,616,388 | <p>I tried moving the Execute method to another thread using the <strong>worker model</strong> as suggested but it also froze the gui, I don't know why. Probably I did something wrong.</p>
<p>However, when I created another thread directly in the Class implemented to execute the loop and it worked. I followed this exa... | 0 | 2016-09-21T12:19:18Z | [
"python",
"multithreading",
"qt",
"dialog",
"pyqt"
] |
Levenshtein edit distance Python | 39,580,488 | <p>This piece of code returns the Levenshtein edit distance of 2 terms.
How can i make this so that insertion and deletion only costs 0.5 instead of 1 ? substitution should still costs 1.</p>
<pre><code>def substCost(x,y):
if x == y:
return 0
else:
return 1
def levenshtein(target, source):
i =... | 0 | 2016-09-19T19:15:32Z | 39,582,342 | <p>There are two places you need to account for the reduced cost of adding or removing a vowel. They are the <code>return j</code> and <code>return i</code> lines in the base cases of your function, and the <code>+1</code>s in the <code>min</code> call after the first two recursive calls.</p>
<p>We need to change each... | 1 | 2016-09-19T21:23:00Z | [
"python",
"levenshtein-distance"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.