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 |
|---|---|---|---|---|---|---|---|---|---|
Code for testing of data in a neural network after the training is complete | 37,827,613 | <p>I have modified a code found online for my use. The training of neural network is complete. But I am not sure how to go about with the testing of the data-set. My data-set consists of 350 entries, of which half I want to use for training and the other half for testing. Can anyone help me with how the code will look ... | 2 | 2016-06-15T06:26:48Z | 37,828,193 | <p>As I understood it, you want to use a neural network for <strong>classification of your data-set's entries</strong>.<br>
So after training, your network might be able to group those entries in <strong>6 different classes</strong>, since your last layer has 6 <em>neurons</em>. </p>
<p>Here's what I would to:</p>
<... | 0 | 2016-06-15T07:00:02Z | [
"python",
"numpy",
"testing",
"neural-network",
"training-data"
] |
PyCharm: Configuring multi-hop remote Interpreters via SSH | 37,827,685 | <p>To connect to the computer at my office I need to run ssh twice. First to connect to the host-1 and then from host-1 to host-2 and each one has different credentials. However the configuration menu in Pycharm only accepts one ssh tunnel.</p>
<p><a href="http://i.stack.imgur.com/KE7Sz.jpg" rel="nofollow">Configure R... | 3 | 2016-06-15T06:31:01Z | 38,212,999 | <p>You can use port forwarding on ssh.
If local system is <strong>A</strong>, the next ssh hop is <strong>B</strong>, and the target hop is <strong>C</strong>, open a terminal and run:
ssh -L 6000::22 @</p>
<p>You can substitute 6000 with any port.
Now you can ssh into the ssh server on <strong>C</strong> on another ... | 3 | 2016-07-05T21:24:24Z | [
"python",
"ssh",
"pycharm",
"ssh-tunnel"
] |
pypy pickled cannot be unpickled by cpython | 37,827,715 | <p>I have a piece of code which pickled by pypy, however, pypy add its own opcode to extend the cpython opcode, which cannot be unpickled by cpython(raise SystemError: unknown opcode).</p>
<p>It's caused by the special opcode: LOOKUP_METHOD & CALL_METHOD, just refer to <a href="http://doc.pypy.org/en/latest/interp... | 2 | 2016-06-15T06:32:47Z | 37,832,673 | <p>There aren't any options to disable the <code>LOOKUP_METHOD</code> optimization; you could try disabling <a href="https://github.com/mozillazg/pypy/blob/c97337f7b4485f91d719a0c984ae44fd3e91f4b7/pypy/interpreter/astcompiler/codegen.py#L983" rel="nofollow"><code>astcompiler.PythonCodeGenerator._optimize_method_call()<... | 2 | 2016-06-15T10:22:57Z | [
"python",
"cpython",
"pypy"
] |
Shift Pandas date index to next month | 37,827,795 | <p>I have a dataframe with a date index. I want to create a new column with a lagged value. That is, laggedfoo(1aug2016) = foo(1july2016)</p>
<p>I used dataframe.shift, but it didn't behave as expected; I can hack it to work, but I think I'm missing the big picture of how to treat and shift date indices.</p>
<p>Wh... | 1 | 2016-06-15T06:37:24Z | 37,827,947 | <p>I think you need change frequency to <code>month start frequency</code> - <code>MS</code> - see <a href="http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases" rel="nofollow"><code>offset-aliases</code></a>:</p>
<pre><code>import pandas as pd
fwd_df = pd.DataFrame({'Dubai m1': {pd.Timestamp('2... | 1 | 2016-06-15T06:47:33Z | [
"python",
"date",
"pandas",
"dataframe",
"datetimeindex"
] |
How to retrieve all OU of Active Directory in LDAP? | 37,827,798 | <p>I am using ldap3. I want to retrieve all Organizational units of AD.
Here is my code</p>
<pre><code>from ldap3 import Server, Connection, SUBTREE, ALL
total_entries = 0
s = Server('172.30.1.197', port=636, use_ssl=True, get_info=ALL)
admin_username = "Administrator@naanal.local"
admin_password = "p@ssw0rd1"
c = Co... | 0 | 2016-06-15T06:37:37Z | 37,837,301 | <p>The last three entries look like referrals. According to the docs, referral chasing can be disabled. See here: <a href="http://ldap3.readthedocs.io/connections.html" rel="nofollow">http://ldap3.readthedocs.io/connections.html</a></p>
<pre><code>c = Connection(s, user=admin_username, password=admin_password, auto_re... | 0 | 2016-06-15T13:45:33Z | [
"python",
"active-directory",
"ldap"
] |
Fluent interface with Python | 37,827,808 | <p>I have a Python function "send_message" which takes three arguments:</p>
<pre><code>send_message("i like windmills", to="INBOX", from="OUTBOX")
</code></pre>
<p>I am thinking about putting a fluent interface on top of it. Ideally I'd like to write the following:</p>
<pre><code>send_message("i like windmills").to(... | 1 | 2016-06-15T06:38:20Z | 37,827,955 | <p>It can be accomplished this way, I am unsure if there is a better way because this is my first attempt. Good luck!</p>
<pre><code>DEFAULT_SENDER = 'my_address'
#Because the sender object is optional I assume you have a default sender
class Send_message(object):
def __init__(self, message):
self.message... | 1 | 2016-06-15T06:47:45Z | [
"python",
"dsl",
"fluent-interface"
] |
Calculating overtime using python | 37,827,824 | <p>Hi I am python beginner!
Here is the questions I am having problem with!</p>
<p>Question:</p>
<p>Write a program to prompt the user for hours and rate per hour using raw_input to compute gross pay. Pay the hourly rate for the hours up to 40 and 1.5 times the hourly rate for all hours worked above 40 hours. Use 45 ... | 2 | 2016-06-15T06:39:26Z | 37,827,881 | <p>Your calculation is correct, you just need to format the output correctly. <code>%d</code> is for integers so changing to <code>%f</code> which is used for floats will do the trick:</p>
<pre><code>print "Your pay is %f" %pay
</code></pre>
<p>With above change you'll get following output:</p>
<pre><code>Your pay i... | 2 | 2016-06-15T06:44:05Z | [
"python"
] |
Calculating overtime using python | 37,827,824 | <p>Hi I am python beginner!
Here is the questions I am having problem with!</p>
<p>Question:</p>
<p>Write a program to prompt the user for hours and rate per hour using raw_input to compute gross pay. Pay the hourly rate for the hours up to 40 and 1.5 times the hourly rate for all hours worked above 40 hours. Use 45 ... | 2 | 2016-06-15T06:39:26Z | 37,827,884 | <p>Your code is correct, but you are using <code>%d</code> to print the value of variable <code>pay</code>, which converts it back to <code>int</code> and the decimal part is ignored.</p>
<p>So try using <code>%s</code> or <code>%f</code> or <code>%.2f</code>.</p>
| 2 | 2016-06-15T06:44:16Z | [
"python"
] |
Calculating overtime using python | 37,827,824 | <p>Hi I am python beginner!
Here is the questions I am having problem with!</p>
<p>Question:</p>
<p>Write a program to prompt the user for hours and rate per hour using raw_input to compute gross pay. Pay the hourly rate for the hours up to 40 and 1.5 times the hourly rate for all hours worked above 40 hours. Use 45 ... | 2 | 2016-06-15T06:39:26Z | 37,827,994 | <p>When you print the pay of the user, you use <code>%d</code> to print the actual pay. To display floating point numbers (such as 498.75), you have to use <code>%f</code> (or more precisely, <code>%.2f</code> since you can't pay someone less than 1 cent).</p>
<p>So this would be the correct way, that wields 498.75 :<... | 1 | 2016-06-15T06:49:47Z | [
"python"
] |
Get ping time in python | 37,827,864 | <p>I have made a program that tells me if I am connected to the internet or not. Now I want it to ping www.google.com and show me the ping time in ms. I don't want to use any 3rd party software or download anything.</p>
<p>Edit:
My code is:</p>
<pre><code>def is_connected():
try:
# see if we can resolve the hos... | -1 | 2016-06-15T06:42:59Z | 37,831,924 | <p>A ping is <strong>not</strong> the same thing as a HTTP connection! The first is a low level ICMP packet that is used to test connectiviy and find round-trip time mainly on a local network. It is generaly not used on broad internet, because for security reasons it is often blocked by firewall and external routers.</... | 1 | 2016-06-15T09:51:13Z | [
"python",
"windows",
"python-3.x"
] |
Opencv python error | 37,827,920 | <p>I followed <a href="http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/#comment-72178" rel="nofollow">this</a> to install opencv. When I tested the C and Java samples, they worked fine. But the python samples resulted in a </p>
<pre><code> import cv2
ImportError: No module named cv2
</... | 0 | 2016-06-15T06:46:04Z | 37,828,385 | <p>Ok. For using OpenCv in Python, you gotta do one more step. Find the file called cv2.so or cv2.pyd (I'm not sure which one it is.)in the OpenCv installation directory.. copy paste it to your site-packages folder inside Python installation directory. </p>
| 0 | 2016-06-15T07:09:22Z | [
"python",
"opencv"
] |
Opencv python error | 37,827,920 | <p>I followed <a href="http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/#comment-72178" rel="nofollow">this</a> to install opencv. When I tested the C and Java samples, they worked fine. But the python samples resulted in a </p>
<pre><code> import cv2
ImportError: No module named cv2
</... | 0 | 2016-06-15T06:46:04Z | 37,828,849 | <p>Install the library with apt, apt-get install python-opencv python-opencv-apps. It will resolve all the issues. </p>
| 0 | 2016-06-15T07:30:40Z | [
"python",
"opencv"
] |
how to convert this curl command to some Python codes that do the same thing? | 37,828,160 | <p>I am trying to download my data by using Fitbit API. I have figured out how to obtain a certain day's data, which is good. And here is the curl command I used:</p>
<pre><code>curl -i -H "Authorization: Bearer (here goes a very long token)" https://api.fitbit.com/1/user/-/activities/heart/date/2016-6-14/1d/1sec/time... | 2 | 2016-06-15T06:58:43Z | 37,828,440 | <p>The problem comes from the construction of the <code>Request</code> object : by default, the second parameter is the data that you want to pass along with the request. Instead, you have to specify that you want to pass headers. This is the correct way to do it :</p>
<pre><code>import urllib2
url = 'https://api.fitb... | 3 | 2016-06-15T07:11:30Z | [
"python",
"curl",
"request",
"urllib2"
] |
how to convert this curl command to some Python codes that do the same thing? | 37,828,160 | <p>I am trying to download my data by using Fitbit API. I have figured out how to obtain a certain day's data, which is good. And here is the curl command I used:</p>
<pre><code>curl -i -H "Authorization: Bearer (here goes a very long token)" https://api.fitbit.com/1/user/-/activities/heart/date/2016-6-14/1d/1sec/time... | 2 | 2016-06-15T06:58:43Z | 37,828,522 | <p>You can use the excellent lib <code>requests</code> which is much easier to use than <code>urllib</code>, in my opinion.</p>
<p>First, <code>pip install requests</code>, then in your interpreter:</p>
<pre><code>import requests
response = requests.get(url='https://api.fitbit.com/1/user/-/activities/heart/date/2016-... | 1 | 2016-06-15T07:15:23Z | [
"python",
"curl",
"request",
"urllib2"
] |
FFTshift causes oscillations - why? (numpy) | 37,828,241 | <p>my original problem was the following:</p>
<p>I have a pulse-envelope in an array a (0-element = time 0, last element = time T).
I want to fourier spectrum of the pulse. So what I did was <code>np.fft.fftshift(np.fft.fft(a))</code>. All good. </p>
<p>But then I was told to do a shift beforehand, too: <code>np.fft... | 1 | 2016-06-15T07:02:26Z | 37,831,829 | <p>Your line</p>
<pre><code>a_shift = np.fft.fftshift(a)
</code></pre>
<p>reorders your original time-domain signal. That means in terms of FFT that you are altering the phases.
Note also that there is a discontinuity in your signal. By the line above, this discontinuity is shifted to the center of the signal, which... | 2 | 2016-06-15T09:46:45Z | [
"python",
"numpy",
"fft",
"ifft"
] |
Scrapy cannot extract text from <a> | 37,828,387 | <p>On: <a href="http://web.unep.org/inquiry/news" rel="nofollow">http://web.unep.org/inquiry/news</a>, I want to get the headlines. Based on firefox Xpathchecker, the xpath is <code>//div[@class='highlighter']/a</code> (see <a href="http://i.stack.imgur.com/DeuG5.png" rel="nofollow">http://i.stack.imgur.com/DeuG5.png</... | 1 | 2016-06-15T07:09:26Z | 37,832,381 | <p><strong>The website has incorrect HTML markup</strong> regarding links inside those <code><div class="highlighter"></code> elements:</p>
<pre><code><div class="highlighter">
<a target="_blank" href="http://unep.org/newscentre/Default.aspx?DocumentID=27071&amp;ArticleID=36155&amp;l=en" />
N... | 0 | 2016-06-15T10:09:43Z | [
"python",
"xpath",
"scrapy"
] |
if and else in python lambda expression | 37,828,489 | <p>Please help me to understand how this works. Output is 4</p>
<pre><code>a=4
b=7
x=lambda: a if 1 else b
lambda x: 'big' if x > 100 else 'small'
print(x())
</code></pre>
| 0 | 2016-06-15T07:13:38Z | 37,828,669 | <p>Your <code>x</code> is always equals to 4, as it takes no arguments and <code>if 1</code> is always <code>True</code>.
Then you have lambda expression that's not assigned to any variable, neither used elsewhere.
Eventualy, you print out <code>x</code>, which is always <code>4</code> as I said above.</p>
<p>P.S. I s... | 0 | 2016-06-15T07:22:27Z | [
"python",
"if-statement",
"lambda"
] |
if and else in python lambda expression | 37,828,489 | <p>Please help me to understand how this works. Output is 4</p>
<pre><code>a=4
b=7
x=lambda: a if 1 else b
lambda x: 'big' if x > 100 else 'small'
print(x())
</code></pre>
| 0 | 2016-06-15T07:13:38Z | 37,828,705 | <p>Let me translate that for you. </p>
<p>You assign to <code>x</code> a <code>lambda</code> function with no arguments. Because 1 always evaluates as <code>true</code>, you always return the externally defined variable <code>a</code>, which evaluates as 4.
Then, you create a lambda function with one argument <code>x... | 0 | 2016-06-15T07:24:49Z | [
"python",
"if-statement",
"lambda"
] |
if and else in python lambda expression | 37,828,489 | <p>Please help me to understand how this works. Output is 4</p>
<pre><code>a=4
b=7
x=lambda: a if 1 else b
lambda x: 'big' if x > 100 else 'small'
print(x())
</code></pre>
| 0 | 2016-06-15T07:13:38Z | 37,828,740 | <p>First, let's remove this line as it doesn't do anything:</p>
<pre><code>lambda x: 'big' if x > 100 else 'small'
</code></pre>
<p>This <code>lambda</code> expression is defined but never called. The fact that it's argument is also called <code>x</code> has nothing to do with the rest of the code.</p>
<p>Let's ... | 1 | 2016-06-15T07:26:31Z | [
"python",
"if-statement",
"lambda"
] |
Basemap and Fiona won't install for processing of maps & shp files in iPython Notebook | 37,828,552 | <p>I'm a relatively new student of python and am still finding my way
around. I usually find answers pretty quickly via stack overflow but
this one leaves me stumped</p>
<p>I simply cannot get shape and map files to work with ipython notebook.
I can't seem to install basemap or fiona</p>
<p>Here is the command:</p>
... | 3 | 2016-06-15T07:16:47Z | 37,838,147 | <p>I recommend using the <a href="https://conda-forge.github.io/" rel="nofollow">conda-forge channel</a> to install those packages with <code>conda</code>. On the command line:</p>
<pre><code>conda install -c conda-forge pyshp fiona descartes
</code></pre>
<p>Using pip to install on windows will not work (you need th... | 3 | 2016-06-15T14:21:31Z | [
"python",
"pandas",
"matplotlib-basemap",
"geopandas"
] |
Basemap and Fiona won't install for processing of maps & shp files in iPython Notebook | 37,828,552 | <p>I'm a relatively new student of python and am still finding my way
around. I usually find answers pretty quickly via stack overflow but
this one leaves me stumped</p>
<p>I simply cannot get shape and map files to work with ipython notebook.
I can't seem to install basemap or fiona</p>
<p>Here is the command:</p>
... | 3 | 2016-06-15T07:16:47Z | 39,231,903 | <p>The simpler solution if you don't already have Anaconda installed is to simply install <code>libgdal-dev</code> from your system's package manager. E.g., <code>sudo apt-get install libgdal-dev</code>.</p>
| 1 | 2016-08-30T15:42:57Z | [
"python",
"pandas",
"matplotlib-basemap",
"geopandas"
] |
How to seperate last two digits with dot in Python | 37,828,567 | <p>I always want to separate the last two digits with a decimal point . (dot)L</p>
<pre><code>print("{:.2f}".format(300));
</code></pre>
<p>Output:</p>
<pre><code>300.00
</code></pre>
<p>Expected output:</p>
<pre><code>3.00
</code></pre>
<p>Next</p>
<pre><code>print("{:.2f}".format(333333300));
</code></pre>
<p... | 1 | 2016-06-15T07:17:36Z | 37,828,612 | <p><code>300.00</code> is a representation of number <code>300</code>. <code>3.00</code> is a representation of number <code>3</code>. Those are two different values. There is no way Python will represent <code>300</code> as <code>3</code>.</p>
<p>Assuming you really want to print <code>3.00</code> (which for pretty m... | 2 | 2016-06-15T07:19:43Z | [
"python"
] |
How to seperate last two digits with dot in Python | 37,828,567 | <p>I always want to separate the last two digits with a decimal point . (dot)L</p>
<pre><code>print("{:.2f}".format(300));
</code></pre>
<p>Output:</p>
<pre><code>300.00
</code></pre>
<p>Expected output:</p>
<pre><code>3.00
</code></pre>
<p>Next</p>
<pre><code>print("{:.2f}".format(333333300));
</code></pre>
<p... | 1 | 2016-06-15T07:17:36Z | 37,828,630 | <p>Use the number value you actually want to output, i.e. don't add the '0' you want in the string representation.</p>
<pre><code>print("{:.2f}".format(3))
</code></pre>
<p>It is the string formatting which does add the '0' for you when it creates the string representation of the number value, depending on the specif... | 0 | 2016-06-15T07:20:38Z | [
"python"
] |
How to seperate last two digits with dot in Python | 37,828,567 | <p>I always want to separate the last two digits with a decimal point . (dot)L</p>
<pre><code>print("{:.2f}".format(300));
</code></pre>
<p>Output:</p>
<pre><code>300.00
</code></pre>
<p>Expected output:</p>
<pre><code>3.00
</code></pre>
<p>Next</p>
<pre><code>print("{:.2f}".format(333333300));
</code></pre>
<p... | 1 | 2016-06-15T07:17:36Z | 37,831,056 | <pre><code>def f(n):
a = divmod(n,100)
if a[1] < 10:
print("{}.0{}".format(a[0],a[1]))
else:
print("{}.{}".format(a[0],a[1]))
</code></pre>
| 0 | 2016-06-15T09:11:50Z | [
"python"
] |
How to seperate last two digits with dot in Python | 37,828,567 | <p>I always want to separate the last two digits with a decimal point . (dot)L</p>
<pre><code>print("{:.2f}".format(300));
</code></pre>
<p>Output:</p>
<pre><code>300.00
</code></pre>
<p>Expected output:</p>
<pre><code>3.00
</code></pre>
<p>Next</p>
<pre><code>print("{:.2f}".format(333333300));
</code></pre>
<p... | 1 | 2016-06-15T07:17:36Z | 37,831,722 | <p>In Python 2.6 :</p>
<pre><code>def myPrint(x):
print("{0:.2f}".format(x/100.00));
myPrint(2990);
</code></pre>
<p>29.90</p>
| 0 | 2016-06-15T09:41:23Z | [
"python"
] |
Python IndexError: list assignment index out of range when listing txt file | 37,828,584 | <p>So, I got this error </p>
<pre><code> Traceback (most recent call last):
File **, line 15, in <module>
del a[del_line]
IndexError: list assignment index out of range
</code></pre>
<p>I am trying to make a program that will generate password combinations, but delete them almost immediately... | 2 | 2016-06-15T07:18:19Z | 37,829,237 | <p>Possibly, you should add </p>
<pre><code>f1.flush()
</code></pre>
<p>after </p>
<pre><code>print(''.join(i), file=f1)
</code></pre>
<p>Explanation: <a href="http://stackoverflow.com/questions/7127075/what-exactly-the-pythons-file-flush-is-doing">what exactly the python's file.flush() is doing?</a></p>
<hr>
... | 0 | 2016-06-15T07:50:05Z | [
"python",
"python-2.7"
] |
Python IndexError: list assignment index out of range when listing txt file | 37,828,584 | <p>So, I got this error </p>
<pre><code> Traceback (most recent call last):
File **, line 15, in <module>
del a[del_line]
IndexError: list assignment index out of range
</code></pre>
<p>I am trying to make a program that will generate password combinations, but delete them almost immediately... | 2 | 2016-06-15T07:18:19Z | 37,829,632 | <p><strong>Updated:</strong></p>
<pre><code>from __future__ import print_function
import itertools
import sys
from time import sleep
f1 = open("passfile.txt", "w")
res = itertools.product("ABCD", repeat=2)
for i in res:
text = ""
for string in i: # makes the iterated i 'readable', i is a list with each lette... | 0 | 2016-06-15T08:09:43Z | [
"python",
"python-2.7"
] |
How to uninstall Python/pygame/Homebrew on Mac? | 37,828,607 | <p>When trying to install pygame for Python3 on my mac I mainly followed <a href="http://brysonpayne.com/2015/01/10/setting-up-pygame-on-a-mac/" rel="nofollow">this guide</a>. However, this ultimately didn't accomplish anything, aside from screwing something up in my Terminal path and giving me the problem described <a... | 0 | 2016-06-15T07:19:36Z | 37,829,556 | <p>follow the steps for <a href="https://coolestguidesontheplanet.com/add-shell-path-osx/" rel="nofollow">'Adding in a Permanent Location'</a></p>
<p>And with homebrew you can always run <code>brew uninstall <program-name></code></p>
<p>I'm sorry you are having so much trouble with unix, it really is an awesome... | 0 | 2016-06-15T08:05:59Z | [
"python",
"osx",
"homebrew"
] |
Django : django.db.utils.OperationalError: unable to open database file | 37,828,762 | <p>Stack trace:</p>
<pre><code>System check identified no issues (0 silenced).
Unhandled exception in thread started by <function wrapper at 0x7f58375ac9b0>
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
File... | -4 | 2016-06-15T07:27:26Z | 37,829,259 | <p>You should show your database settings here and put your error log in a better format.</p>
<p>I guess you're using SQLite, right? If so please check your data file path:
- Is it correct? Should be full-path.
- Does your app has right permissions (read/write) on it and its parent directories
- Make sure its parent d... | 0 | 2016-06-15T07:51:16Z | [
"python",
"django"
] |
Creating Custom SessionStore for a django project | 37,828,926 | <p>If I want to subclass a module such as <code>django.contrib.sessions.backends.db.SessionStore</code> so that I can override a lot of its default behaviour, what is the standard way of doing this in Django?</p>
<p>Suppose I create a file called <code>mydb.py</code>:</p>
<pre><code>from django.contrib.sessions.backe... | 0 | 2016-06-15T07:34:25Z | 37,829,453 | <p>You should refer to it as to the file:</p>
<pre><code>SESSION_ENGINE = 'python.path.mydb'
</code></pre>
<p><a href="https://docs.djangoproject.com/ja/1.9/topics/http/sessions/#extending-database-backed-session-engines" rel="nofollow">Django docs</a> is missing this little detail. In <code>django/contrib/sessions/m... | 1 | 2016-06-15T08:00:53Z | [
"python",
"django"
] |
Class construktion: Save and write data | 37,829,129 | <p>I need to save file and write into a class.I have some problems.</p>
<ol>
<li><p>when the file is saved I got always error what I don't will. I would like exception only wenn necesarry and in that case delete the saved file.</p></li>
<li><p>With my code i can't write to text file.What could be a problem with my fun... | 0 | 2016-06-15T07:44:33Z | 37,832,707 | <p>The function <code>SaveFile</code> must be repaired.</p>
<pre><code>def SaveFile(self):
self.file_opt = self.options = {}
self.options['filetypes'] = [('Text Files', '.txt')]
self.dataname = asksaveasfilename(**self.file_opt)
self.datamode = 'a'
try:
self.fout = o... | 0 | 2016-06-15T10:24:27Z | [
"python"
] |
Neural network only learns most common training image | 37,829,169 | <p>I'm building a neural net using TensorFlow and Python, and using the Kaggle 'First Steps with Julia' dataset to train and test it. The training images are basically a set of images of different numbers and letters picked out of Google street view, from street signs, shop names, etc. The network has 2 fully-connected... | 0 | 2016-06-15T07:46:55Z | 37,829,933 | <p>Your learning rate is way too high. It should be around <code>0.01</code>, you can experiment around it but <code>0.5</code> is too high.</p>
<p>With a high learning rate, the network is likely to get stuck in a configuration and output something fixed, like you observed.</p>
<hr>
<h3>EDIT</h3>
<p>It seems the r... | 0 | 2016-06-15T08:24:43Z | [
"python",
"neural-network",
"tensorflow"
] |
Neural network only learns most common training image | 37,829,169 | <p>I'm building a neural net using TensorFlow and Python, and using the Kaggle 'First Steps with Julia' dataset to train and test it. The training images are basically a set of images of different numbers and letters picked out of Google street view, from street signs, shop names, etc. The network has 2 fully-connected... | 0 | 2016-06-15T07:46:55Z | 37,846,462 | <p>Which optimizer are you using? If you've only tried gradient descent, try using one of the adaptive ones (e.g. adagrad/adadelta/adam).</p>
| 0 | 2016-06-15T21:55:04Z | [
"python",
"neural-network",
"tensorflow"
] |
Neural network only learns most common training image | 37,829,169 | <p>I'm building a neural net using TensorFlow and Python, and using the Kaggle 'First Steps with Julia' dataset to train and test it. The training images are basically a set of images of different numbers and letters picked out of Google street view, from street signs, shop names, etc. The network has 2 fully-connected... | 0 | 2016-06-15T07:46:55Z | 37,846,825 | <p>Trying to squeeze blood from a stone!</p>
<p>I'm skeptical that with 4283 training examples your net will learn 62 categories...that's a big ask for such a small amount of data. Especially since your net is not a conv net...and it's forced to reduce its dimensionality to 100 at the first layer. You may as well pc... | 1 | 2016-06-15T22:25:05Z | [
"python",
"neural-network",
"tensorflow"
] |
Neural network only learns most common training image | 37,829,169 | <p>I'm building a neural net using TensorFlow and Python, and using the Kaggle 'First Steps with Julia' dataset to train and test it. The training images are basically a set of images of different numbers and letters picked out of Google street view, from street signs, shop names, etc. The network has 2 fully-connected... | 0 | 2016-06-15T07:46:55Z | 37,861,304 | <p>I'm afraid that this was a rookie mistake. When turning the data from a folder of images to a single .pickle file, I used:</p>
<pre><code> imageFileNames = os.listdir(folder)
</code></pre>
<p>to get the all the image file names in that folder. As it turns out, this returns the file names in an <strong><em>arbitra... | 0 | 2016-06-16T13:53:20Z | [
"python",
"neural-network",
"tensorflow"
] |
Error while pip installing pyobjc | 37,829,266 | <p>I am trying to install pyobjc-core which is a requirement for pyautogui. I am getting the below error while installing. I have already updated setuptools using
pip3 install --upgrade setuptools and also using sudo python3 ez_setup.py. I am on OSX Yosemite and using Python 3.5. </p>
<p>I see that the code below h... | 1 | 2016-06-15T07:51:29Z | 37,829,906 | <p>yep, the error is clear, you need xcode... it's silly but unfortunately there are these "developer tools" that are tied to it, and since many packages require dev tools (in your specific case "xcodebuild" needs it) you have to install xcode (anyway it's free)</p>
| 1 | 2016-06-15T08:23:31Z | [
"python",
"xcode",
"osx",
"pyobjc"
] |
Pandas python updating values in a table based on preexisting values and conditions | 37,829,330 | <p>I have a dataframe:</p>
<pre><code>import pandas as pd
df=pd.DataFrame({
'Player': ['John','John','John','Steve','Steve','Ted', 'James','Smitty','SmittyJr','DJ'],
'Name': ['A','B', 'A','B','B','C', 'A','D','D','D'],
'Group':['2A','1B','2A','2A','1B','1C','2A','1C','1C','2A'],
'Medal':['G', '?', '?', 'S', 'B','?','... | 2 | 2016-06-15T07:54:48Z | 37,829,456 | <p>Try:</p>
<pre><code>import pandas as pd
import numpy as np
myfill = lambda df: df.ffill().bfill()
df.replace('?', np.nan).groupby(['Name', 'Group']).apply(myfill).fillna('?')
Player Group Name Medal
0 John 2A A G
1 John 1B B B
2 John 2A A G
3 Steve 2A B ... | 1 | 2016-06-15T08:01:01Z | [
"python",
"pandas",
"dataframe",
"iteration",
"condition"
] |
Pandas python updating values in a table based on preexisting values and conditions | 37,829,330 | <p>I have a dataframe:</p>
<pre><code>import pandas as pd
df=pd.DataFrame({
'Player': ['John','John','John','Steve','Steve','Ted', 'James','Smitty','SmittyJr','DJ'],
'Name': ['A','B', 'A','B','B','C', 'A','D','D','D'],
'Group':['2A','1B','2A','2A','1B','1C','2A','1C','1C','2A'],
'Medal':['G', '?', '?', 'S', 'B','?','... | 2 | 2016-06-15T07:54:48Z | 37,829,826 | <p>Another solution with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.replace.html" rel="nofollow"><code>replace</code></a> <code>?</code> by last value (with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.iloc.html" rel="nofollow"><code>iloc</code></a>) of ... | 2 | 2016-06-15T08:19:42Z | [
"python",
"pandas",
"dataframe",
"iteration",
"condition"
] |
Can you have required keyword arguments in Javascript or Python? | 37,829,344 | <p>Can you have required keyword arguments in javascript or python? Is this a common feature of programming languages, or is it new and rare? They would be analogous to this implementation of keyword arguments in Ruby in Ruby 2.1+</p>
<pre><code>def obvious_total(subtotal:, tax:, discount:)
subtotal + tax - discount... | 0 | 2016-06-15T07:55:32Z | 37,829,651 | <p><a href="http://python.org/dev/peps/pep-3102" rel="nofollow">PEP-3102</a> introduced <em>"keyword-only arguments"</em>, so in Python 3.x you could do:</p>
<pre class="lang-py prettyprint-override"><code>def obvious_total(*, subtotal, tax, discount):
"""Calculate the total and force keyword arguments."""
ret... | 2 | 2016-06-15T08:10:55Z | [
"javascript",
"python",
"ruby",
"keyword-argument"
] |
Python bokeh - linking timeseries | 37,829,410 | <p>Is it possible to link to high level bokeh timeseries on panning ?
the documentation <a href="http://bokeh.pydata.org/en/0.11.1/docs/user_guide/interaction.html" rel="nofollow">http://bokeh.pydata.org/en/0.11.1/docs/user_guide/interaction.html</a> only speaks about low-level plot. I didn't find any info on the net a... | 3 | 2016-06-15T07:58:48Z | 40,034,517 | <p>Although my bokeh plots are embedded and served in a Django app, I believe I have stumbled on a solution to this. Instead of specifying x_range and y_range inside the TimeSeries constructor, put these lines after the two TimeSeries objects have been created:</p>
<pre><code>fig_ca.x_range = ew_kpi.x_range
fig_ca.y_r... | 0 | 2016-10-14T03:33:53Z | [
"python",
"bokeh"
] |
Python Inverted Circle (Turtle) | 37,829,553 | <p><a href="http://i.stack.imgur.com/pUNcV.png" rel="nofollow"><img src="http://i.stack.imgur.com/pUNcV.png" alt=""></a></p>
<p>How do you draw an inverted circle in Python using turtle only? i.e. a circle which is drawn clockwise rather than the traditional way of drawing one anticlockwise.</p>
<p>The current turtle... | -3 | 2016-06-15T08:05:50Z | 37,830,915 | <pre><code>x=turtle.Turtle()
x.right(90)
x.forward(100)
x.right(90)
x.circle(100)
</code></pre>
| 0 | 2016-06-15T09:06:50Z | [
"python",
"python-2.7",
"python-3.x",
"turtle-graphics"
] |
QTextEdit doesn't make new line when reaching field border | 37,829,600 | <p>I am trying to make a chat application, so there is a text box where user types in the content.
The TextEdit box, would resize dynamically every time, when i just pressed return, but when it reaches the end of the field, unfortunately, it just increases by a little automatically.</p>
<pre><code>def func(self):
... | 1 | 2016-06-15T08:08:06Z | 37,830,165 | <p>This is an interesting question since it actually involves measuring the text width and height given line breaks but also given possible word wrapping. All subject to constraints (i.e. the width)</p>
<p>My suggestion is not to count the number of new lines etc rather than to let <code>Qt</code> measure the <a href=... | 0 | 2016-06-15T08:35:18Z | [
"python",
"pyqt"
] |
Removing duplicates dictionary from a list except one dictionary can be duplicate using python | 37,829,789 | <p>I have a list like </p>
<pre><code>d=[{'date': datetime.datetime(2016, 6, 3, 8, 32, 35), 'temp': 39.1}, {'date': datetime.datetime(2016, 6, 3, 9, 32, 35), 'temp': 39.1}, {'date': datetime.datetime(2016, 6, 3, 9, 32, 35), 'temp': 39.1}, {'date': None, 'temp': None}, {'date': datetime.datetime(2016, 6, 3, 11, 32, 35)... | 0 | 2016-06-15T08:18:11Z | 37,829,962 | <p>If you are okay with non-list-comprehension solution, then try this:</p>
<pre><code>>>> result = []
>>> for i in d:
... if (i not in result) or (i == {'date': None, 'temp': None}):
... result.append(i)
</code></pre>
| 0 | 2016-06-15T08:26:17Z | [
"python",
"duplicates"
] |
Removing duplicates dictionary from a list except one dictionary can be duplicate using python | 37,829,789 | <p>I have a list like </p>
<pre><code>d=[{'date': datetime.datetime(2016, 6, 3, 8, 32, 35), 'temp': 39.1}, {'date': datetime.datetime(2016, 6, 3, 9, 32, 35), 'temp': 39.1}, {'date': datetime.datetime(2016, 6, 3, 9, 32, 35), 'temp': 39.1}, {'date': None, 'temp': None}, {'date': datetime.datetime(2016, 6, 3, 11, 32, 35)... | 0 | 2016-06-15T08:18:11Z | 37,830,029 | <p>You could simply add an <code>or</code>:</p>
<pre><code>result = [i for n, i in enumerate(d) if i not in d[n + 1:] or i == {'date': None, 'temp': None}]
</code></pre>
| 0 | 2016-06-15T08:29:10Z | [
"python",
"duplicates"
] |
If statement not working properly in python | 37,829,794 | <p>First, I opened the file and wrote some numbers to it.</p>
<pre><code>writeFile = open("charge_accounts.txt", "w")
writeFile.write("5658845\n")
writeFile.write("4520125\n")
writeFile.write("7895122\n")
writeFile.write("8777541\n")
writeFile.write("8451277\n")
writeFile.write("1302850\n")
writeFile.write("8080152\n"... | -1 | 2016-06-15T08:18:16Z | 37,829,912 | <p>Each of the <code>line</code> strings still has the <code>\n</code> at it's end, so even though the lines and numbers seem to be the same, <code>if line in digit:</code> can not work. Instead, reverse it:</p>
<pre><code>if digit in line:
</code></pre>
<p>Also, <code>digit</code> is already a string after <code>raw... | 0 | 2016-06-15T08:23:42Z | [
"python",
"for-loop"
] |
If statement not working properly in python | 37,829,794 | <p>First, I opened the file and wrote some numbers to it.</p>
<pre><code>writeFile = open("charge_accounts.txt", "w")
writeFile.write("5658845\n")
writeFile.write("4520125\n")
writeFile.write("7895122\n")
writeFile.write("8777541\n")
writeFile.write("8451277\n")
writeFile.write("1302850\n")
writeFile.write("8080152\n"... | -1 | 2016-06-15T08:18:16Z | 37,830,028 | <p>This will work :-</p>
<pre><code> digit = raw_input('Input seven-digit account number: ')
digit2 = len(str(digit))
digit = str(digit)
if digit2 == 7:
print 'hello'
text = open('charge_accounts.txt', "r")
for line in text:
digit3 = line
print 'here', lin... | 0 | 2016-06-15T08:29:11Z | [
"python",
"for-loop"
] |
Cannot run convolutional.py in anaconda tenserenv | 37,829,898 | <p>I have installed tensorflow in an anaconda environment called tensorenv and to test the installation I tried to run one of the examples convolutional.py and the follwing comes up.</p>
<pre><code>Initialized!
E tensorflow/stream_executor/cuda/cuda_dnn.cc:346] Loaded cudnn library: 5005 but source was compiled agains... | 2 | 2016-06-15T08:23:09Z | 37,830,066 | <p>You have to build from source if you want to use cuDNN v5.</p>
<p>According to the documentation:</p>
<blockquote>
<p>Other versions are supported (Cuda toolkit >= 7.0 and cuDNN 6.5(v2), 7.0(v3), v5) only when installing from sources</p>
</blockquote>
| 1 | 2016-06-15T08:30:58Z | [
"python",
"tensorflow",
"anaconda",
"cudnn"
] |
Python: Separate class methods from the class in an own package | 37,830,020 | <p>I wrote a class with many different parameters, depending on the parameter the class uses different actions.</p>
<p>I can easily differentiate my methods into different cases, each set of methods belonging to certain parameters.</p>
<p>This resulted in a huge .py file, implementing all methods in the one class. Fo... | 0 | 2016-06-15T08:28:56Z | 37,830,779 | <p>For better readability, I got a few suggestions.</p>
<ol>
<li>Collapse all functions definitions, which can easily be achieved by
one click in most of the popular text editors.</li>
<li>Place related methods next to each other.</li>
<li><p>Give proper names to categorise and differentiate methods, for
example.</p>... | 0 | 2016-06-15T09:02:04Z | [
"python",
"python-3.x",
"methods",
"packages",
"class-method"
] |
Print a list with names and ages and show their average age | 37,830,051 | <p>So I am suposed to print a list with names and ages, each on a seperate row and then show their averagea age and I need some help.
This is what I got so far:</p>
<pre><code>namn = ["Lena", 22, "Jonas", 26, "Anna", 27, "Kalle", 23, "Erik", 30, "Josefine", 20, "Emelie", 32, "Johanna", 29,
"Peter", 19]
</code></pr... | -4 | 2016-06-15T08:30:22Z | 37,830,402 | <p>you must first create a dictionary.
Here`s the code</p>
<pre><code>def name_age(namn):
dic = {}
age = 0
for n in range(0, len(namn), 2):
dic[namn[n]] = namn[n+1]
for i in dic:
print i, dic[i]
age = age + dic[i]
avg_age = age / len(dic)
return avg_age
</code></pre>
| 0 | 2016-06-15T08:45:17Z | [
"python",
"python-2.7"
] |
Print a list with names and ages and show their average age | 37,830,051 | <p>So I am suposed to print a list with names and ages, each on a seperate row and then show their averagea age and I need some help.
This is what I got so far:</p>
<pre><code>namn = ["Lena", 22, "Jonas", 26, "Anna", 27, "Kalle", 23, "Erik", 30, "Josefine", 20, "Emelie", 32, "Johanna", 29,
"Peter", 19]
</code></pr... | -4 | 2016-06-15T08:30:22Z | 37,833,123 | <p>This should work:</p>
<pre><code>data = {name: age for name, age in zip(namn[0::2], namn[1::2])}
for name, age in data.iteritems():
print '%11s: %d' % (name, age)
print 'Average age: %f' % (sum(data.values())/float(len(data)))
</code></pre>
| 0 | 2016-06-15T10:41:08Z | [
"python",
"python-2.7"
] |
Print a list with names and ages and show their average age | 37,830,051 | <p>So I am suposed to print a list with names and ages, each on a seperate row and then show their averagea age and I need some help.
This is what I got so far:</p>
<pre><code>namn = ["Lena", 22, "Jonas", 26, "Anna", 27, "Kalle", 23, "Erik", 30, "Josefine", 20, "Emelie", 32, "Johanna", 29,
"Peter", 19]
</code></pr... | -4 | 2016-06-15T08:30:22Z | 37,833,622 | <p>This also works:</p>
<pre><code>pairs = dict([tuple(namn[i:i+2]) for i in range(0, len(namn), 2)])
for name, age in sorted(pairs.items()):
print("%s: %d" % (name, age))
avg_age = sum(pairs.values())/ len(pairs)
print("Average Age: %f" % (avg_age))
</code></pre>
<p>Output:</p>
<pre><code>Anna: 27
Emelie: 32
E... | 0 | 2016-06-15T11:04:39Z | [
"python",
"python-2.7"
] |
Draw colored checkers grid in python | 37,830,053 | <p>i need to draw a colored checkers grid in an existing image, with colors taken from a list.
This is the code i have:</p>
<pre><code>import image as im
def draw_gen_checkers(img, s, colors):
n = 0
for i in range(len(img)/s):
for j in range(len(img[0])/s):
for ii in range(i*s, i*s+s):
... | 0 | 2016-06-15T08:30:24Z | 37,830,764 | <p>Glad to see your work progress :)</p>
<p>Let's do the math : your picture is 300px long, your cases are 25px long, so you have 12 cases per line, since you have 4 colors you have 12 // 4 == 3 color rotations by line, but since 12 % 3 == 0, when you start your new line, your n is back to 0. And nowhere you say that ... | 0 | 2016-06-15T09:01:24Z | [
"python",
"image",
"colors",
"grid"
] |
Draw colored checkers grid in python | 37,830,053 | <p>i need to draw a colored checkers grid in an existing image, with colors taken from a list.
This is the code i have:</p>
<pre><code>import image as im
def draw_gen_checkers(img, s, colors):
n = 0
for i in range(len(img)/s):
for j in range(len(img[0])/s):
for ii in range(i*s, i*s+s):
... | 0 | 2016-06-15T08:30:24Z | 37,831,463 | <pre><code>def draw_gen_checkers(img, s, colors):
n = 0
for i in range(len(img)/s + 1):
for j in range(len(img[0])/s + 1):
for ii in range(i*s, i*s+s):
for jj in range(j*s,j*s+s):
if 0 <= ii < len(img) and 0 <= jj < len(img[0]):
img[ii][jj] = color... | 0 | 2016-06-15T09:30:13Z | [
"python",
"image",
"colors",
"grid"
] |
How to avoid "WindowsError: [Error 5] Access is denied" | 37,830,326 | <p>There's the script to re-create folder:</p>
<pre><code># Remove folder (if exists) with all files
if os.path.isdir(str(os.path.realpath('..') + "\\my_folder")):
shutil.rmtree(os.path.realpath('..') + "\\my_folder", ignore_errors=True)
# Create new folder
os.mkdir(os.path.realpath('..') + "\\my_folder")
</co... | 2 | 2016-06-15T08:41:44Z | 37,830,578 | <p>It happens because you are not checking if you have permissions to open that path. You need to change the permissions on those folders.</p>
| 1 | 2016-06-15T08:53:15Z | [
"python",
"python-2.7",
"windowserror"
] |
How to avoid "WindowsError: [Error 5] Access is denied" | 37,830,326 | <p>There's the script to re-create folder:</p>
<pre><code># Remove folder (if exists) with all files
if os.path.isdir(str(os.path.realpath('..') + "\\my_folder")):
shutil.rmtree(os.path.realpath('..') + "\\my_folder", ignore_errors=True)
# Create new folder
os.mkdir(os.path.realpath('..') + "\\my_folder")
</co... | 2 | 2016-06-15T08:41:44Z | 37,831,625 | <p><strong>What could cause this error?</strong></p>
<p>You simply do not have access to the folder you are writing in for the process that is currently running (python.exe), or maybe even for the user. Unless your user is an admin there may be directories for which you do not have write permissions. </p>
<hr>
<p><s... | 1 | 2016-06-15T09:37:13Z | [
"python",
"python-2.7",
"windowserror"
] |
How do I create a new pandas DataFrame containing specific values? | 37,830,335 | <p>I have a pandas DataFrame containing values for <code>Year</code> and <code>Month</code> (represented as integers) like this:</p>
<pre><code>df.head(5)
Year Month
0 1997 1
1 1997 8
2 2010 9
3 1998 1
4 2009 10
</code></pre>
<blockquote>
<p>I want to create a new DataFrame con... | 0 | 2016-06-15T08:41:58Z | 37,830,359 | <p>Use <code>isin</code> and pass your list to filter the df:</p>
<pre><code>In [168]:
df = pd.DataFrame({'Year':np.arange(1997,2010), 'Month':np.arange(13)})
df[df['Year'].isin([1996, 2000, 2002])]
Out[168]:
Month Year
3 3 2000
5 5 2002
</code></pre>
<p>What you tried fails because <code>and</code> ... | 1 | 2016-06-15T08:43:38Z | [
"python",
"pandas"
] |
Set a custom icon to balloon tooltip using win32gui with python? | 37,830,338 | <p>I've been seeing a lot of post and question about this in other languages, C# mostly, but not in python.</p>
<p>I'm using windows 10, and when creating a balloon tooltip notification, the custom icon I'm using show itself blurry and with a black field arround it, I've tried with different icons, with different imag... | 0 | 2016-06-15T08:42:13Z | 39,057,439 | <p>To use a user-supplied icon for the notification popup (the successor to the balloon tooltip in recent versions of Windows), in <code>NOTIFYICONDATA</code> put the icon handle in <code>hIcon</code> as usual, and put a value of 4 (<code>NIIF_USER</code>) in your <code>dwInfoFlags</code>:</p>
<pre><code>NIIF_USER = 4... | 0 | 2016-08-20T18:29:29Z | [
"python",
"windows",
"notifications",
"win32gui"
] |
extracting attribute value from html | 37,830,389 | <pre><code>import requests
from bs4 import BeautifulSoup
r = requests.get("http://www.nepalstock.com.np/marketdepthofcompany/238")
soup = BeautifulSoup(r.content,"lxml")
value_select = soup.select_one("select.form-control")
for val in value_select.find("option")[1:]:
n = val['value']
print (n)
</code></pre>
<... | 1 | 2016-06-15T08:44:37Z | 37,830,743 | <p>Because <code>find</code> returns a single tag, you need <code>find_all</code>:</p>
<pre><code>for val in value_select.find_all("option")[1:]:
n = val['value']
print (n)
</code></pre>
<p>Or use a css selector to skip the first option:</p>
<pre><code>for val in value_select.select("option + option"):
</cod... | 2 | 2016-06-15T09:00:45Z | [
"python",
"web-scraping",
"beautifulsoup"
] |
Combine regular expression in Python | 37,830,404 | <p>I'm newbie in regular expression.</p>
<p>I'm trying to get list of service that are up or down in svstat command.</p>
<p>Example output of svstat:</p>
<pre><code>/etc/service/worker-test-1: up (pid 1234) 97381 seconds
/etc/service/worker-test-2: up (pid 4567) 92233 seconds
/etc/service/worker-test-3: up (pid 8910... | 0 | 2016-06-15T08:45:24Z | 37,830,771 | <p>You could enclose <code>pid</code> to optional non-capturing group:</p>
<pre><code>/etc/service/(?P<service_name>.+):\s(?P<status>up|down)(?:\s\(pid\s(?P<pid>\d+)\))?\s(?P<seconds>\d+)
</code></pre>
<p>This would result <code>pid</code> being <code>None</code> in case service is down. See <... | 1 | 2016-06-15T09:01:48Z | [
"python",
"regex",
"python-2.7"
] |
Combine regular expression in Python | 37,830,404 | <p>I'm newbie in regular expression.</p>
<p>I'm trying to get list of service that are up or down in svstat command.</p>
<p>Example output of svstat:</p>
<pre><code>/etc/service/worker-test-1: up (pid 1234) 97381 seconds
/etc/service/worker-test-2: up (pid 4567) 92233 seconds
/etc/service/worker-test-3: up (pid 8910... | 0 | 2016-06-15T08:45:24Z | 37,831,258 | <p>I don't know if you are forced to use regex at all but if you don't have to, you can do something like this:</p>
<pre><code>if "down" in linetext:
print( "is down" )
else:
print( "is up" )
</code></pre>
<p>Easier to read and faster as well. </p>
| -1 | 2016-06-15T09:21:12Z | [
"python",
"regex",
"python-2.7"
] |
Combine regular expression in Python | 37,830,404 | <p>I'm newbie in regular expression.</p>
<p>I'm trying to get list of service that are up or down in svstat command.</p>
<p>Example output of svstat:</p>
<pre><code>/etc/service/worker-test-1: up (pid 1234) 97381 seconds
/etc/service/worker-test-2: up (pid 4567) 92233 seconds
/etc/service/worker-test-3: up (pid 8910... | 0 | 2016-06-15T08:45:24Z | 37,831,618 | <p>As promised here my lunchbreak alternative (do not want to talk into fixed token split parsing, but might come in handy when considering the rest of the use case that only the OP knows ;-)</p>
<pre><code>#! /usr/bin/env python
from __future__ import print_function
d = """
/etc/service/worker-test-1: up (pid 1234) ... | 1 | 2016-06-15T09:36:58Z | [
"python",
"regex",
"python-2.7"
] |
Implicty wait selenium Python 2.7 not working | 37,830,433 | <p>I am scraping public linkedIn data from specific people.
here is the code inside the while loop. For you to know, I used time.sleep() for the first 400 profils urls and it worked. However, it is not working anymore as it makes my firefox browser crash. I am pretty sure that the bug comes from the time.sleep() funct... | 0 | 2016-06-15T08:46:40Z | 37,830,955 | <p>With WebDriverWait, the browser waits but firefox crashes again: here the code</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expe... | 0 | 2016-06-15T09:08:12Z | [
"python",
"selenium",
"wait"
] |
Creating a zero vector,and modifying it in theano | 37,830,512 | <p>I need to create a some fixed length(length equal to size of some other tensor vector which is passed) zero vector in theano.</p>
<pre><code>def some_fun(self, y)
x_h = T.fvector('x_h')
ret = T.alloc(0, x_h)
vec_h = theano.function(inputs=[x_h], outputs=ret)
vec=vec_h(y.shape[0])
vec[T.arange(y.... | 0 | 2016-06-15T08:50:31Z | 37,833,398 | <p>Have you tried <a href="http://deeplearning.net/software/theano/library/tensor/basic.html#theano.tensor.zeros_like" rel="nofollow">theano.tensor.zeros_like</a>? It seems like that should be a shortcut to what you're trying to do.</p>
<p>Then, when you get </p>
<blockquote>
<p>"TypeError: 'TensorVariable' object ... | 1 | 2016-06-15T10:52:46Z | [
"python",
"theano",
"deep-learning"
] |
How to write query in django to join two tables? | 37,830,640 | <p>class Subscriber(Model):</p>
<pre><code>"""This defines the Contact imported to a Campaign
**Attributes**:
* ``last_attempt`` - last call attempt date
* ``count_attempt`` - Count the amount of call attempt
* ``completion_count_attempt`` - Count the amount of attempt to call in order to achieve completio... | 0 | 2016-06-15T08:55:54Z | 37,830,809 | <p>Given you have contact:</p>
<pre><code>contact = Contact.objects.get(id=contact_id)
</code></pre>
<p>you get the subscriber:</p>
<pre><code>subscriber = Subscriber.objects.filter(contact=contact)
</code></pre>
| 0 | 2016-06-15T09:02:55Z | [
"python",
"mysql",
"django",
"django-models"
] |
how to close trace 32 application itself through cmm command? | 37,830,836 | <p>I load and execute a cmm script inside trace32 application using bmm commands.
when the execution is over i need to close the entire t32 application window itself (similar to File -> Exit) using <strong>cmm command</strong> ?</p>
| 1 | 2016-06-15T09:03:50Z | 37,845,692 | <p>To close the PowerView main window use TRACE32 command <code>QUIT</code></p>
| 2 | 2016-06-15T21:00:33Z | [
"python",
"command",
"exit",
"trace32"
] |
Python regex: one or more occurrences of a string | 37,830,849 | <p>Suppose I have strings like these:</p>
<ol>
<li><code>"DT NN IN NN"</code></li>
<li><code>"NN IN NN"</code></li>
<li><code>"NN NN IN NN"</code></li>
<li><code>"NN IN NN NN NN"</code></li>
<li><code>"NN NN IN NN NN"</code></li>
<li><code>"CD NN IN CD NN"</code></li>
<li><code>"NN IN NN DT"</code></li>
</ol>
<p>Basi... | 0 | 2016-06-15T09:04:24Z | 37,831,043 | <p>I think this will work</p>
<pre><code>^((?:NN\s+)+)IN\s+NN
</code></pre>
<p>For ending with NN, use:</p>
<pre><code>^(?:NN\s+)+IN\s+(?:NN\s+)*NN$
</code></pre>
<p><strong><a href="https://regex101.com/r/nT9rQ4/2" rel="nofollow">Regex Demo</a></strong></p>
<p>In your regex</p>
<pre><code>(NN+) (IN) (NN+)
</code... | 1 | 2016-06-15T09:11:26Z | [
"python",
"regex",
"python-2.7"
] |
Dynamic Nested Loops on Lists | 37,830,856 | <p>I have the following code to compute all the possible combinations of odds for a number of games. I would like to do the following</p>
<ol>
<li>Remove all the ugly nested loops.</li>
<li>Allow dynamic games, i.e I will not have to stay creating a match list adding and add an entry to the nested loop. (ex I want to ... | 2 | 2016-06-15T09:04:33Z | 37,831,123 | <p>You should have a look at <a href="https://docs.python.org/3/library/itertools.html#itertools.product" rel="nofollow"><code>itertools.product</code></a>. Also, your <code>total_rank</code> list seems to be kind of pointless (note that it will contain many refrences to <em>the same</em> list over and over again) and ... | 1 | 2016-06-15T09:15:18Z | [
"python",
"list",
"loops",
"numpy",
"nested"
] |
Python string to a colour | 37,830,929 | <p>I have a database of thousands of different colours. I want to map them to one of the colours I have in a list.</p>
<p>Before this database of colours was only a few hundred and I managed this with something like the code below. This is now getting unmaintainable as this database of unclassified colours is growing ... | 3 | 2016-06-15T09:07:21Z | 37,831,520 | <p>I'd start with a decent colour dictionary to map names to <em>colour definitions</em> in a given colour space (like RGB or CMYK or HSV). There are various sets available on the internet; you'll have to do work up-front to obtain them and normalise the data from each to use the same colour space. The more sources you... | 3 | 2016-06-15T09:32:10Z | [
"python"
] |
Python string to a colour | 37,830,929 | <p>I have a database of thousands of different colours. I want to map them to one of the colours I have in a list.</p>
<p>Before this database of colours was only a few hundred and I managed this with something like the code below. This is now getting unmaintainable as this database of unclassified colours is growing ... | 3 | 2016-06-15T09:07:21Z | 37,832,959 | <p>Once you have a large database of names to correct answers (see Martijn's answer), you could use that database to train a classification algorithm, for example one from <a href="http://scikit-learn.org/" rel="nofollow">scikit-learn</a>:</p>
<pre><code>#!/usr/bin/env python3
from sklearn import svm
from sklearn.fea... | 1 | 2016-06-15T10:34:24Z | [
"python"
] |
pyinstaller & django OSError: [Errno 2] No such file or directory | 37,830,952 | <p>I am trying to compile a django web application using pyinstaller.
I used following command:</p>
<pre><code> /usr/local/python2.7/bin/pyinstaller --name=zhaobiao ./zbproject/manage.py
</code></pre>
<p>When I executed the compiled exe it gave me following error:</p>
<pre><code> [root@smon zhaobiao]# ./dist/zhao... | 0 | 2016-06-15T09:08:06Z | 37,854,540 | <p>I have copy the directory /root/Downloads/zbproject/zbapp to /root/Downloads/dist/zhaobiao/</p>
<p>now it works.</p>
<pre><code>[root@smon test]# ./dist/zhaobiao/zhaobiao runserver 0.0.0.0:8000
Performing system checks...
System check identified no issues (0 silenced).
May 30, 2016 - 03:04:49
Django version 1.9.... | 0 | 2016-06-16T09:01:57Z | [
"python",
"django",
"pyinstaller"
] |
Columns located within a column | 37,831,023 | <p>I am trying to extract a dataframe from a web api and can't seem to work out how to break columns out. For Home and Away, they have breakdowns inside them, so should read Home Wins, Home Draws etc.</p>
<pre><code>url = "http://api.football-data.org/v1/soccerseasons/398/leagueTable/?matchday=38"
response = requests.... | 1 | 2016-06-15T09:10:52Z | 37,831,589 | <p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.io.json.json_normalize.html" rel="nofollow"><code>json_normalize</code></a>:</p>
<pre><code>import pandas as pd
import json
import requests
from pandas.io.json import json_normalize
url = "http://api.football-data.org/v1/so... | 0 | 2016-06-15T09:35:20Z | [
"python",
"json",
"pandas",
"dataframe"
] |
SSL certificate verify failed with python requests library | 37,831,059 | <p>We have this local site which has recently just updated its certificate. I saved the certificates in a <code>certs.pem</code> file and tried to connect it with some tools. Below operations are done on a Ubuntu 14.10 box.</p>
<p>When I run:</p>
<pre><code>openssl s_client -connect mylocalsite:8080 -verify 9 -CAfile... | 1 | 2016-06-15T09:11:56Z | 37,833,722 | <p>Looks like <code>openssl s_client -connect</code> is happy with "only" having the correct certificate but you need to pass the whole chain to requests' <code>verify</code> parameter (though both are using the same library under the hood, of course).</p>
<p><strong>SSL support in requests needs some <em>serious</em>... | 1 | 2016-06-15T11:09:01Z | [
"python",
"ssl-certificate",
"python-requests"
] |
Detecting circles in an image using laplacian | 37,831,191 | <p>I'm trying detect the disk and cup in the back of an eye (fundus) to calculate certain things later on. So here is an image of the eye:</p>
<p><a href="http://i.stack.imgur.com/8Lzuq.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/8Lzuq.jpg" alt="enter image description here"></a></p>
<p>I'm just trying to ... | 0 | 2016-06-15T09:18:26Z | 37,872,605 | <p><strong>EDIT:</strong>
Previous MSER approach as shown fails to find a circular blob, though it highlights the region. So I tried <a href="https://en.wikipedia.org/wiki/Difference_of_Gaussians" rel="nofollow">Difference-of-Gaussians</a>(DoG) for blob detection, and it gives good results. You can experiment with the ... | 1 | 2016-06-17T03:25:07Z | [
"python",
"opencv",
"matplotlib",
"computer-vision",
"gaussian"
] |
Is it possible to vectorize a function that access different elements in an numpy array? | 37,831,215 | <p>Let's say that I wish to implement the following code in python</p>
<p>This function takes an image as 1 dimensional array, and iterates over individual elements in the array (pixels in the input image) which affects an output array that is also an image represented as a 1 dimensional array</p>
<p>example:
a sing... | 5 | 2016-06-15T09:19:30Z | 37,831,474 | <p>Let's say <code>arr</code> represents the input array and <code>thresh</code> be the threshold to be compared against each of the input elements. Now, we can threshold the input array against the given threshold giving us a mask/boolean array. Then, we can perform 2D convolution and subtract <code>1s</code> from it ... | 0 | 2016-06-15T09:30:47Z | [
"python",
"arrays",
"numpy",
"vectorization"
] |
Is it possible to vectorize a function that access different elements in an numpy array? | 37,831,215 | <p>Let's say that I wish to implement the following code in python</p>
<p>This function takes an image as 1 dimensional array, and iterates over individual elements in the array (pixels in the input image) which affects an output array that is also an image represented as a 1 dimensional array</p>
<p>example:
a sing... | 5 | 2016-06-15T09:19:30Z | 37,833,453 | <p>If I understood the question correctly, then the approach can be turned upside down: if a pixel has in its neighbourhood pixels that match the condition, increment it by one for each match. Do this for all pixels. Scipy (among others) offers tools for <a href="http://docs.scipy.org/doc/scipy/reference/ndimage.html#f... | 5 | 2016-06-15T10:56:04Z | [
"python",
"arrays",
"numpy",
"vectorization"
] |
Is it possible to vectorize a function that access different elements in an numpy array? | 37,831,215 | <p>Let's say that I wish to implement the following code in python</p>
<p>This function takes an image as 1 dimensional array, and iterates over individual elements in the array (pixels in the input image) which affects an output array that is also an image represented as a 1 dimensional array</p>
<p>example:
a sing... | 5 | 2016-06-15T09:19:30Z | 37,835,000 | <p>I think what you are trying to do is easiest with 2D array indexing. You can reshape arrays easily with numpy. No data is copied. The new 2D array just provides a convenient way to index the same values that are stored in the original array. Here is an example code. </p>
<pre><code>#imports
import numpy as np
... | 3 | 2016-06-15T12:06:38Z | [
"python",
"arrays",
"numpy",
"vectorization"
] |
List of actuals import names in python | 37,831,322 | <p>With "pip freeze" I'll get a list of package names. e.g.:</p>
<pre><code>Django==1.9.7
psycopg2==2.6.1
djangorestframework==3.3.3
djangorestframework-jwt==1.8.0
django-rest-swagger==0.3.7
django-environ==0.4.0
python-dateutil==2.5.3
django-sendfile==0.3.10
</code></pre>
<p>Is there any way to receive a list of ac... | 6 | 2016-06-15T09:23:48Z | 37,831,729 | <p>You may use the standard <a href="https://docs.python.org/3/library/pkgutil.html"><code>pkgutil</code></a> module to get the list of top-level imports like this:</p>
<pre><code>import pkgutil
list(pkgutil.iter_modules())
</code></pre>
<p>That will only find modules that live in regular files, zip files or another ... | 6 | 2016-06-15T09:41:48Z | [
"python",
"pip"
] |
List of actuals import names in python | 37,831,322 | <p>With "pip freeze" I'll get a list of package names. e.g.:</p>
<pre><code>Django==1.9.7
psycopg2==2.6.1
djangorestframework==3.3.3
djangorestframework-jwt==1.8.0
django-rest-swagger==0.3.7
django-environ==0.4.0
python-dateutil==2.5.3
django-sendfile==0.3.10
</code></pre>
<p>Is there any way to receive a list of ac... | 6 | 2016-06-15T09:23:48Z | 37,831,778 | <p>Another way is to look at the first line of this file : </p>
<pre><code># If output of pip freeze is djangorestframework==3.3.3
# Then your dir prefix becomes "djangorestframework-3.3.3"
../lib/python2.7/site-packages/<dir-prefix>.dist-info/top_level.txt
# e.g.
../lib/python2.7/site-packages/djangorestfram... | 0 | 2016-06-15T09:44:09Z | [
"python",
"pip"
] |
List of actuals import names in python | 37,831,322 | <p>With "pip freeze" I'll get a list of package names. e.g.:</p>
<pre><code>Django==1.9.7
psycopg2==2.6.1
djangorestframework==3.3.3
djangorestframework-jwt==1.8.0
django-rest-swagger==0.3.7
django-environ==0.4.0
python-dateutil==2.5.3
django-sendfile==0.3.10
</code></pre>
<p>Is there any way to receive a list of ac... | 6 | 2016-06-15T09:23:48Z | 37,833,320 | <p>Yes, top_level.txt will be a correct module name. You can use pkg_resources module to extract metadata from packages.</p>
<p>Python code for this:</p>
<pre><code>import pkg_resources
def read_requirements(requirements_file):
with open(requirements_file, 'r') as f:
return f.read().splitlines()
def g... | 1 | 2016-06-15T10:48:59Z | [
"python",
"pip"
] |
Django error loading MySQLdb module undefined symbol:_ZTVN10__cxxabiv117__class_type_infoE | 37,831,365 | <p>I'm working on centos 6.5/Python2.7.10/Django/MySQL, I get the following error when I try to run:</p>
<pre><code>python manage.py check
</code></pre>
<p>The error is:</p>
<pre><code>Traceback (most recent call last):
File "../manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File ... | 0 | 2016-06-15T09:25:45Z | 37,849,210 | <p>I got stuck with this problem for almost a whole day, now I solved the problem.
First, do not install mysqlclient through <code>pip install mysqlclient</code>, you should install from source(download <a href="https://pypi.python.org/pypi/mysqlclient" rel="nofollow">here</a>).</p>
<p>Then:</p>
<pre><code>tar -zxvf ... | 0 | 2016-06-16T03:05:31Z | [
"python",
"mysql",
"django",
"python-2.7"
] |
Theano Ubuntu 12 cuda | 37,831,532 | <p>Hello my question is the next one:</p>
<p>I use theano on ubuntu 14 and configure theano flags by editing .theanorc. To use cuda, I only have to add:
[cuda]
root=/usr/local/cudaVersion/</p>
<p>And everything goes, theano is capable of finding nvcc, the libs and everything, I do not have to add cudaRoot to the $PAT... | 0 | 2016-06-15T09:32:31Z | 37,845,094 | <p>I will try to help you the best i can.
I use Theano and CUDA on Linux.</p>
<p>First, are you sudo in both OS's ? Did you install theano and python environment and cuda as sudo? Because, i suppose that, if the setup of CUDA wasnt done on global library path, then it wont be automatically detected.</p>
<p>Also, acco... | 0 | 2016-06-15T20:23:21Z | [
"python",
"ubuntu-12.04",
"theano",
"theano-cuda"
] |
Number and letter replacement are mixed up with custom substitution cipher in Python | 37,831,686 | <p>This part of the code transfers the letters to numbers and then multiply it by the key (datetime*ip (replaced(.,5)</p>
<pre><code>import datetime
import time
import socket
while (True):
IP=int(socket.gethostbyname(socket.gethostname()).replace(".","5"))
time=(int(datetime.datetime.now().strftime("%Y%m%d%H%M%S")))
... | -1 | 2016-06-15T09:39:56Z | 37,880,912 | <p>Your "decryption" cannot work, because not every character has its own slot. Let's say the key is <code>1</code> and an example ciphertext is <code>7334662</code> which "clearly" represents <code>en</code>. Since your decryption starts replacing <code>346</code> to <code>b</code>, the ciphertext will result in <code... | 0 | 2016-06-17T11:53:33Z | [
"python",
"python-3.x",
"encryption"
] |
Comparing the entities of lists of tuples, find the pair and output their IDs from another list of tuples if they are not the same | 37,831,698 | <p>I have two lists of tuples as follows:</p>
<pre><code>a= [(0.37239153400387603, 0.17091178239454413,
0.41009763328456317, 0.7121861651366165),
(0.4654894175048452, 0.21363972799318015,
0.17091178239454413, 0.37239153400387603,
0.7121861651366165)]
b= [(199, 200, 201, 202),
(79, 80,200, ... | 0 | 2016-06-15T09:40:29Z | 37,832,308 | <p>Well if I understood correctly all you need is to concatenate corresponding "IDs" to the floating point, then all you would need is:</p>
<pre><code>concatenatedList = [ (a[i][j], b[i][j]) for i in range(len(a)) for j in range(len(a[i])) ]
for k in range(len(concatenatedList)):
for l in range(k+1, len(concatenat... | 1 | 2016-06-15T10:06:36Z | [
"python",
"list",
"tuples"
] |
TypeError when calling requests_oauthlib multiple times (error actually raised within urllib3) | 37,831,713 | <p>I'm writing a script to pull some data from the Twitter API. It's use of OAuth 1.1 means I'm using the <code>requests_oauthlib</code> helper library on top of <code>requests</code> to authenticate the session.</p>
<p>The first call to the API works, but then subsequent calls give a <code>TypeError</code> as follows... | 0 | 2016-06-15T09:41:11Z | 37,831,909 | <p>The format for OAuth1Session is:</p>
<pre><code>oauth = OAuth1Session(client_key,
client_secret=client_secret,
resource_owner_key=resource_owner_key,
resource_owner_secret=resource_owner_secret,
verifier=verifier)
</code></pre>
... | 0 | 2016-06-15T09:50:39Z | [
"python",
"python-requests",
"urllib3"
] |
TypeError when calling requests_oauthlib multiple times (error actually raised within urllib3) | 37,831,713 | <p>I'm writing a script to pull some data from the Twitter API. It's use of OAuth 1.1 means I'm using the <code>requests_oauthlib</code> helper library on top of <code>requests</code> to authenticate the session.</p>
<p>The first call to the API works, but then subsequent calls give a <code>TypeError</code> as follows... | 0 | 2016-06-15T09:41:11Z | 37,851,034 | <p>Edit: Also added reference to reloading container library within IPython / Jupyter.</p>
<p>After a fair bit of reading, it appears the problem may arise when you call <code>get</code> on a request but don't access the body of the response (which is what I did whilst building / debugging the flow):</p>
<p><a href="... | 0 | 2016-06-16T06:01:42Z | [
"python",
"python-requests",
"urllib3"
] |
Python xgboost on Windows machine | 37,831,775 | <p>I am succeeded to install xgboost on windows machine and <code>import xgboost</code> inside the Spyder is working , but when I try to run xgboost.train I get the following error :</p>
<blockquote>
<pre><code>File "C:\Users\Anaconda2\lib\site-packages\xgboost-0.4-py2.7.egg\xgboost\core.py",
line 806, in update _che... | 0 | 2016-06-15T09:44:00Z | 37,831,930 | <p>I suspect that's an error coming from the c++ implementation nothing to do with your python installation. Try to install a previous or later version.</p>
| 0 | 2016-06-15T09:51:20Z | [
"python",
"xgboost"
] |
Fast sorting of large nested lists | 37,831,905 | <p>I am looking to find out the likelihood of parameter combinations using Monte Carlo Simulation.
I've got 4 parameters and each can have about 250 values.
I have randomly generated 250,000 scenarios for each of those parameters using some probability distribution function.
I now want to find out which parameter combi... | 0 | 2016-06-15T09:50:23Z | 37,832,198 | <p>You can take out the sorting part, as the final result is a dictionary which will be unordered in any case, then use a dict comprehension:</p>
<pre><code>>>> a = [[1,2],[1,2],[3,4,5],[3,4,5], [3,4,5]]
>>> a_tupled = [tuple(i) for i in a]
>>> b_set = set(a_tupled)
>>> {repr(i): a_... | 1 | 2016-06-15T10:01:55Z | [
"python",
"performance",
"list",
"python-2.7",
"count"
] |
Fast sorting of large nested lists | 37,831,905 | <p>I am looking to find out the likelihood of parameter combinations using Monte Carlo Simulation.
I've got 4 parameters and each can have about 250 values.
I have randomly generated 250,000 scenarios for each of those parameters using some probability distribution function.
I now want to find out which parameter combi... | 0 | 2016-06-15T09:50:23Z | 37,832,321 | <pre><code>{str(item):a.count(item) for item in a}
</code></pre>
<p>Input :</p>
<pre><code>a = [[1,2,5,8],[1,2,5,8],[3,4,5,6],[3,4,5,7],[3,4,5,7]]
</code></pre>
<p>Output :</p>
<pre><code>{'[3, 4, 5, 6]': 1, '[1, 2, 5, 8]': 2, '[3, 4, 5, 7]': 2}
</code></pre>
| 0 | 2016-06-15T10:07:16Z | [
"python",
"performance",
"list",
"python-2.7",
"count"
] |
how to extract information I want by NLKT | 37,831,985 | <p>I want to extract relevant information about few topics. for example:</p>
<ul>
<li>product information</li>
<li>purchase experience of customer</li>
<li>recommendation of family or friend</li>
</ul>
<p>In first step, I extract information from one of the website. for instance :</p>
<blockquote>
<p>i think AIA d... | 0 | 2016-06-15T09:53:20Z | 38,096,485 | <p>You just need to follow these <a href="https://www.youtube.com/watch?v=CMyoQbBq5IE&list=PLQVvvaa0QuDfRO5bQFLcVgvIOIhNUZpZf&index=1" rel="nofollow">video</a> </p>
<p>or read this <a href="https://pythonprogramming.net/named-entity-recognition-nltk-python/" rel="nofollow">blog</a>.</p>
| 0 | 2016-06-29T10:07:31Z | [
"python",
"python-3.x",
"dictionary",
"bigdata",
"text-analysis"
] |
Possible incongruence in Sympy when assuming positive numbers | 37,832,160 | <p>Using Sympy package version 1.0 on Python 2.7.11 I found what (to me) is an incongruence. This is the code I'm using:
</p>
<pre><code>import sympy as sy
from sympy.stats import Normal, density
from sympy.assumptions import assuming, Q, ask
sy.init_printing()
a = sy.symbols('a', real=True)
with assuming(Q.positive... | 4 | 2016-06-15T10:00:35Z | 37,839,708 | <p>The problem is simple: there are two assumptions systems in SymPy, called the old-style and new-style assumptions. They don't interact quite well, yet.</p>
<p>The old-style assumptions define predicates on symbols, e.g.</p>
<pre><code>x = Symbol("x", positive=True)
</code></pre>
<p>deduction is then performed on ... | 3 | 2016-06-15T15:29:27Z | [
"python",
"sympy"
] |
Python class method run when another method is invoked | 37,832,228 | <p>I have a class as follows:</p>
<pre><code>class MyClass(object):
def __init__(self):
self.foo = "foo"
self.bar = "bar"
self.methodCalls = 0 #tracks number of times any function in the instance is run
def get_foo(self):
addMethodCall()
return self.foo
def get_ba... | 0 | 2016-06-15T10:03:34Z | 37,832,857 | <p>No, there are no hooks <em>on a class</em> to do this. Methods are attributes <em>too</em>, albeit somewhat special in that they are produced when accessing the function object on the instance; functions are <a href="https://docs.python.org/2/howto/descriptor.html" rel="nofollow">descriptors</a>.</p>
<p>The <em>cal... | 3 | 2016-06-15T10:30:05Z | [
"python",
"python-2.7",
"class"
] |
How to create masked array with a vector that seperates sections of a 2d array? | 37,832,460 | <p>Let's say I have a standard 2d numpy array, let's call it my2darray with values. In this array there are two major sections. Let's say for each column, there is a specific row which separates "scenario1" and "scenario2". How can i create 2 masked arrays that represent the top section of my2darray and the bottom of m... | 1 | 2016-06-15T10:13:35Z | 37,832,849 | <p>Using <a href="http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html" rel="nofollow"><code>NumPy's broadcasted comparison</code></a>, we can create such a <code>2D</code> mask in a vectorized manner. Rest of the work is all about <code>sum-reduction</code> along the first axis for which we can take help from... | 0 | 2016-06-15T10:29:44Z | [
"python",
"numpy",
"masked-array"
] |
Calling overloaded method using super() yields AttributeError | 37,832,661 | <p>I have a class definition like</p>
<pre><code>from tinydb import TinyDB
class DB(TinyDB):
def __init__(self, filename):
return super(DB, self).__init__(filename)
def exists(self, url):
return bool(self.search(Entry.url == url))
def insert(self, *args, **kwargs):
if len(self) &... | 1 | 2016-06-15T10:22:20Z | 37,833,104 | <p>Your last example works because of the <code>__getattr__</code> method defined on <code>TinyDB</code>:</p>
<pre><code>class TinyDB(object):
# [....]
def __getattr__(self, name):
"""
Forward all unknown attribute calls to the underlying standard table.
"""
return getattr(self.... | 1 | 2016-06-15T10:39:58Z | [
"python",
"oop"
] |
Python Regex for pattern matching | 37,832,701 | <p>I am trying to parse the sample input test_string1 as below:</p>
<pre><code>import re
TEST_STRING1 = """Using definitions from (yyyy/mm/dd): 2016/6/8
The following files are collected:
File: Test.exe
Source: Google
avping blob: 123123
Downloaded 3 Files
"""
def fun():
regex_exp = re.compile(r"File:\... | 1 | 2016-06-15T10:24:13Z | 37,832,805 | <p>You may use an optional non-capturing group and use <code>[^\w\d]*</code> greedy version:</p>
<pre><code>(File:\s(?P<File>[^\n\r\t]+?)[\n\r\t\s]*?Source:\s(?P<Source>.*)[^\w\d]*(?:avping\sblob:\s(?P<Avping_blob>[A-Fa-f0-9]{6}))?)
</code></pre>
<p>See the <a href="https://regex101.com/r/yD8dS9/2" ... | 1 | 2016-06-15T10:28:03Z | [
"python",
"regex",
"pattern-matching"
] |
Name output variables using a suffix entered as input | 37,832,818 | <p>How can I name output variables of my function, using a suffix (a string) entered as input of my function, in order to apply the same function more than once, but obtaining each time the results with a different name?</p>
<p>I'd try something like that:</p>
<pre><code>import... (what I should import??..)
import nu... | 0 | 2016-06-15T10:28:39Z | 37,832,970 | <p>It would be better to have a list on the receiving end so that you can do e.g.:</p>
<pre><code>mylist.append(myFun(int))
</code></pre>
<p>You can then iterate over the list to get your results.</p>
<p><strong>EDIT</strong></p>
<p>You can also use a dictionary instead of a list so that you can still access your r... | 2 | 2016-06-15T10:34:45Z | [
"python",
"numpy"
] |
Name output variables using a suffix entered as input | 37,832,818 | <p>How can I name output variables of my function, using a suffix (a string) entered as input of my function, in order to apply the same function more than once, but obtaining each time the results with a different name?</p>
<p>I'd try something like that:</p>
<pre><code>import... (what I should import??..)
import nu... | 0 | 2016-06-15T10:28:39Z | 37,833,095 | <p>I don't see why you would want dynamic variable names, but this should do what you want:</p>
<pre><code>exec("a%s = %s" % (mysuffix, some_other_string));
</code></pre>
<p>Replace the second argument by the variable type you need. But most likely you simply want a list of variables.</p>
| 0 | 2016-06-15T10:39:36Z | [
"python",
"numpy"
] |
Adding h5 files in a zip to use with PySpark | 37,832,937 | <p>I am using PySpark 1.6.1 for my spark application. I have additional modules which I am loading using the argument <code>--py-files</code>. I also have a h5 file which I need to access from one of the modules for initializing the ApolloNet.</p>
<p>Is there any way I could access those files from the modules if I p... | 0 | 2016-06-15T10:33:36Z | 37,876,437 | <p>Found that you can add the additional files to all the workers by using <code>--files</code> argument in spark-submit.</p>
| 0 | 2016-06-17T08:14:27Z | [
"python",
"pyspark",
"caffe"
] |
Python Linear Regression Error | 37,832,994 | <p>I have two arrays with the following values:</p>
<pre><code>>>> x = [24.0, 13.0, 12.0, 22.0, 21.0, 10.0, 9.0, 12.0, 7.0, 14.0, 18.0,
... 1.0, 18.0, 15.0, 13.0, 13.0, 12.0, 19.0, 13.0]
>>> y = [10.0, 9.0, 22.0, 7.0, 4.0, 7.0, 56.0, 5.0, 24.0, 25.0, 11.0, 2.0,
... 9.0, 1.0, 9.0, 12.0, 9.0... | 1 | 2016-06-15T10:35:39Z | 37,846,468 | <p>The problem is you are performing <a href="https://docs.scipy.org/doc/numpy-1.10.1/user/basics.types.html#array-scalars" rel="nofollow">scalar addition</a> with an empty <code>list</code>.</p>
<p>The reason you have an empty <code>list</code> is because you try to perform scalar multiplication with a python list ra... | 2 | 2016-06-15T21:55:29Z | [
"python",
"csv",
"regression",
"data-mining",
"linear"
] |
Fastest way to iterate over two panda data frames | 37,833,210 | <p>I have two data frames:</p>
<p><code>dt1</code> where I store millions of registry key entries. Defined with columns: <code>Index([u'count', u'id', u'is_malicious', u'key', u'name', u'value'], dtype='object')</code></p>
<p>And <code>dt2</code> where I match those registry entries to machines across our network. De... | 0 | 2016-06-15T10:44:33Z | 37,833,286 | <p>I think if you perform a left <code>merge</code> you can then count the dupes calling <code>value_counts</code> on 'id' column:</p>
<pre><code>dt1.merge(dt2,left_on='id', right_on='registry_key_id', how='left')['id'].value_counts()
</code></pre>
| 0 | 2016-06-15T10:47:42Z | [
"python",
"pandas",
"dataframe"
] |
Fastest way to iterate over two panda data frames | 37,833,210 | <p>I have two data frames:</p>
<p><code>dt1</code> where I store millions of registry key entries. Defined with columns: <code>Index([u'count', u'id', u'is_malicious', u'key', u'name', u'value'], dtype='object')</code></p>
<p>And <code>dt2</code> where I match those registry entries to machines across our network. De... | 0 | 2016-06-15T10:44:33Z | 37,837,338 | <p>You could give .map a try. After creating a dataframe containing the counts of each distinct id from your second dataframe, the reference_id in the first dataframe can be mapped there.</p>
<pre><code>import pandas as pd
import string
import time
df1=pd.DataFrame(data= {"id": ["a","b","c","d"]*5,"value":range(20)},... | 2 | 2016-06-15T13:46:57Z | [
"python",
"pandas",
"dataframe"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.