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
Convert query result to JSON
38,174,566
<p>I have my python function that returns a query result:</p> <pre><code>class Arc_Nodes_Data(Resource): def get(self): #Connect to databse conn = connectDB() cur = conn.cursor() #Perform query and return JSON data try: cur.execute("SELECT start_location FROM trips U...
0
2016-07-03T21:38:05Z
38,174,624
<p>You can use list comprehension to do that what you want:</p> <pre><code>return jsonify ([{'id': x} for x in Nodelist]) </code></pre> <p>That comprehension make 3 dictionaries wiht each containing one id element.</p> <p>You can also combine last to lines in one line:</p> <pre><code>return jsonify ([{'id': i[0]} f...
0
2016-07-03T21:47:18Z
[ "python", "json", "postgresql", "flask" ]
Python, loop of statements pulling from excel
38,174,570
<p>Im still new to python. Just wondering if there is an easier way to accomplish my task.</p> <p>This is my current code</p> <pre><code>win = visual.Window([800,800],monitor="testmonitor", units="deg") msg = visual.TextStim(win, text='hello this is a test',pos=[0,+1],color='white') msg.draw() win.flip() core.wait(2...
0
2016-07-03T21:38:57Z
38,174,614
<blockquote> <p><a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself" rel="nofollow"><strong>D</strong> on't<br> <strong>R</strong> epeat<br> <strong>Y</strong> ourself</a></p> </blockquote> <p>Your solution uses 4 blocks of codes of 4 lines each, the last 3 lines are the same, and the first is almost ...
2
2016-07-03T21:45:55Z
[ "python", "excel", "loops" ]
pil python multiple Image independent draw
38,174,726
<p>I have a database with (x, y) points gathered over time to plot on an image. For better data representation, I would like to generate frames of the image plus a circle on the (x, y) coordinates when they should show up. I managed to do this with the following code, but it takes - in my opinion - too much time (the v...
1
2016-07-03T22:03:01Z
38,175,118
<p>You could change...</p> <pre><code>for i in range(0, 4250, 1): valaro = Image.open('pngs/valaro_800.png') </code></pre> <p>...to...</p> <pre><code>original = Image.open('pngs/valaro_800.png') for i in range(0, 4250, 1): valaro = original.copy() </code></pre> <p>...so the image is only loaded once, but I ...
0
2016-07-03T23:08:15Z
[ "python", "python-2.7", "optimization", "python-imaging-library", "draw" ]
Start python file everyday at 10pm for 12hours
38,174,747
<p>How can I set up starting of python file everyday at same time but after 12hours stop</p>
-2
2016-07-03T22:06:09Z
38,174,842
<p>Use cron to start at same time every day:</p> <pre><code>https://help.ubuntu.com/community/CronHowto </code></pre> <p>In your code, note the time the program starts using <code>datetime.now()</code> and in the main loop of your program, run until it is 12 hours later</p>
1
2016-07-03T22:23:33Z
[ "python", "time" ]
Start python file everyday at 10pm for 12hours
38,174,747
<p>How can I set up starting of python file everyday at same time but after 12hours stop</p>
-2
2016-07-03T22:06:09Z
38,175,874
<p>You haven't specified your OS, etc., but here's a general approach:</p> <p><strong>Step 1</strong>: Write a python script that terminates after 12 hours. (Trivial -- see <a href="http://stackoverflow.com/questions/14920384/stop-code-after-time-period">this</a>)</p> <p><strong>Step 2</strong>: If you're using ub...
0
2016-07-04T01:36:07Z
[ "python", "time" ]
functools.partial: TypeError: got multiple values for keyword argument
38,174,751
<p>I am using the partial method from the functools module to map a function over a range of values:</p> <pre><code>def basic_rule(p,b,vx=1,**kwargs): return (p / b) if vx != 0 else 0 def rule5(func,**kwargs): vals = map(functools.partial(func,**kwargs), range(1,kwargs['b']+1)) return [x for i,x in enume...
0
2016-07-03T22:06:34Z
38,175,108
<p><a href="https://docs.python.org/3/library/functools.html#functools.partial" rel="nofollow">functools.partial</a> generates a partial that stores the arguments receiveids in 2 properties:</p> <ul> <li><code>arguments</code> stores positional arguments</li> <li><code>keywords</code> stores all keyword-based argument...
0
2016-07-03T23:06:19Z
[ "python", "dictionary", "functools" ]
Pygame Missile Coll
38,174,797
<p>So basically lead_x and lead_y are coordinates of a thing, and so are MineX and MineY.</p> <pre><code>if lead_x &gt; XMine and lead_x &lt; XMine + MineThickness: if lead_x + block_size &gt; XMine and lead_x + block_size &lt; XMine + MineThickness: if lead_y &gt; YMine and lead_y &lt; YMine + MineThickne...
1
2016-07-03T22:14:18Z
38,213,970
<p>Pygame offers a lot of functionality to accomplish what you're trying to do manually. If you create your game objects using <a href="http://www.pygame.org/docs/ref/rect.html" rel="nofollow">Sprites</a> you can just <a href="http://www.pygame.org/docs/ref/rect.html#pygame.Rect.colliderect" rel="nofollow">Sprite.colli...
0
2016-07-05T22:40:06Z
[ "python", "pygame" ]
Extracting information from a third-party Python module?
38,174,824
<p>NOTE: I've worked in Java for years but I'm new to Python, so I apologize if this is a kind of vague question. I'm just thrashing around trying to make something work.</p> <p>I'm trying to use a third-party Python module which is an application SDK. The Python module is a wrapper for an underlying legacy C SDK...
1
2016-07-03T22:20:25Z
38,175,477
<p>A good starting point for finding information about a module is to do...</p> <pre><code>&gt;&gt;&gt; import &lt;modulename&gt; &gt;&gt;&gt; &lt;modulename&gt; </code></pre> <p>It's usually one of four possible types...</p> <hr> <p><strong>1. Built-in</strong></p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; ...
3
2016-07-04T00:18:55Z
[ "python" ]
Python os.startfile Can't Find The FIle
38,174,843
<p>I'm having a problem with Python programming. In my program I use a <code>os.startfile()</code> to start a program but it won't let me.</p> <p>When my program is executing the command to start the file I get the following error in the Windows Script Host: </p> <pre><code>Script: C:\Users\Personal Name\Desktop\...
-2
2016-07-03T22:23:37Z
38,174,931
<p>Backslashes in text can cause the next character to be interpreted as a special character instead of its actual value.</p> <p>For example, <code>\n</code> is a newline character and <code>\b</code> is a backspace character.</p> <p>There are three ways to fix this:</p> <ol> <li><p>Use forward slashes in your path ...
0
2016-07-03T22:39:19Z
[ "python", "windows", "path", "startup", "os.system" ]
Python os.startfile Can't Find The FIle
38,174,843
<p>I'm having a problem with Python programming. In my program I use a <code>os.startfile()</code> to start a program but it won't let me.</p> <p>When my program is executing the command to start the file I get the following error in the Windows Script Host: </p> <pre><code>Script: C:\Users\Personal Name\Desktop\...
-2
2016-07-03T22:23:37Z
38,183,191
<p>SOLVED:</p> <p>I solved it! </p> <p>Short way of explaining it: I moved the Volume Max.vbs file to the folder the python script is and just said open Volume Max.vbs script without any pathway in the os.startfile. Like this: os.startfile(Volume Max.vbs)</p>
0
2016-07-04T11:05:12Z
[ "python", "windows", "path", "startup", "os.system" ]
Edit Django registration default templates
38,174,847
<p>I am trying to override several of Django's default template's in the registration module but have had no luck. </p> <p>My structure:</p> <pre><code>app -templates -registration -logout.html -base.html </code></pre> <p>My logout.html file looks like this:</p> <pre><code>{% extends 'base.html' %} {%...
0
2016-07-03T22:24:24Z
38,174,979
<p>The sequence in which your Installed Apps are listed affect which templates are loaded.</p> <p>In your case, you wish your App's templates override that of Django's Admin, therefore, in the list of Installed Apps, put your app's name <em>before</em> that of Django Admin.</p>
0
2016-07-03T22:46:36Z
[ "python", "django" ]
Specific Pip installation problems
38,174,848
<p>so i'm trying to install pip, but i need to install a version that is compatible with python 3.2 32 Bit. i saw that pip versions above 8.0.0 removed support for Python 3.2, so i need some help installing pip 7.1.2 (the version prior) so i went to the page that has pip 7.1.2, <a href="https://pypi.python.org/pypi/pip...
0
2016-07-03T22:24:27Z
38,175,236
<p>You can download the <a href="https://pypi.python.org/pypi/pip/7.1.2" rel="nofollow">pip 7.1.2</a> source distribution and run from there (is just plain python code, you don't need to compile anything). After extracting the tarball, you can install a package using:</p> <pre class="lang-sh prettyprint-override"><cod...
0
2016-07-03T23:29:55Z
[ "python", "pip", "python-3.2" ]
Specific Pip installation problems
38,174,848
<p>so i'm trying to install pip, but i need to install a version that is compatible with python 3.2 32 Bit. i saw that pip versions above 8.0.0 removed support for Python 3.2, so i need some help installing pip 7.1.2 (the version prior) so i went to the page that has pip 7.1.2, <a href="https://pypi.python.org/pypi/pip...
0
2016-07-03T22:24:27Z
38,175,306
<p>Download <code>get-pip.py</code> using <code>wget</code> or <code>curl</code> Then run <code>python get-pip.py</code></p>
0
2016-07-03T23:42:42Z
[ "python", "pip", "python-3.2" ]
301 MOVED PERMANENTLY, with python fcgi
38,174,875
<p>I'm working with a rather cheap shared hosting account trying to deploy a flask app using <a href="http://fgimian.github.io/blog/2014/02/14/serving-a-python-flask-website-on-hostmonster" rel="nofollow">http://fgimian.github.io/blog/2014/02/14/serving-a-python-flask-website-on-hostmonster</a> . I've put the code and ...
0
2016-07-03T22:29:00Z
39,069,284
<p>I recently encountered the same problem and managed to solve it by downgrading my Werkzeug package</p> <pre><code>pip install Werkzeug==0.9.6 </code></pre> <p>It's not clear to me why this helped but it seems that the my version of Werkzeug (0.11.10) was incompatible with Flask (0.11.1).</p>
1
2016-08-21T22:08:20Z
[ "python", "fastcgi" ]
Python - Measuring DNS and roundtrip time
38,174,877
<p>I am working on python script to measure the response time to DNS server and the response time for the get data from a web server.</p> <p>The approach I took as follows</p> <ol> <li>First measure the DNS lookup time using sockets module.Let's call this function A</li> <li>Measure the response from web server using...
2
2016-07-03T22:29:24Z
38,185,098
<blockquote> <p>DNS lookup is being called twice (once in function A &amp; then in function B).</p> </blockquote> <p>You can eliminate this issue by using the IP address returned by <code>gethostbyname()</code> for the subsequent HTTP request.</p> <p>If you like, you can also split the timing for the HTTP request i...
1
2016-07-04T12:44:03Z
[ "python", "dns", "response" ]
(PRAW) Get a value from a comment, then reply with another column's data, that's on the same row as the first piece of data
38,174,959
<p>Here's the CSV code.</p> <pre class="lang-python prettyprint-override"><code>import praw import time import csv import codecs import re from collections import defaultdict def read_csv(): with open('CPU-Bench.csv', 'r') as f: reader = csv.reader(f) for row in reader: import pandas as pd df...
0
2016-07-03T22:43:30Z
38,201,981
<p>You definetely need to setup reddit agent, authenticate it as reddit application in settings and all that other stuff that you do for normal bot. Oh and also it would be nice to parse dataframe to dictionary for easy lookup (since you will only do it when bot starts and then have really fast time to look up).</p> <...
0
2016-07-05T11:11:31Z
[ "python", "csv", "praw" ]
Heroku local not working, but works on the production server
38,174,968
<p>I was having some trouble with heroku local, so I went back and tried this with the heroku django starter pack, and got the same results.</p> <p>When I run heroku local and go to local host:5000, I get a timeout error on the page. However, I push the same code to heroku master and I am able to access the site on th...
0
2016-07-03T22:44:54Z
38,256,726
<p>This is almost certainly because you already have a process using port 5000. The comments suggest you have already solved this, but I figured I'd answer for others and help unblock that port. Assuming you are a *nix machine, you can check if another process is using the 5000 port by typing:</p> <pre><code>lsof -i :...
0
2016-07-07T23:18:53Z
[ "python", "django", "heroku" ]
Telegram Bot: Custom Keyboard [Python]
38,175,080
<p>I've downloaded this <a href="https://github.com/yukuku/telebot" rel="nofollow">open-source code</a> from GitHub which is written in Python(that I'm pretty new to it), I wanted to make my bot to have a Custom-Keyboard instead of letting users say whatever they wanted. for instance if user start the chat with my bot,...
-1
2016-07-03T23:01:59Z
38,798,725
<p>First, I recommend you to use some module to work with it. Since you're new, the <a href="https://github.com/python-telegram-bot/python-telegram-bot" rel="nofollow">python-telegram-bot</a> could help you.</p> <p>Well, assuming you will use it, you have two options:</p> <ol> <li><p>You can create a keyboard where t...
1
2016-08-05T22:47:41Z
[ "python", "telegram-bot", "python-telegram-bot" ]
Storing Each Iteration of Array after Loop Completion
38,175,089
<p>I'm very new to Python. I've searched extensively for a solution to my problem, but I'm hitting dead ends left and right.</p> <p>I've produced a series of arrays using following code:</p> <pre><code>fh = open(short_seq, 'r') line_counter = 0 pos = [0] array = [0.0 for x in range(101)] for line in fh: line_coun...
0
2016-07-03T23:03:42Z
38,175,977
<pre><code>array = [0.0 for x in range(101)] </code></pre> <p>is a list. <code>array = np.zeros((101,),float)</code> is an array of the same size.</p> <p>With <code>for line in fh:</code> you get a line, a string. I expect <code>for i in line:</code> to iterate over the characters in that string. Is that really wh...
0
2016-07-04T01:55:24Z
[ "python", "arrays", "numpy", "matrix" ]
Python MD5 Cracker "TypeError: object supporting the buffer API required"
38,175,170
<p>My code looks as follows:</p> <pre><code>md = input("MD5 Hash: ") if len(md) != 32: print("Don't MD5 Hash.") else: liste = input("Wordlist: ") ac = open(liste).readlines() for new in ac: new = new.split() hs = hashlib.md5(new).hexdigest() if hs == md: print("MD5 H...
0
2016-07-03T23:17:14Z
38,175,276
<p>Whatever the case, by calling <a href="https://docs.python.org/3/library/stdtypes.html#str.split" rel="nofollow"><strong><code>split()</code></strong></a> on <code>new</code> you create a <code>list</code> object and not an <code>str</code>; lists do not support <a href="https://docs.python.org/3/c-api/buffer.html" ...
0
2016-07-03T23:36:25Z
[ "python", "python-3.x", "md5" ]
Transfering variable to another file using methods, python
38,175,183
<p>I have two different files like this:</p> <p>file name Game.py</p> <pre><code>from objects import * ... player = Player() self.screen.blit(player.draw[0], player.draw[1]) ... </code></pre> <p>and </p> <p>file name Player.py</p> <pre><code>class Player def __init__(self) player = pygame.Rect(0, 0, Tilewidt...
0
2016-07-03T23:20:11Z
38,190,596
<p>In Python, 'import' can easily reach any files or folders with the same filepath. Therefore, why not put the Game and Player files in the same folder? If you do, you could import select variables using :</p> <pre><code>from Game import &lt;variable&gt;, &lt;another variable&gt;, &lt;etc...&gt; </code></pre> <p>in ...
0
2016-07-04T18:38:15Z
[ "python", "pygame" ]
Transfering variable to another file using methods, python
38,175,183
<p>I have two different files like this:</p> <p>file name Game.py</p> <pre><code>from objects import * ... player = Player() self.screen.blit(player.draw[0], player.draw[1]) ... </code></pre> <p>and </p> <p>file name Player.py</p> <pre><code>class Player def __init__(self) player = pygame.Rect(0, 0, Tilewidt...
0
2016-07-03T23:20:11Z
38,190,801
<p>Instead of <code>from objects import *</code> try in Game.py</p> <pre><code>from objects.player import Player </code></pre> <p>It's good practice avoid using wildcard imports (<code>*</code>) to avoid namespace polution as explained <a href="http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#imp...
0
2016-07-04T18:58:07Z
[ "python", "pygame" ]
Django: Increasing the size of Slug with Unique True
38,175,199
<p>I need to increase size of my slug to 500 which by default is 255 characters but same time I need to keep it unique as well. Is there a way around to make it happen?</p> <p>models.py</p> <pre><code>class Product(models.Model): title = models.CharField(max_length=500) description = models.TextField(blank=Tr...
0
2016-07-03T23:22:41Z
38,177,414
<p>According to the <a href="https://docs.djangoproject.com/en/1.9/ref/databases/#character-fields" rel="nofollow">documentation</a> the maximum length for a <code>SlugField</code> is 255 characters. But it is the database backend that enforces it so, depending on which backend you are using, you <em>might</em> be able...
2
2016-07-04T05:21:10Z
[ "python", "django" ]
Detect pattern in a string in python
38,175,235
<p>I need to be able to detect patterns in a string in Python. For example:</p> <p>xx/xx/xx (where x is an integer).</p> <p>How could I do this?</p>
0
2016-07-03T23:29:35Z
38,175,312
<p>This is a case for regular expressions. The best resource to start out that I have read so far would be from a book called "Automate The boring Stuff with Python.</p> <p>This is just a sample of how you migth implement regular expressions to solve your problem. </p> <pre><code>import re regex = re.compile(r'\d\d\...
0
2016-07-03T23:43:51Z
[ "python", "string" ]
Detect pattern in a string in python
38,175,235
<p>I need to be able to detect patterns in a string in Python. For example:</p> <p>xx/xx/xx (where x is an integer).</p> <p>How could I do this?</p>
0
2016-07-03T23:29:35Z
38,175,379
<p>Assuming you want to match more than just dates, you'll want to look into using Regular Expressions (also called Regex). Here is the link for the re Python doc: <a href="https://docs.python.org/2/library/re.html" rel="nofollow">https://docs.python.org/2/library/re.html</a> This will tell you all of the special cha...
0
2016-07-03T23:58:01Z
[ "python", "string" ]
getting filename from python generator object
38,175,257
<p>I am new to python. I am learning os.walk and yield. If I try to <code>print(fname)</code> below it prints a generator object. How do I print the actual file name generated.</p> <pre><code>import os, fnmatch def locate(pattern, root=os.curdir): for path, dirs, files in os.walk(os.paths.abspath(root)): ...
0
2016-07-03T23:33:24Z
38,175,264
<pre><code>if __name__ == '__main__': for fname in locate('assert.py') print(fname) </code></pre> <p>generators are not evaluated until needed (or iterated)</p> <pre><code>print next(locate("assert.py"),"assert.py not found!") </code></pre> <p>is a way to just get the first match</p>
1
2016-07-03T23:34:49Z
[ "python", "generator" ]
How to put the title at the bottom of a figure in matplotlib?
38,175,407
<p>I use matplotlib to plot a figure with four subfigures, and <code>set_title</code> method put the title ( <code>(a) (b) (c) (d)</code>) on the top of every subfigure, see the following code example. </p> <p><code> fig = pyplot.figure()<br> ax = fig.add_subplot(1, 4, 1)<br> ax.set_title('(a)') </code></p> <p>But I...
0
2016-07-04T00:05:37Z
38,175,566
<p>Since you're not using the x axis you can just simply set the xlabel to act as the title, should take care of the positioning:</p> <pre><code>ax.set_xlabel('this really is a title disguised as an x label') </code></pre> <p><strong>Edit:</strong></p> <p>Try offsetting the title according to the figure height, I ho...
2
2016-07-04T00:38:48Z
[ "python", "matplotlib", "title", "figure" ]
How to get information of .jar file in python-magic
38,175,436
<p>I have a folder full of jar, html, css, exe type file. How can I check the file?</p> <p>I already run "file" command on *NIX and using python-magic. but the result is all like this.</p> <p><code>test : Zip archive data, at least v1.0 to extract</code></p> <p>How can I get information specifically like <code>test ...
1
2016-07-04T00:10:54Z
38,175,676
<p>While not required, most JAR files have a <code>META-INF/MANIFEST.MF</code> file contained within them. You could check for the existence of this file, after checking if it's a zip file:</p> <pre><code>import zipfile def zipFileContains(zipFileName, pathName): f = zipfile.ZipFile(zipFileName, "r") result =...
0
2016-07-04T01:00:25Z
[ "python", "python-magic" ]
Curve_fit to apply_along_axis. How to speed it up?
38,175,464
<p>I've got some big datasets to which I'd like to fit monoexponential time decays.</p> <p>The data consists of multiple 4D datasets, acquired at different times, and the fit should thus run along a 5th dimension (through datasets).</p> <p>The code I'm currently using is the following:</p> <pre><code>import numpy as...
1
2016-07-04T00:16:37Z
38,175,802
<p>So you are applying a <code>fit</code> operation 100*100*50*500 times, to a 1d array (of 3 values in the example, more in real life?)?</p> <p><code>apply_along_axis</code> does iterate over all the dimensions of the input array, except for one. There's no compiling or doing this <code>fit</code> over multiple axes...
1
2016-07-04T01:23:01Z
[ "python", "performance", "python-2.7", "numpy", "scipy" ]
Curve_fit to apply_along_axis. How to speed it up?
38,175,464
<p>I've got some big datasets to which I'd like to fit monoexponential time decays.</p> <p>The data consists of multiple 4D datasets, acquired at different times, and the fit should thus run along a 5th dimension (through datasets).</p> <p>The code I'm currently using is the following:</p> <pre><code>import numpy as...
1
2016-07-04T00:16:37Z
38,187,922
<p>In this particular case, where you're fitting a single exponential, you're likely better off to take the log of your data. Then fitting becomes linear and <em>that</em> is much faster than a nonlinear least squares, and can likely be vectorized since it becomes pretty much a linear algebra problem.</p> <p>(And of c...
0
2016-07-04T15:15:21Z
[ "python", "performance", "python-2.7", "numpy", "scipy" ]
How to Save PyCharm Embedded Terminal Tabs
38,175,480
<p>Is there a way to save the Embedded Tabs so each time you open PyCharm you don't have to reconfigure the tab names? It seems like such a simple issue to have but I am unable to find any information on it. This is the documentation on JetBrains Site for <a href="https://www.jetbrains.com/help/pycharm/2016.1/working-w...
0
2016-07-04T00:20:44Z
38,206,076
<p>There is an <a href="https://youtrack.jetbrains.com/issue/IDEA-117946" rel="nofollow">issue</a> about saving terminal tabs between sessions, please vote :)</p>
0
2016-07-05T14:30:23Z
[ "python", "intellij-idea", "ide", "pycharm" ]
How to subset nan/inf values in Dato SFrames
38,175,579
<p>Im trying to subset a column of a large data frame with a couple nan/inf values in one of the columns. </p> <p>I have tried for example something like this.</p> <pre><code>df = df[df['a'] == 'NaN'] </code></pre> <p>Or </p> <pre><code>df = df[df['a'] == 'Inf'] </code></pre> <p>How do I reference these types of v...
0
2016-07-04T00:40:31Z
38,175,613
<p>You know it's a dictionary so you can't use comprehension but you can iterate:</p> <pre><code>subset = {} for d in df: if d['a']=='Nan': subset.update(d) print subset </code></pre>
0
2016-07-04T00:48:49Z
[ "python", "sframe" ]
How to subset nan/inf values in Dato SFrames
38,175,579
<p>Im trying to subset a column of a large data frame with a couple nan/inf values in one of the columns. </p> <p>I have tried for example something like this.</p> <pre><code>df = df[df['a'] == 'NaN'] </code></pre> <p>Or </p> <pre><code>df = df[df['a'] == 'Inf'] </code></pre> <p>How do I reference these types of v...
0
2016-07-04T00:40:31Z
38,195,856
<p>NaN is a special value. It is not equal to anything, not even itself. Here's one way to filter by NaN:</p> <pre><code>import math df = df[df['a'].apply(lambda x: math.isnan(x))] </code></pre> <p>Inf is a little easier:</p> <pre><code>df = df[df['a'] == float('inf')] </code></pre>
0
2016-07-05T05:37:57Z
[ "python", "sframe" ]
How to import nominal features in numpy Python
38,175,615
<pre><code>Botnet_Training_data = np.genfromtxt("training_data.txt", delimiter = ",") </code></pre> <p>This is the code I use to import data from a text file however, when I print the data this is what I see:</p> <pre><code>print (Botnet_Training_data[0]) [ 0.00000000e+00 nan nan nan 4.91000000e+02 0...
0
2016-07-04T00:49:05Z
38,175,779
<p>I'm not sure what you mean by 'nominal'. But as a default <code>genfromtxt</code> is importing values as floats. If it can't convert the string to a float, it places <code>nan</code> in that slot.</p> <p>Try <code>dtype=None</code>, and show us the <code>.shape</code>, and <code>.dtype</code> of the result.</p> ...
0
2016-07-04T01:19:02Z
[ "python", "numpy", "machine-learning", "scikit-learn" ]
How to retrain Inception v3 model in tensorflow
38,175,673
<p>I've been following some tutorials on retraining the Inception v3 model in tensorflow. I used the Google Codelabs Tensorflow for Poets tutorial that is based on a github project. That project uses data on different types of flowers to predict flowers. It says that I can try it on my own data sets by supplying a dire...
0
2016-07-04T00:59:49Z
38,227,368
<p>This line in your output indicates that you didn't download flower images or they are in the wrong place: CRITICAL:tensorflow:Category has no images - validation.</p> <p>What do you have inside of directory $HOME/tf_files/flower_photos ?</p>
0
2016-07-06T15:04:12Z
[ "python", "machine-learning", "tensorflow" ]
How to retrain Inception v3 model in tensorflow
38,175,673
<p>I've been following some tutorials on retraining the Inception v3 model in tensorflow. I used the Google Codelabs Tensorflow for Poets tutorial that is based on a github project. That project uses data on different types of flowers to predict flowers. It says that I can try it on my own data sets by supplying a dire...
0
2016-07-04T00:59:49Z
38,264,426
<p><strong>Fix:</strong></p> <p>The issue happens when you have less number of images in any of your sub folders.</p> <p>I have faced same issue when total number of images under a particular category was less than 30, please try to increase the image count to resolve the issue.</p> <p><strong>Reason:</strong></p> ...
1
2016-07-08T10:28:15Z
[ "python", "machine-learning", "tensorflow" ]
How to retrain Inception v3 model in tensorflow
38,175,673
<p>I've been following some tutorials on retraining the Inception v3 model in tensorflow. I used the Google Codelabs Tensorflow for Poets tutorial that is based on a github project. That project uses data on different types of flowers to predict flowers. It says that I can try it on my own data sets by supplying a dire...
0
2016-07-04T00:59:49Z
38,415,493
<p>For me, this error was caused by having folders in the training directory that did not have images in them. I was following the same "Poets" tutorial and ended up putting directories with subdirectories in the image dir. Once I removed those and placed only directories with images directly in them (no sub dirs) the ...
0
2016-07-16T20:48:08Z
[ "python", "machine-learning", "tensorflow" ]
How to retrain Inception v3 model in tensorflow
38,175,673
<p>I've been following some tutorials on retraining the Inception v3 model in tensorflow. I used the Google Codelabs Tensorflow for Poets tutorial that is based on a github project. That project uses data on different types of flowers to predict flowers. It says that I can try it on my own data sets by supplying a dire...
0
2016-07-04T00:59:49Z
39,862,603
<p>I was trying to train using my own set of images (pictures of dogs instead of flowers), and ran into this same problem.</p> <p>I identified that the problem for me ended up being that my folder names (category names) weren't present in the imagenet_synset_to_human_label_map.txt file that gets loaded in the inceptio...
0
2016-10-04T22:15:40Z
[ "python", "machine-learning", "tensorflow" ]
Pandas List Append Issue! Can Print() but Cannot .append()
38,175,709
<p>I am working on a small project and need to carryout some heavy data scrubbing. So far, so good but I have hit a brick wall.</p> <p>I cannot append variables to a list. I can print them out, but when I attempt to .append() these variables, the first item only is successful.</p> <pre><code>for i in gr2.Segment.toli...
0
2016-07-04T01:07:02Z
38,175,727
<p>Replace</p> <pre><code>for i in gr2.Segment.tolist(): l = len(i[0]) r = len(i[1]) dl = [] dl.append(l) </code></pre> <p>with</p> <pre><code>dl = [] for i in gr2.Segment.tolist(): l = len(i[0]) r = len(i[1]) dl.append(l) </code></pre> <p>You re-declare your list every iteration - that'...
1
2016-07-04T01:10:14Z
[ "python", "loops", "pandas", "append" ]
Effectively adding new columns from sqlite db to pandas dataframe
38,175,724
<p>I am learning more and more about python, moving from less efficient looping over lists of lists and have been learning numpy/pandas.</p> <p>Let's say I have a pandas data frame <em>df</em>, for example something that looks like:</p> <pre><code>| id | Year | Value | --------------------- | 1 | 2015 | 1.00 | | 1 ...
1
2016-07-04T01:09:45Z
38,175,929
<p>Since you want an SQL-style <em>left join</em>, just use</p> <pre><code>pd.merge(df, data.fetchall(), on='id', how='left') </code></pre>
1
2016-07-04T01:47:00Z
[ "python", "sqlite", "pandas" ]
Smooth movement with Tkinter?
38,175,765
<p>I'm trying to make a movable sprite in Tkinter; it works, but I'm not sure binding a Canvas with is the best solution. There is a delay after I press "w", for example, where the character moves once, stops for a few seconds, then starts moving a bit laggily.</p> <p>Code:</p> <pre><code>import Tkinter as t tk = t...
0
2016-07-04T01:16:10Z
38,175,922
<p>Alright, I found an answer to my question. I just created a game loop and added a <code>velx</code> variable, and added the bindings <code>&lt;KeyPress&gt;</code> and <code>&lt;KeyRelease&gt;</code>.</p> <p>Code:</p> <pre><code>import Tkinter as t tk = t.Tk() w = t.Button() c = t.Canvas(tk, bg = "#000000", bd = 3...
2
2016-07-04T01:45:39Z
[ "python", "tkinter" ]
Failed to query in sqlite by using column names
38,175,776
<p>This is an extended question from <a href="http://stackoverflow.com/questions/38165636/assigning-column-names-in-a-txt-file-in-python/38165919#38165919">Assigning column names in a txt file in python</a></p> <p>I have the following code. I extracted data from a xml file and saved it into a txt file. Then I imported...
0
2016-07-04T01:18:00Z
38,186,017
<p>As zhliu03 indicated, the cause of the problem is the leading space is taken as part of the column names.</p> <p>This solves the problem:</p> <pre><code>f.write("programID,season,workID,composerLastName,composerFirstName,workTitle,OpusNumber,conductorLastName,conductorFirstName\n") </code></pre>
0
2016-07-04T13:31:15Z
[ "python", "sqlite", "sqlite3" ]
Django-Guardian - Restrict group access to class
38,175,777
<p>I have followed the user guide from the django-guardian docs to set up django-guardian. This has given me the possibility to control whether a group can view a specific class or not. This is the example from the django-guardian docs with an added field (customer):</p> <pre><code>class Task(models.Model): summar...
1
2016-07-04T01:18:07Z
38,177,572
<p>This can be easily achieved with django-guardian, it just requires a bit more coding from your behalf.</p> <p>For instance, to restrict which records a view returns in an admin changelist:</p> <pre><code>from django.contrib import admin from myapp import models from guardian.shortcuts import get_objects_for_user ...
1
2016-07-04T05:38:35Z
[ "python", "django", "python-3.x", "django-guardian" ]
Parsing and searching in CSV in python
38,175,797
<p>I am using python 3.5.x </p> <p>In python i am trying to parse a csv file which has lot of paragrah in it and identity and get couple of matches and create new csv file out of it</p> <p>lets imaging i have 2 rows but in real time will have more rows</p> <p><strong>Description.</strong></p> <pre><code>Welcom new ...
0
2016-07-04T01:22:16Z
38,176,946
<p>Simplify your process by using <a href="https://docs.python.org/3/library/string.html#format-string-syntax" rel="nofollow">string formatting</a> to construct the line you are going to write:</p> <pre><code>s = '{},{}|{}\n{}|{}' </code></pre> <p>Assign the data to variable names</p> <pre><code>if user_name: us...
0
2016-07-04T04:25:21Z
[ "python", "csv", "parsing", "search" ]
What does "TypeError: can't multiply sequence by non-int of type 'tuple'" mean?
38,175,905
<pre><code>#Finding the volume of a box print("Welcome to box volume calculation! Please answer the following questions.") x = float(raw_input("How wide is the box? ")), y = float(raw_input("How high is the box? ")), z = float(raw_input("How long is the box? ")), "The volume of the box is " + str(x*y*z) + " units cube...
0
2016-07-04T01:42:03Z
38,175,907
<p>Get rid of your commas in the lines where you are asking for input. Those lines should read:</p> <pre><code>x = float(raw_input("How wide is the box? ")) y = float(raw_input("How high is the box? ")) z = float(raw_input("How long is the box? ")) </code></pre> <p>Explanation ... a statement of the form:</p> <pre>...
3
2016-07-04T01:43:01Z
[ "python" ]
What does "TypeError: can't multiply sequence by non-int of type 'tuple'" mean?
38,175,905
<pre><code>#Finding the volume of a box print("Welcome to box volume calculation! Please answer the following questions.") x = float(raw_input("How wide is the box? ")), y = float(raw_input("How high is the box? ")), z = float(raw_input("How long is the box? ")), "The volume of the box is " + str(x*y*z) + " units cube...
0
2016-07-04T01:42:03Z
38,175,913
<p>Your <em>variables</em> are tuples not floats:</p> <pre><code>x = float(raw_input("How wide is the box? ")), # ^ </code></pre> <p>The trailing comma makes your object a tuple containing one float:</p> <pre><code>&gt;&gt;&gt; x = 2.2, &gt;&gt;&gt; type(x) &lt;class 'tuple...
1
2016-07-04T01:43:43Z
[ "python" ]
How to go to next page when web crawling using Python
38,175,975
<p>I trying to do web crawling using python. But I can't figure out how to change pages automatically. So I found the pattern but I don't know how to go to next page automatically until it reaches end of page. </p> <p>so the pattern is </p> <p>'http//.../sortBy=helpful&amp;pageNumber=0'</p> <p>'http//.../sortBy=hel...
0
2016-07-04T01:54:55Z
38,176,026
<p>Not directly answering the question, but this is something that can be easily and conveniently handled by <a href="http://scrapy.org/" rel="nofollow"><code>Scrapy</code></a>'s <a href="http://doc.scrapy.org/en/latest/topics/spiders.html#crawlspider" rel="nofollow"><code>CrawlSpider</code> class</a> and the <a href="...
0
2016-07-04T02:03:26Z
[ "python", "python-3.x", "web-crawler", "urllib2" ]
Python Script Won't Run from Aws Ubuntu Terminal
38,176,089
<p>I just set up my first aws server for a personal project I'm doing. I'm running ubuntu linux, and I have a python script that accesses an sqlite database file in order to send email. I have these same files on my own ubuntu machine and the script works fine. I'm having trouble, however, figuring out how to run my sc...
0
2016-07-04T02:14:26Z
38,176,230
<p>You can modify the script to add verbose that prints out to the console the status of the script, or if you just want to know whether your script is running in the background, you can check whether the process is active using <code>ps</code> (process name would be the name of the script) :</p> <pre><code>ps aux | g...
0
2016-07-04T02:38:01Z
[ "python", "linux", "ubuntu", "amazon-web-services" ]
Translating multi-byte characters into 7-bit ASCII in Python
38,176,258
<p>I'm downloading and parsing a web page via a Python script. I need it to be encoded into 7-bit ASCII for further processing. I am using the requests library (<a href="http://docs.python-requests.org/en/master/" rel="nofollow">http://docs.python-requests.org/en/master/</a>) in a virtualenv based upon whatever Ubuntu ...
0
2016-07-04T02:43:19Z
38,178,064
<p>Python has everything you need to cleanly process non ASCII characters... provided you declare the proper encoding. Your input file is UTF8 encoded, not ISO-8859-1, because <code>r'\xe2\x80\x93'</code> is the UTF8 encoding for the EN DASH character or unicode <code>U+2013</code>.</p> <p>So you should:</p> <ul> <li...
1
2016-07-04T06:24:42Z
[ "python", "encoding", "python-requests" ]
Python - Continuous Input, biggest and smallest numbers with try and except
38,176,316
<p>Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number.</p> <...
-5
2016-07-04T02:51:57Z
38,176,724
<p>Let me try to answer. Your code only check the length's input is less than 1 or not. So, for example, when user type <code>a</code>, it is accepted. It only break when user type nothing, which has length 0. You must check: - user's input is <code>Done</code> or not, - user's input is number or not</p> <p>After t...
0
2016-07-04T03:53:09Z
[ "python", "python-2.7" ]
Python - Continuous Input, biggest and smallest numbers with try and except
38,176,316
<p>Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number.</p> <...
-5
2016-07-04T02:51:57Z
38,180,154
<p>Here's one way you can do it:</p> <p>You can put the values in the list and then use the <code>max()</code> and <code>min()</code> method to get the greatest and lowest value</p> <p>Here's my code:</p> <pre><code>smallestNum=None largestNum=None listOfValues=[] try: while True: try: #To catch any non...
1
2016-07-04T08:34:40Z
[ "python", "python-2.7" ]
Python Solving System Of Equations For Variable On Both Sides Of Equality
38,176,323
<p>Is there a way to solve a linear system of equations in python where the unknown is on both sides of the equality. So for instance if I have:</p> <pre><code>x_1 = 0.7 + 0.5 * x_1 - 0.4 * x_2 x_2 = 0.7 * x_1 + 0.5 - 0.4 * x_1 x_3 = 0.7 * x_2 + 0.5 * x_1 - 0.4 </code></pre> <p>where this can be expressed as:</p> <p...
1
2016-07-04T02:52:34Z
38,176,947
<p>Looks like that can be easily cast as a linear equation problem:</p> <pre><code>-0.7 = (0.5 - 1) * x_1 - 0.4 * x_2 -0.5 = 0.7 * x_1 - (0.4 + 1) * x_2 0.4 = 0.7 * x_2 + 0.5 * x_1 - x_3 A = np.array([[0.5-1, -0.4, 0], [0.7, -.4-1, 0], [.5, .7, -1]]) F = np.array([-.7, -.5, .4]) F = A * X X = F/A </code></pre> <p>w...
0
2016-07-04T04:25:26Z
[ "python", "numpy", "sympy" ]
Python Solving System Of Equations For Variable On Both Sides Of Equality
38,176,323
<p>Is there a way to solve a linear system of equations in python where the unknown is on both sides of the equality. So for instance if I have:</p> <pre><code>x_1 = 0.7 + 0.5 * x_1 - 0.4 * x_2 x_2 = 0.7 * x_1 + 0.5 - 0.4 * x_1 x_3 = 0.7 * x_2 + 0.5 * x_1 - 0.4 </code></pre> <p>where this can be expressed as:</p> <p...
1
2016-07-04T02:52:34Z
38,177,043
<p>You need to get your equations to form (x_3 omitted for obvious reasons)</p> <pre><code>0.5 * x1 + 0.4 * x2 = 0.7 0.7 * x1 - 1.4 * x2 = -0.5 </code></pre> <p>before you can use <code>numpy.linalg.solve</code>, like in this case</p> <pre><code>import numpy as np a = np.array([[0.5, 0.4], # first row x_i facto...
2
2016-07-04T04:37:37Z
[ "python", "numpy", "sympy" ]
graph.write_pdf("iris.pdf") AttributeError: 'list' object has no attribute 'write_pdf'
38,176,472
<p>My code is follow the class of machine learning of google.The two code are same.I don't know why it show error.May be the type of variable is error.But google's code is same to me.Who has ever had this problem?</p> <p>This is error</p> <pre><code>[0 1 2] [0 1 2] Traceback (most recent call last): File "/media/jo...
6
2016-07-04T03:13:34Z
38,177,223
<p>I think you are using newer version of python. Please try with pydotplus.</p> <pre><code>import pydotplus ... graph = pydotplus.graph_from_dot_data(dot_data.getvalue()) graph.write_pdf("iris.pdf") </code></pre> <p>This should do it.</p>
12
2016-07-04T04:59:49Z
[ "python", "machine-learning", "graphviz", "pydot" ]
graph.write_pdf("iris.pdf") AttributeError: 'list' object has no attribute 'write_pdf'
38,176,472
<p>My code is follow the class of machine learning of google.The two code are same.I don't know why it show error.May be the type of variable is error.But google's code is same to me.Who has ever had this problem?</p> <p>This is error</p> <pre><code>[0 1 2] [0 1 2] Traceback (most recent call last): File "/media/jo...
6
2016-07-04T03:13:34Z
39,169,550
<p><code>pydot.graph_from_dot_data()</code> returns a list, so try:</p> <pre><code>graph = pydot.graph_from_dot_data(dot_data.getvalue()) graph[0].write_pdf("iris.pdf") </code></pre>
4
2016-08-26T15:15:16Z
[ "python", "machine-learning", "graphviz", "pydot" ]
graph.write_pdf("iris.pdf") AttributeError: 'list' object has no attribute 'write_pdf'
38,176,472
<p>My code is follow the class of machine learning of google.The two code are same.I don't know why it show error.May be the type of variable is error.But google's code is same to me.Who has ever had this problem?</p> <p>This is error</p> <pre><code>[0 1 2] [0 1 2] Traceback (most recent call last): File "/media/jo...
6
2016-07-04T03:13:34Z
40,121,499
<p>I install scikit-learn via conda and all of about not work. Firstly, I have to install libtool</p> <pre><code>brew install libtool --universal </code></pre> <p>Then I follow <a href="http://scikit-learn.org/stable/modules/generated/sklearn.tree.export_graphviz.html" rel="nofollow">this sklearn guide</a> Then chang...
0
2016-10-19T03:13:22Z
[ "python", "machine-learning", "graphviz", "pydot" ]
Does pandas.read_csv loads all data at once?
38,176,645
<p>I want to know when I use <code>pandas.read_csv('file.csv')</code> function to read <code>csv</code> file, did it load all data of <code>file.csv</code> into <code>DataFrame</code>?</p>
0
2016-07-04T03:42:20Z
38,176,821
<p>The way to check is <code>len(df)</code>. This will give you the number of lines in <code>DataFrame.</code> Then, you need to check the <code>csv</code> file for lines. On linux, use <code>wc -l</code>. Or, you may need to use something else to findout lines in csv. <code>Notepad++, Nano, SumlineText.</code></p>
0
2016-07-04T04:07:42Z
[ "python", "pandas" ]
Trying to get IQR with groupby data
38,176,655
<p>I'm new to Python. I'm trying to create a basic set of descriptive stats (min, max, IQR, etc.).</p> <p>I snipped some code to help me get to where I am, but it is a bit more complicated since I've used groupby: </p> <pre><code>Causesofdeathbyyear = deathdata.groupby(['Year','Causes of Death']) </code></pre> <p>Wh...
0
2016-07-04T03:43:30Z
38,176,843
<p>You should just be passing <code>IQR</code> instead of <code>IQR()</code></p> <p>Here is a similar example:</p> <pre><code>In[1]: import pandas as pd In[2]: import numpy as np In[3]: data = pd.DataFrame({"A": np.random.random_integers(0, 100, 100), "Year": np.random.random_integers(2000, 2015, 100)}) In[4]: gro...
0
2016-07-04T04:10:45Z
[ "python", "pandas", "statistics" ]
Why the single quotes cannot be removed in this Python code?
38,176,662
<p>I find below code from internet and run it correctly.</p> <pre><code>#!/usr/bin/python import demjson json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; text = demjson.decode(json) print text </code></pre> <p>The result is below:</p> <pre><code>{u'a': 1, u'c': 3, u'b': 2, u'e': 5, u'd': 4} </code></pre> <p>But if I re...
-1
2016-07-04T03:44:21Z
38,176,682
<p>Because then it's not JSON. JSON is a <strong><em>string</em></strong> that looks like JavaScript objects. Making it not a string makes it not JSON.</p>
5
2016-07-04T03:48:40Z
[ "python" ]
Why the single quotes cannot be removed in this Python code?
38,176,662
<p>I find below code from internet and run it correctly.</p> <pre><code>#!/usr/bin/python import demjson json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; text = demjson.decode(json) print text </code></pre> <p>The result is below:</p> <pre><code>{u'a': 1, u'c': 3, u'b': 2, u'e': 5, u'd': 4} </code></pre> <p>But if I re...
-1
2016-07-04T03:44:21Z
38,176,701
<p>Well you could do this if you really wanted to:</p> <pre><code>import json m = {"a":1,"b":2,"c":3,"d":4,"e":5} n = json.dumps(m) o = json.loads(n) print o['a'], o['b'] </code></pre> <p>The main reason why your code won't work is answered by <a href="http://stackoverflow.com/a/38176682/264802">Ignacio Vazqu...
-1
2016-07-04T03:51:00Z
[ "python" ]
Sympy RuntimeError: maximum recursion depth exceeded when solving equation with logarithms
38,176,765
<p>I'm trying to solve a simple equation with logarithms in sympy, however I get a <code>RuntimeError: maximum recursion depth exceeded</code> when I try to execute the code. Here is what I am doing:</p> <pre><code>import sympy as sp import numpy as np pH = sp.Symbol("pH") pCO2 = sp.Symbol("pCO2") HCO3 = sp.Symbol("H...
2
2016-07-04T03:59:40Z
38,179,082
<p>If you want a symbolic solution, based on algebraic manipulations (which is what SymPy is for), you should avoid floats as much as possible. For example, 6.1 is represented as 3433994715870003/562949953421312 in double precision, and when a coefficient like that meets logarithms, algebraic manipulations can easily p...
2
2016-07-04T07:29:32Z
[ "python", "sympy", "symbolic-math" ]
Dealing with lots of objects in a Python Program
38,176,794
<p>I am building a python program which will be working with thousands of python objects. I am curious about what is the most elegant way to organize them, and I am also not clear on when things get copied in python. </p> <p>For example if I have a manager object which has a list of thousands of objects, but it also h...
2
2016-07-04T04:04:17Z
38,177,101
<p><a href="http://stackoverflow.com/questions/986006/how-do-i-pass-a-variable-by-reference">This post</a> talks about passing a variable by reference (Python passes by assignment). </p> <blockquote> <p>[If] I have a manager object which has a list of thousands of objects, but it also has a dictionary with keys to e...
0
2016-07-04T04:45:57Z
[ "python", "python-3.x", "oop" ]
Why can't I create more than one instance of my class?
38,176,813
<p>When I create the first instance of my class it runs perfectly. But when I try to create a second instance I get a TypeError: 'str' object is not callable.</p> <pre><code>class Settlement: def __init__(self): self.name() . . . First_Name = [list items here] Second_Name = [list items...
0
2016-07-04T04:06:46Z
38,176,910
<p>In:</p> <pre><code>def name(self): first = Settlement.First_Name[random.randint(0, (len(Settlement.First_Name)-1))] second = Settlement.Second_Name[random.randint(0, (len(Settlement.Second_Name)-1))] Settlement.name = "Name: "+ first+second </code></pre> <p>You have a method called <code>name</code> - ...
1
2016-07-04T04:20:26Z
[ "python", "class", "object" ]
Why can't I create more than one instance of my class?
38,176,813
<p>When I create the first instance of my class it runs perfectly. But when I try to create a second instance I get a TypeError: 'str' object is not callable.</p> <pre><code>class Settlement: def __init__(self): self.name() . . . First_Name = [list items here] Second_Name = [list items...
0
2016-07-04T04:06:46Z
38,176,919
<p>Update 1: The problem is that you are using name as function and as Class variable. Change the Settlement.name to something else and it work.</p> <pre><code>import random class Settlement: def __init__(self): self.name() First_Name = ['Romaan', 'test'] Second_Name = ['Shmrd', 'test'] def ...
1
2016-07-04T04:21:06Z
[ "python", "class", "object" ]
using multiprocessing with theano
38,176,827
<p>I'm trying to use theano with cpu-multiprocessing with a neural network library, Keras.</p> <p>I use <code>device=gpu</code> flag and load the keras model. Then for extracting features for over a million images, im using multiprocessing pool.</p> <p>The function looks something like this:</p> <pre><code>from kera...
2
2016-07-04T04:08:58Z
38,684,285
<p>It is possible to use multiple processes if the other processes do not use keras, to my knowledge you need to restrict usage of keras to a single process. This seems to include all keras classes and methods, even those who do not seem to use the gpu, e.g. ImageDataGenerator.</p> <p>If the workload is GPU limited it...
0
2016-07-31T13:07:36Z
[ "python", "multithreading", "multiprocessing", "theano", "keras" ]
Union of two lists of dictionaries containing lists
38,176,838
<p>I have two lists: </p> <pre><code>lst1 = [{u'Hours': [{u'HourOfDay': 15, u'TotalVisits': 1, u'TotalTimeSpent': 7223.0}, {u'HourOfDay': 12, u'TotalVisits': 3, u'TotalTimeSpent': 37550.0}], u'DayOfWeek': 1}, {u'Hours': [{u'HourOfDay': 19, u'TotalVisits': 6, u'TotalTimeSpent': 234...
0
2016-07-04T04:10:30Z
38,177,551
<p>Ok, here is a solution using your current data structure, which personally I think is silly because it combines the worst aspects of a list with the worst aspects of a dictionary:</p> <pre><code>final = [] for d1,d2 in zip(list1,list2): new = {'DayOfWeek':d1['DayOfWeek'], 'Hours':[]} d1copy = d1['Hours'][:...
1
2016-07-04T05:36:24Z
[ "python" ]
Union of two lists of dictionaries containing lists
38,176,838
<p>I have two lists: </p> <pre><code>lst1 = [{u'Hours': [{u'HourOfDay': 15, u'TotalVisits': 1, u'TotalTimeSpent': 7223.0}, {u'HourOfDay': 12, u'TotalVisits': 3, u'TotalTimeSpent': 37550.0}], u'DayOfWeek': 1}, {u'Hours': [{u'HourOfDay': 19, u'TotalVisits': 6, u'TotalTimeSpent': 234...
0
2016-07-04T04:10:30Z
38,180,630
<p>This is a really strange dict structure, and you're even using a non-zero-based numerical scale for days of the week. It took me a while to parse your data structure, but here's what's going on: </p> <p>lst1 and lst2 are structured as lists of objects like this: [{object Day 1}, {object Day 2}, ... {object Day 7}]...
0
2016-07-04T09:00:13Z
[ "python" ]
Implicit differentiation with Python 3?
38,176,865
<p>How can we derivate a implicit equation in Python 3?<br> Example <code>x^2+y^2=25</code> differentiation is: <code>dy/dx=-x/y</code>, when try this:</p> <pre><code>from sympy import * init_printing(use_unicode=True) x = symbols('x') y = Function('y')(x) eq = x**2+y**2-25 sol = diff(eq, x) print(sol) </code></pre...
2
2016-07-04T04:14:22Z
38,177,145
<p>You have the differential equation, so you can rearrange it using solve:</p> <pre><code>solve(sol, diff(y, x, 1)) </code></pre>
1
2016-07-04T04:51:03Z
[ "python", "python-3.x", "math", "sympy", "calculus" ]
Implicit differentiation with Python 3?
38,176,865
<p>How can we derivate a implicit equation in Python 3?<br> Example <code>x^2+y^2=25</code> differentiation is: <code>dy/dx=-x/y</code>, when try this:</p> <pre><code>from sympy import * init_printing(use_unicode=True) x = symbols('x') y = Function('y')(x) eq = x**2+y**2-25 sol = diff(eq, x) print(sol) </code></pre...
2
2016-07-04T04:14:22Z
38,187,173
<p>You may use the implicit function theorem which states that when two variables <code>x</code>, <code>y</code>, are related by the implicit equation <code>f(x, y) = 0</code>, then the derivative of <code>y</code> with respect to <code>x</code> is equal to <code>- (df/dx) / (df/dy)</code> (as long as the partial deriv...
2
2016-07-04T14:33:38Z
[ "python", "python-3.x", "math", "sympy", "calculus" ]
Implicit differentiation with Python 3?
38,176,865
<p>How can we derivate a implicit equation in Python 3?<br> Example <code>x^2+y^2=25</code> differentiation is: <code>dy/dx=-x/y</code>, when try this:</p> <pre><code>from sympy import * init_printing(use_unicode=True) x = symbols('x') y = Function('y')(x) eq = x**2+y**2-25 sol = diff(eq, x) print(sol) </code></pre...
2
2016-07-04T04:14:22Z
38,213,287
<p>SymPy has the function <code>idiff</code> which does what you want</p> <pre><code>In [2]: idiff(x**2+y**2-25, y, x) Out[2]: -x ─── y </code></pre>
3
2016-07-05T21:44:05Z
[ "python", "python-3.x", "math", "sympy", "calculus" ]
Calculating square root using only integer math in python
38,177,013
<p>I'm working on a microcontroller that does not support floating point math. Integer math only. As such, there is no sqrt() function and I can't import any math modules. The MCU is running a subset of python that supports eight Python data types: None, integer, Boolean, string, function, tuple, byte list, and iterato...
3
2016-07-04T04:33:44Z
38,177,299
<p>there is a algorithm to calculate it, but it use floor division, without that this is what come to my mind</p> <pre><code>def isqrt_linel(n): x = 0 while (x+1)**2 &lt;= n: x+=1 return x </code></pre> <p>by the way, the algorithm that I know use the Newton method:</p> <pre><code>def isqrt(n): ...
1
2016-07-04T05:08:04Z
[ "python", "math", "square-root" ]
Calculating square root using only integer math in python
38,177,013
<p>I'm working on a microcontroller that does not support floating point math. Integer math only. As such, there is no sqrt() function and I can't import any math modules. The MCU is running a subset of python that supports eight Python data types: None, integer, Boolean, string, function, tuple, byte list, and iterato...
3
2016-07-04T04:33:44Z
38,177,333
<p>Note that the largest possible sum is 3*1024**2, so the largest possible square root is 1773 (floor - or 1774 rounded).</p> <p>So you could simply take 0 as a starting guess, and repeatedly add 1 until the square exceeds the sum. That can't take more than about 1770 iterations.</p> <p>Of course that's probably to...
3
2016-07-04T05:11:59Z
[ "python", "math", "square-root" ]
Modify different objects without checking flags
38,177,073
<p>I am wanting to modify different objects. At the moment I pass a flags parameter to decide whether to perform the changes or not. Is there a way to make this work without passing any flags, or is this the best way of doing it? I dont feel like this is a scalable solution once I have more instances of the objects.</p...
1
2016-07-04T04:41:35Z
38,177,180
<p>Using <a href="https://docs.python.org/2/library/functions.html#getattr" rel="nofollow"><code>getattr</code></a>, you can access arbitrary instance member of an object:</p> <pre><code>getattr(obj, instance_attribute_name) </code></pre> <p>Example:</p> <pre><code>&gt;&gt;&gt; 'a'.upper() 'A' &gt;&gt;&gt; getattr('...
1
2016-07-04T04:55:05Z
[ "python", "oop", "static-methods" ]
PHP get python processes and kill it. Xamp/Windows
38,177,134
<p>How can I get all the python processes along with the arguments of each of process and kill it via PHP Xampp/Windows</p>
2
2016-07-04T04:50:10Z
38,420,833
<pre><code>exec("ps aux | grep python", $psOutput); if (count($psOutput) &gt; 0) { foreach ($psOutput as $ps) { $ps = preg_split('/ +/', $ps); $pid = $ps[1]; exec("kill -9 $pid"); } } </code></pre> <p>Try this or <code>exec("pkill -9 python");</code></p>
-2
2016-07-17T11:45:27Z
[ "php", "python", "windows", "xampp" ]
PHP get python processes and kill it. Xamp/Windows
38,177,134
<p>How can I get all the python processes along with the arguments of each of process and kill it via PHP Xampp/Windows</p>
2
2016-07-04T04:50:10Z
38,485,814
<p>On windows there are three system commands to get processes :</p> <p><code>tasklist</code>, probably the simplest (though you don't have access to the args).</p> <p><code>get-process</code>, requires powershell, can't see its output I don't have powershell</p> <p>And what should satisfy your needs : <code>wmic pr...
4
2016-07-20T16:20:26Z
[ "php", "python", "windows", "xampp" ]
PHP get python processes and kill it. Xamp/Windows
38,177,134
<p>How can I get all the python processes along with the arguments of each of process and kill it via PHP Xampp/Windows</p>
2
2016-07-04T04:50:10Z
38,530,182
<pre><code>&lt;?php $list = str_replace(' ','|',shell_exec('tasklist')); $split = explode("\n", $list); $extension = 'py'; foreach ($split as $item) { preg_match_all('#((.*)\.'.$extension.')[\|]+([0-9]+)#',$item, $matches); if($matches[1][0] != '' and $matches[3][0] != ''){ echo $matches[1][0].' '.shell_exec('T...
0
2016-07-22T15:25:19Z
[ "php", "python", "windows", "xampp" ]
PHP get python processes and kill it. Xamp/Windows
38,177,134
<p>How can I get all the python processes along with the arguments of each of process and kill it via PHP Xampp/Windows</p>
2
2016-07-04T04:50:10Z
38,546,144
<p>You can use <code>tasklist</code> and <code>taskkill</code> commands via <code>shell_exec</code> function. The following <code>Task</code> demonstrate how they can be used to find info about tasks and how to kill them.</p> <pre><code>class Task { function __construct($header,$row) { $this-&gt;im...
3
2016-07-23T20:29:13Z
[ "php", "python", "windows", "xampp" ]
Error using functions from another script in python
38,177,143
<p>I'm trying to get a little bit better organized in my programming, so I've decided to use multiple python files to organize my game. For some reason, I cannot use functions from another script. My main script in which I run the game is called main.py and the script I'm trying to use functions from is gamemap.py . He...
0
2016-07-04T04:50:44Z
38,177,330
<p>Please check whether the two file are in the same directory.</p> <p>You can also use </p> <pre><code>from gamemap import loadmapstuff loadmapstuff() </code></pre>
0
2016-07-04T05:11:38Z
[ "python", "python-2.7", "pygame" ]
Error using functions from another script in python
38,177,143
<p>I'm trying to get a little bit better organized in my programming, so I've decided to use multiple python files to organize my game. For some reason, I cannot use functions from another script. My main script in which I run the game is called main.py and the script I'm trying to use functions from is gamemap.py . He...
0
2016-07-04T04:50:44Z
38,178,182
<p>When you create your own <b>module</b> (in your case gamemap.py) you must create and empty file call <code>__init__.py</code> inside the folder that contains your module.</p> <p>With this file (<code>__init__.py</code>) python understood that this folder is a package, and then you can <code>import</code> the module...
1
2016-07-04T06:33:20Z
[ "python", "python-2.7", "pygame" ]
How to emit dataChanged in PyQt5
38,177,144
<p>The code below breaks on self.emit line. It works fine in PyQt4. How to fix this code so it works in PyQt5?</p> <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtCore import QObject, pyqtSignal class ItemDelegate(QtWidgets.QItemDelegate): def __init__(self, parent): QtWidgets.QItemDele...
1
2016-07-04T04:51:01Z
38,178,198
<p><a href="http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html" rel="nofollow">As you can read here</a>, <code>QtCore.SIGNAL</code> was discontinued after <code>PyQt4</code> and is therefore not compatible.</p> <p><a href="http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html" rel="nofollow">This page</...
0
2016-07-04T06:34:32Z
[ "python", "qt", "pyqt", "pyqt5" ]
Create a file with maven
38,177,265
<p>I am using maven to generate some protobuf python code but it erases the <strong>init</strong>.py every time.</p> <p>I was wondering if maven had a tool to create a blank <strong>init</strong>.py so that I do not need to create it manually every single time.</p> <p>(Maybe a copy from a different <strong>init</stro...
0
2016-07-04T05:03:57Z
38,190,337
<p>The solution was found here: <a href="https://github.com/xolstice/protobuf-maven-plugin/issues/9" rel="nofollow">https://github.com/xolstice/protobuf-maven-plugin/issues/9</a></p> <p>Instead of creating a new file. I instead just didn't delete it. (for anyone else wanting to create a file through maven... keep sea...
0
2016-07-04T18:16:42Z
[ "python", "maven" ]
Delete partial data in mongoDB
38,177,273
<p>I have a mongoDB collection which has a count of <code>372985</code> names, I want to delete entries after <code>200000</code> so that total number of entries after deletion reduces from <code>372985</code> to <code>200000</code></p> <p>How can I do this by mongoDB query?</p> <p><strong>Usecase</strong></p> <p>My...
2
2016-07-04T05:04:26Z
38,183,147
<p>You need to do it in steps, cause MongoDB needs a query to match documents to be deleted; MongoDB cannot use <code>skip</code> or <code>limit</code> when removing documents.</p> <ol> <li>find (the ids of) documents that you want to delete, using skip to jump to documents after 200000 </li> <li>delete the documents ...
1
2016-07-04T11:03:09Z
[ "python", "database", "mongodb", "mongodb-query", "mongo-shell" ]
Execute Select query on Mysql table over 300 million rows(hit no index) using multiple threads?
38,177,285
<p><strong>ABSTRACT</strong></p> <p>I aim to read data from database A, do some extra processing, then insert the new one into database B. Because the data size is extremely large, I can barely read them all at once, then I slice them into several pieces and spawn multiple threads to read and process.</p> <p><strong>...
0
2016-07-04T05:05:52Z
38,177,487
<blockquote> <p>I know such Select queries are slow queries since every single Select query has to search the entire table(iterates over 300 million rows, according to the EXPLAIN command) before it could return what I want. But why multi-threading doesn't work and even make it worse? What's the corresponding...
0
2016-07-04T05:28:40Z
[ "python", "mysql", "sql", "database", "multithreading" ]
Is there a way to save multiple plots to html in plotly
38,177,343
<p>I would like to generate independent plots and save them to one html file, using plotly offline plot. Is there a way to achieve this?</p>
-1
2016-07-04T05:12:44Z
38,179,842
<p>I hope the following example, taken from <a href="https://mpld3.github.io/examples/index.html#example-gallery" rel="nofollow">here</a>, suites your needs:</p> <pre><code>import matplotlib.pyplot as plt import numpy as np import pandas as pd import mpld3 from mpld3 import plugins # Define some CSS to control our cu...
1
2016-07-04T08:17:02Z
[ "python", "plotly" ]
Failed to insert the data using python.mysql connector
38,177,405
<p>I'm new to using MySQL connector for python and I have the below-given data to be inserted into a table called "region_based_billings". I tried all possible ways to insert this data and it seems I missing a syntax not sure exactly where and for which data type? . </p> <pre><code> date = '2016-06-29' region = ...
0
2016-07-04T05:19:40Z
38,177,495
<p>Remove space between column names. column name should be a single word or words seprated by _. In your case column name have gap. So these column should be:-</p> <pre><code>account type = account_type product type = product_type </code></pre> <p>and so on...</p>
1
2016-07-04T05:29:44Z
[ "python", "mysql-workbench", "mysql-python", "mysql-connector" ]
Failed to insert the data using python.mysql connector
38,177,405
<p>I'm new to using MySQL connector for python and I have the below-given data to be inserted into a table called "region_based_billings". I tried all possible ways to insert this data and it seems I missing a syntax not sure exactly where and for which data type? . </p> <pre><code> date = '2016-06-29' region = ...
0
2016-07-04T05:19:40Z
38,177,689
<p>Removed the white spaces and it resolved the problem. Thanks. </p> <pre><code>Serial_no int(11) NO PRI auto_increment date date NO region varchar(50) NO account_type varchar(65) NO product_type varchar(65) NO total_amount float YE...
0
2016-07-04T05:50:17Z
[ "python", "mysql-workbench", "mysql-python", "mysql-connector" ]
Failed to insert the data using python.mysql connector
38,177,405
<p>I'm new to using MySQL connector for python and I have the below-given data to be inserted into a table called "region_based_billings". I tried all possible ways to insert this data and it seems I missing a syntax not sure exactly where and for which data type? . </p> <pre><code> date = '2016-06-29' region = ...
0
2016-07-04T05:19:40Z
38,177,752
<p>Here no of products has a datatype of int. But, you are using it has a string. For integer, you need to use <strong>%d</strong>. </p> <p>cursor.execute('INSERT INTO iaas.region_based_billing (date, region, account type, product type, total amount, no of products) VALUES <strong>(%s, %s, %s, %s, %f, %d)'</strong>,(d...
0
2016-07-04T05:55:51Z
[ "python", "mysql-workbench", "mysql-python", "mysql-connector" ]
Quickest way to calculate subset of correlation matrix
38,177,464
<p>I'm partial to using pandas builtin <code>corr</code> method for dataframes. However, I am trying to calculate the correlation matrix of a dataframe with 45,000 columns. And then repeat this 250 times. The calculation is crushing my ram (16 GB, mac book pro). I'm grabbing statistics on the columns of the resulti...
1
2016-07-04T05:26:26Z
38,195,754
<p>Using dot products to compute the correlation (as in your example) seems like a good approach. I'll describe two improvements, then code implementing them.</p> <h3>Improvement 1: Pull means out of dot product</h3> <p>We can pull the means out of the dot product, to avoid having to subtract them from every value (s...
2
2016-07-05T05:28:39Z
[ "python", "numpy", "pandas" ]
Trying to implement User Login(Login Manager) with Sqlite3 in Flask
38,177,548
<p>The problem is that once the user logs in, he doesn't stay logged in. I have a condition on the login page to redirect the user if he is logged in but it doesn't seem to work. </p> <p>For instance, after logging in, if a user reloads the login page he is asked to log in again. If I add @login_required to any of my ...
-1
2016-07-04T05:36:15Z
38,178,303
<p>You need to set a cookie (typically) or authorization headers which your app will check to be a valid logged in user.</p> <p>Otherwise, the user's browser has to way to tell your application that it's logged in and there's nothing in your app which is identifying that user as someone who just logged in validly.</p>...
0
2016-07-04T06:41:43Z
[ "python", "python-2.7", "sqlite", "flask", "sqlite3" ]
How does one implement a subsampled RBF (Radial Basis Function) in Numpy?
38,177,549
<p>I was trying to implement a Radial Basis Function in Python and Numpy as describe by <a href="http://work.caltech.edu/slides/slides16.pdf" rel="nofollow">CalTech lecture here</a>. The mathematics seems clear to me so I find it strange that its not working (or it seems to not work). The idea is simple, one chooses a ...
2
2016-07-04T05:36:15Z
38,180,186
<h3>Scaling of interpolating functions</h3> <p>The main problem is unfortunate choice of standard deviation of the functions used for interpolation:</p> <pre><code>stddev = 100 </code></pre> <p>The features of your functions (its humps) are of size about 1. So, use</p> <pre><code>stddev = 1 </code></pre> <h3>Order...
3
2016-07-04T08:36:14Z
[ "python", "numpy", "machine-learning", "neural-network" ]
How do you select a directory or a list of filenames with PyQt4 and pass it to a variable in python
38,177,678
<p>I am an absolute beginner with PyQt but I have fairly conversant with Python and Pygame. I am writing a file utility for Windows and I need to get either a directory path or paths of several selected files into a variable or a list. How is this possible using pyqt? I know how to do it with tk but I have compiling er...
0
2016-07-04T05:48:47Z
38,179,401
<p>I found the shortest way to do this was</p> <pre><code>import sys from PyQt4 import QtGui app = QtGui.QApplication(sys.argv) a = QtGui.QFileDialog.getOpenFileNames() if a: for name in a: print name </code></pre>
1
2016-07-04T07:48:55Z
[ "python", "pyqt4" ]
numpy covariance and covariance matrix by formula is producing different results
38,177,799
<p>I generate a matrix that I want to get the covariance of:</p> <pre><code>test=np.array([4,2,.6,4.2,2.1,.59,3.9,2,.58,4.3,2.1,.62,4.1,2.2,.63]).reshape(5,3) test array([[ 4. , 2. , 0.6 ], [ 4.2 , 2.1 , 0.59], [ 3.9 , 2. , 0.58], [ 4.3 , 2.1 , 0.62], [ 4.1 , 2.2 , 0.63]]) </c...
1
2016-07-04T06:00:44Z
38,178,104
<p>The difference comes from the fact that the <code>np.cov</code> calculates the covariance between row vectors, which is why the result is <code>5*5</code> instead of <code>3*3</code>, but <code>np.mean</code> calculates the average of column vectors and when you do <code>test - mean</code> the calculation is also br...
1
2016-07-04T06:27:31Z
[ "python", "numpy", "matrix", "matrix-multiplication", "covariance" ]
what does this freq mean? pandas pd.date_range('2000-1-1', periods=100, freq="1953U")
38,177,847
<p>I am new to Pandas. Can someone please help me understand what does this freq value mean "1953U". I know that "U" is for micro seconds. What I am not sure is the 1953 number before "U".</p> <pre><code>pd.date_range('2000-1-1', periods=100, freq="1953U") </code></pre> <p>Thanks for your help.</p>
0
2016-07-04T06:04:58Z
38,177,978
<p><code>1953</code> is the multiplier. You can find details in the pandas documentation: </p> <blockquote> <p><strong>freq</strong> : string or DateOffset, default ‘D’ (calendar daily) Frequency strings can have multiples, e.g. ‘5H’</p> </blockquote> <p><a href="http://pandas.pydata.org/pandas-docs/stabl...
0
2016-07-04T06:17:09Z
[ "python", "pandas" ]
what does this freq mean? pandas pd.date_range('2000-1-1', periods=100, freq="1953U")
38,177,847
<p>I am new to Pandas. Can someone please help me understand what does this freq value mean "1953U". I know that "U" is for micro seconds. What I am not sure is the 1953 number before "U".</p> <pre><code>pd.date_range('2000-1-1', periods=100, freq="1953U") </code></pre> <p>Thanks for your help.</p>
0
2016-07-04T06:04:58Z
38,177,995
<p>It means that the frequency is 1953 microseconds. You can have your answer by actually running the command :</p> <pre><code>&gt;&gt;&gt; import pandas as pd &gt;&gt;&gt; pd.date_range('2000-1-1', periods=100, freq="1953U") DatetimeIndex([ '2000-01-01 00:00:00', '2000-01-01 00:00:00.001953', '20...
0
2016-07-04T06:18:46Z
[ "python", "pandas" ]
Contour without float artifacts
38,178,014
<p>I linearly interpolate and after that contour data. For calculations <strong>I use float type because I do not know how many decimals will be in input data</strong>. Sometimes it might be no decimals, sometimes one or over 10.</p> <p>Unfortunately <strong>because of using float after interpolation and contouring of...
2
2016-07-04T06:21:18Z
38,181,259
<p>With your example the <code>zout</code> should be all 10. but actually varies between 9.9999999999999982 and 10.000000000000002, so contour is trying to plot this. You can use numpy rounding to a given precision, </p> <pre><code>zout_ = np.round_(zout, decimals=3) contours = plt.contour(xout, yout, zout_, levels=[1...
2
2016-07-04T09:30:39Z
[ "python", "matplotlib", "scipy", "contour" ]
Regression: Variable influence
38,178,028
<p>Is there any way in SAS , Python to find the most influential variables in rank order apart from correlation ? </p> <p>I might be missing something and any suggestion would be appreciated how to interpret it.</p>
0
2016-07-04T06:22:24Z
38,181,950
<p>In SAS, apart from the correlation (Pearson index) you can use a ranking index like the Spearman coefficient (proc corr). In addition, supposing you have the correct modules (STAT/MINER) licensed you can use:</p> <ul> <li>a linear (logistic) regression on standardized regressors and compare the betas</li> <li>a tre...
0
2016-07-04T10:04:39Z
[ "python", "sas", "regression" ]
How to send immediate GET reponse in tornado?
38,178,044
<p>I have the following code to send result to browser based on the api call.</p> <pre><code>import tornado.ioloop import tornado.web from tornado import gen from datetime import date class GetGameByIdHandler(tornado.web.RequestHandler): @gen.coroutine def get(self, id): response = { 'id': int(id), ...
1
2016-07-04T06:23:17Z
38,180,050
<p>if you need to run some code after writing all data to a socket, you can use <a href="http://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.flush" rel="nofollow"><code>tornado.web.RequestHandler.flush</code></a>:</p> <pre><code> self.write(response) self.flush(callback=lambda: DoSomethingWr...
1
2016-07-04T08:28:24Z
[ "python", "api", "asynchronous", "tornado" ]
Debugging a prisoner's simulation
38,178,381
<p><a href="http://pastie.org/private/uma67ccauc2xhjeravlvna" rel="nofollow">Prisoner's Dilemma</a></p> <p>This program should return 204 and 199, but instead returns 0 and 1000. I can fix the problem by changing the first and second lines of the main method to:</p> <pre><code> FirstStrat = Defector() SecondSt...
0
2016-07-04T06:46:38Z
38,179,686
<p>The problem comes from the way you defined the variables from the class <code>Strategy</code>. By defining them this way:</p> <pre><code>class Strategy(object): turn_number = 1 moves = [] opponent_moves = [] total_points = 0 opponent_points = 0 </code></pre> <p>All those variables will be share...
0
2016-07-04T08:08:28Z
[ "python" ]
Pandas: Get next value in column after string match
38,178,407
<p>How does one get the <em>next value</em> in a column, <em>after</em> a string match?</p> <pre><code>regex = 'ABC' row_match = df["column1"].str.match(regex, case=False) </code></pre> <p>I.e. how to get the value in the next row in the same column, following the one where the string <code>ABC</code> can be found?</...
2
2016-07-04T06:48:38Z
38,178,558
<p>You can try using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.shift.html" rel="nofollow"><code>shift</code></a> to get the next value.</p> <p>Here is a small example :</p> <pre><code>&gt;&gt;&gt; import pandas as pd &gt;&gt;&gt; data = ['a', 'b', 'c', 'd', 'c', 'e'] &gt;&gt;&gt;...
3
2016-07-04T06:56:51Z
[ "python", "pandas" ]
Python27 - on windows 10 how can i tell printing paper size is 50.8mm x 25.4mm?
38,178,454
<p>I have this code on windows which is working with A4 printers. But i have a very small printer, when i print something it does not print anything but only push the ticket out.</p> <p><a href="http://i.stack.imgur.com/QJvcB.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/QJvcB.jpg" alt="enter image descriptio...
1
2016-07-04T06:51:13Z
38,179,252
<p>You should try this:</p> <pre><code>#MM_TEXT= Each logical unit is mapped to one device pixel. Positive x is to the right; positive y is down. OR to draw MM_TWIPS see link hDC.SetMapMode(MM_TEXT) font = win32ui.CreateFont({ "name": "Lucida Console", "height": 10, "weight": 20, }) win32print.DocumentProp...
1
2016-07-04T07:40:11Z
[ "python", "windows", "winapi", "printing" ]