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 |
|---|---|---|---|---|---|---|---|---|---|
Google Appengine: Requests Alternative | 37,567,054 | <p>I have a non-GAE application/request-handler that uses the Python requests module in a to post an uploaded imaged via a POST request, as binary:</p>
<pre><code>headers = {"MyAuth" : "xyz"}
r = requests.post(base_uri, data=open('0.jpg')), headers=headers)
</code></pre>
<p>The user uploads an image, the uploaded ima... | 0 | 2016-06-01T11:14:16Z | 37,586,281 | <p>Although probably not the best solution to this problem, I managed to get requests 2.3.0 to work in the GAE project with:</p>
<pre><code>pip install --target myproject/externals/ requests==2.3.0
</code></pre>
<p>I can now use requests as I would normally.</p>
| 0 | 2016-06-02T08:17:11Z | [
"python",
"google-app-engine",
"python-requests",
"urllib3"
] |
Compare a regex match from two separate files and replace with values from one of them | 37,567,061 | <p>Im not really sure how is the best way to do this... I was thinking I need to do it in python?</p>
<ul>
<li><code>filea.html</code> contains <code>data-tx-text="9817db21ccc2d9acc021c4536690b90a_se"</code></li>
<li><code>fileb.html</code> contains <code>data-tx-text="0850235fcb0e503150c224dad3156312_se"</code></li>
... | 1 | 2016-06-01T11:14:29Z | 37,567,326 | <ul>
<li>open filea find stringa</li>
<li>open fileb find stringb</li>
<li>replace stringa with stringb</li>
<li>replace stringb with stringa</li>
<li>Write files back</li>
</ul>
<p>In code as below</p>
<pre><code>import re
pattern = 'data-tx-text="(.*?)"'
With open('filea.html', 'r') as f:
filea = f.read()
With... | 0 | 2016-06-01T11:26:24Z | [
"python",
"regex",
"sed"
] |
Compare a regex match from two separate files and replace with values from one of them | 37,567,061 | <p>Im not really sure how is the best way to do this... I was thinking I need to do it in python?</p>
<ul>
<li><code>filea.html</code> contains <code>data-tx-text="9817db21ccc2d9acc021c4536690b90a_se"</code></li>
<li><code>fileb.html</code> contains <code>data-tx-text="0850235fcb0e503150c224dad3156312_se"</code></li>
... | 1 | 2016-06-01T11:14:29Z | 37,567,783 | <p>In <code>awk</code>, you could use something like this:</p>
<pre><code>NR == FNR {
match($0, /data-tx-text="[^"]+"/);
if (RSTART > 0) {
data[++a] = substr($0, RSTART + 14, RLENGTH - 15);
}
next;
}
/data-tx-text/ {
sub(/data-tx-text="[^"]+"/, "data-tx-text=\"" data[++b] "\"");
pri... | 0 | 2016-06-01T11:48:47Z | [
"python",
"regex",
"sed"
] |
Compare a regex match from two separate files and replace with values from one of them | 37,567,061 | <p>Im not really sure how is the best way to do this... I was thinking I need to do it in python?</p>
<ul>
<li><code>filea.html</code> contains <code>data-tx-text="9817db21ccc2d9acc021c4536690b90a_se"</code></li>
<li><code>fileb.html</code> contains <code>data-tx-text="0850235fcb0e503150c224dad3156312_se"</code></li>
... | 1 | 2016-06-01T11:14:29Z | 37,568,809 | <p>With GNU awk for the 3rd arg to match():</p>
<pre><code>$ cat tst.awk
match($0,/(.*)(data-tx-text="[^"]+")(.*)/,a) {
if (NR==FNR) {
fileb[++bcnt] = a[2]
}
else {
$0 = a[1] fileb[++acnt] a[3]
}
}
NR>FNR
$ awk -f tst.awk fileb filea
data-tx-text="0850235fcb0e503150c224dad3156312_se... | 0 | 2016-06-01T12:35:51Z | [
"python",
"regex",
"sed"
] |
Compare a regex match from two separate files and replace with values from one of them | 37,567,061 | <p>Im not really sure how is the best way to do this... I was thinking I need to do it in python?</p>
<ul>
<li><code>filea.html</code> contains <code>data-tx-text="9817db21ccc2d9acc021c4536690b90a_se"</code></li>
<li><code>fileb.html</code> contains <code>data-tx-text="0850235fcb0e503150c224dad3156312_se"</code></li>
... | 1 | 2016-06-01T11:14:29Z | 37,583,185 | <p>So this is how I have solved it using python, its a bit manual in that i have to change the names of filea and fileb each time, but it works</p>
<p>I think i can improve the regex with escapes? </p>
<pre><code>import re
import sys
with open('filea.html') as originalFile:
originalFileContents = originalFile.r... | 0 | 2016-06-02T05:15:38Z | [
"python",
"regex",
"sed"
] |
Compare a regex match from two separate files and replace with values from one of them | 37,567,061 | <p>Im not really sure how is the best way to do this... I was thinking I need to do it in python?</p>
<ul>
<li><code>filea.html</code> contains <code>data-tx-text="9817db21ccc2d9acc021c4536690b90a_se"</code></li>
<li><code>fileb.html</code> contains <code>data-tx-text="0850235fcb0e503150c224dad3156312_se"</code></li>
... | 1 | 2016-06-01T11:14:29Z | 37,680,152 | <p>Here's how I'd do it using <a href="https://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a>:</p>
<pre><code>from bs4 import BeautifulSoup as bs
replacements, replaced_html = [], ''
with open('fileb.html') as fileb:
# Extract replacements
soup = bs(fileb, 'html.parser')
tags =... | 0 | 2016-06-07T13:00:58Z | [
"python",
"regex",
"sed"
] |
Tkinter destroy method crashes the program | 37,567,127 | <p>I am trying to make a kind of GUI with tkinter, and here is the code. But, when I run it, click settings, and then back, python crashes. Do you have any idea why this might happen and how I would fix it? It happens when either I run the destroy function, or when I do something in the other Tk window, </p>
<p>The co... | 0 | 2016-06-01T11:16:54Z | 37,575,593 | <p>If your program represents one application, only make one <code>Tk</code> instance.</p>
<p>The <code>Tk</code> object represents the root of the entire application, by deleting it and creating another one you are essentially creating a separate application and any references to the previously application results in... | 1 | 2016-06-01T17:50:50Z | [
"python",
"tkinter"
] |
Receiving None as a result of a function | 37,567,297 | <p>Sorry for the newbie question, but I am trying to create a website in HTML using data from a CSV file, and using python to generate it. One function im trying to use is:</p>
<pre><code>def html_table(heading1, data1):
print("""<table>
<tr>
<th>""" + str(heading1) + "<... | 0 | 2016-06-01T11:24:58Z | 37,567,332 | <p>That's because your function is returning nothing. It is only printing stuff.</p>
<p>You want to <code>return</code> that string not <code>print</code> it:</p>
<pre><code>def html_table(heading1, data1):
return """<table>
<tr>
<th>""" + str(heading1) + "</th><td>"
</cod... | 1 | 2016-06-01T11:26:42Z | [
"python",
"html",
"nonetype"
] |
Django-Haystack elasticsearch config in cloud 9 | 37,567,400 | <p>I'm trying to install <code>django-haystack</code> in my django project which I'm working on in the Cloud 9 online IDE. The documentation for <code>django-haystack</code> says to add this configuration to <code>settings.py</code>:</p>
<pre><code>HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.... | 0 | 2016-06-01T11:29:53Z | 37,575,507 | <p>Cloud9 requires you to run apps on port <code>8080</code>, <code>8081</code>, or <code>8082</code>. </p>
<p>If you use <code>8080</code>, you can access your app from <code>https://myproject-username.c9users.io</code>. If you use the other two ports then you'll access it from <code>https://myproject-username.c9user... | 1 | 2016-06-01T17:45:08Z | [
"python",
"django",
"elasticsearch",
"django-haystack",
"cloud9-ide"
] |
Copy and process images in python | 37,567,405 | <p>I have written the following python code to traverse all the images in a folder(the folder contains only images). I want to obtain each image's negative and save it with a similar name. E.g. If original image is xyz.jpg, I want to save it's negative as xyz-n.jpg. How can I do this?</p>
<pre><code>import os, sys
# ... | 0 | 2016-06-01T11:30:13Z | 37,567,511 | <p>You'll require PIL (<a href="https://github.com/python-pillow/Pillow" rel="nofollow">Pillow</a>). Also, use <code>glob</code> instead of <code>os.listdir()</code>. </p>
<pre><code>from PIL import Image
import PIL.ImageOps
import glob
files = glob.glob('path/*.jpg') # Use *.* if you're sure all are images
for... | 3 | 2016-06-01T11:35:31Z | [
"python",
"image-processing"
] |
Copy and process images in python | 37,567,405 | <p>I have written the following python code to traverse all the images in a folder(the folder contains only images). I want to obtain each image's negative and save it with a similar name. E.g. If original image is xyz.jpg, I want to save it's negative as xyz-n.jpg. How can I do this?</p>
<pre><code>import os, sys
# ... | 0 | 2016-06-01T11:30:13Z | 37,567,523 | <p>I would recommend you to use an image processing library, e.g. scikit-image seems appropriate. The conversion code for a single file is as simple as:</p>
<pre><code>from skimage.io import imread, imsave
image = imread('input.png')
negative = 255 - image
imsave('output.png', negative)
</code></pre>
<p>Wrapping thi... | 2 | 2016-06-01T11:36:11Z | [
"python",
"image-processing"
] |
Copy and process images in python | 37,567,405 | <p>I have written the following python code to traverse all the images in a folder(the folder contains only images). I want to obtain each image's negative and save it with a similar name. E.g. If original image is xyz.jpg, I want to save it's negative as xyz-n.jpg. How can I do this?</p>
<pre><code>import os, sys
# ... | 0 | 2016-06-01T11:30:13Z | 37,567,585 | <p>I wrote this little program before you removed your last post to do exactly what you asked.</p>
<pre><code>def make_negatives(dir, output_dir=False, file_types = ['jpg'], versioning=False):
'''
Create a series of negatives based on a directory
:output_dir is the directory to output the negatives... | 1 | 2016-06-01T11:39:46Z | [
"python",
"image-processing"
] |
Add file to tar archive without saving it first | 37,567,680 | <p>Is there a possibility to create a file directly in a tar archive?<br>
Context: I have a method which creates content of some kind as String. I want to save this content as a file in the tar archive. Do I have to create a tmpfile or is there a possibility to create a file directly in the tar archive. </p>
<pre><c... | 2 | 2016-06-01T11:43:35Z | 37,568,006 | <p>I think you should use StringIO, to create a file like in-memory object, and use tarInfo to describe a fake file, like so :</p>
<pre><code>import StringIO
import tarfile
archive = tarfile.open(tarname, mode='w')
for _ in range(some_number):
content = get_content()
s = StringIO.StringIO()
s.write(conten... | 3 | 2016-06-01T11:58:27Z | [
"python",
"python-3.x",
"tar"
] |
Connecting QPushButon to a method in another class in PyQt | 37,567,703 | <p>I am trying to connect a <code>QPushButton</code> created in class <code>A</code> with a method created in class <code>B</code> . This is my code:</p>
<pre><code>class A(QMainWindow):
def __init__(self):
super(QMainWindow, self).__init__()
#A lot of stuff in here
def Button(self):
self.btn = QPushB... | -1 | 2016-06-01T11:44:49Z | 37,567,872 | <p>Normal.</p>
<p>Look at your code:</p>
<pre><code>def Button(self):
self.btn = QPushButton()
self.connect(self.btn, SIGNAL("clicked()"), B().method_1)
</code></pre>
<p>After self.connect() is called, B objet no longer exists.
Therefore, when you click on your button, the handler B.method_1 does not exist a... | 0 | 2016-06-01T11:52:24Z | [
"python",
"pyqt",
"qpushbutton"
] |
Identifying absorbing classes in a sparse graph | 37,567,777 | <p>My problem is as follows. I have Markov chain with several absorbing classes and I would like to determine which states in the state space are absorbing and which are transient. As a simple example, we could have the following sparse transition matrix, with on each row the transition probabilities of states 0,1,2,3.... | 0 | 2016-06-01T11:48:28Z | 37,570,830 | <p>The following should work, noting that the total probability in an absorbing set of states equals number of states in that set:</p>
<pre><code>components,labels = csgraph.connected_components(P, directed=True, connection='strong',return_labels=True)
absorbingStates = np.zeros(P.shape[0],dtype=bool)
for component in... | 1 | 2016-06-01T13:56:42Z | [
"python",
"numpy",
"scipy",
"markov-chains"
] |
Identifying absorbing classes in a sparse graph | 37,567,777 | <p>My problem is as follows. I have Markov chain with several absorbing classes and I would like to determine which states in the state space are absorbing and which are transient. As a simple example, we could have the following sparse transition matrix, with on each row the transition probabilities of states 0,1,2,3.... | 0 | 2016-06-01T11:48:28Z | 37,626,675 | <p>Solving Markov chain problems where you need to rely on floating point math (<code>np.isclose</code>) indicates your graph representation isn't correct for the problem you're trying to solve.</p>
<p>Below I've presented an alternative solution using networkx (but I assume changing to csgraph wouldn't be hard) that ... | 2 | 2016-06-04T05:23:16Z | [
"python",
"numpy",
"scipy",
"markov-chains"
] |
Python 3.5 Adding to dictionary and assigning a value after | 37,567,837 | <p>So, I'm taking a few courses through Udemy. The final project on the Python 3.x course has you making a simple UI which I did fine. </p>
<p>The premise is a grade tracker for students. You could add grades, remove a student, average the student grades, and exit from the program.</p>
<p>I wanted to do something not... | 0 | 2016-06-01T11:51:02Z | 37,568,037 | <p>You cannot add a key without a value. Also, since you expect a "student" record to be a <code>list</code>, you might as well create it with an empty list:</p>
<pre><code>def addStudent():
nameToAdd = input ('Enter the name of the new student: ')
if nameToAdd in studentDict:
print ('Student already ... | 0 | 2016-06-01T11:59:48Z | [
"python"
] |
Python 3.5 Adding to dictionary and assigning a value after | 37,567,837 | <p>So, I'm taking a few courses through Udemy. The final project on the Python 3.x course has you making a simple UI which I did fine. </p>
<p>The premise is a grade tracker for students. You could add grades, remove a student, average the student grades, and exit from the program.</p>
<p>I wanted to do something not... | 0 | 2016-06-01T11:51:02Z | 37,568,186 | <p>Since you are making a dictionary of students as keys and pointing them to a list might I suggest you take advantage of python's amazing higher order data structures? Specifically the defaultdict? As for your problem if you apply a default dict you can easily handle this problem you are having. As below.</p>
<pre><... | 0 | 2016-06-01T12:06:52Z | [
"python"
] |
Conditional Statements using "cmd python -c" â How can I pass `if`? | 37,567,858 | <p>I have written a batch script that prompts the user for an input and displays the help for a specific library <code>ExternalLibrary</code>. However, I receive the error below the code sample.</p>
<pre><code>@echo off
set input=NUL
set /p input="Help: "
python -c "import sys; sys.path.append('D:\\lib'); import Exte... | 1 | 2016-06-01T11:52:00Z | 37,588,656 | <h1>Only simple statements can be written on single line separated by semicolons</h1>
<p>This was more interesting than it seemed. For the sake of unambiguity you can't write conditional or any other compound statement on semicolon separated single line.</p>
<p><a href="https://docs.python.org/3/reference/simple_stmt... | 1 | 2016-06-02T10:02:04Z | [
"python",
"batch-file",
"cmd"
] |
How to get Html code after javascript has modified it? | 37,567,900 | <p>I want to get the HTML code of a webpage after it has been modified (similar to one that we see in inspect element tab of a browser) and I want to do it programatically (if possible using python or any other programming language). Can someone suggest how I might be able to proceed with this? I know its possible sinc... | 0 | 2016-06-01T11:53:39Z | 37,568,051 | <p>As the server has no access to client window after client-side changes, you have to use client side languages.</p>
<p>In jquery: </p>
<pre><code>var fullCode= "<html>" + $("html").html() + "</html>";
</code></pre>
<p>if you want also to include the Doctype:</p>
<pre><code>var node = document.doctype;... | 1 | 2016-06-01T12:00:20Z | [
"javascript",
"python",
"html",
"dom"
] |
How to get Html code after javascript has modified it? | 37,567,900 | <p>I want to get the HTML code of a webpage after it has been modified (similar to one that we see in inspect element tab of a browser) and I want to do it programatically (if possible using python or any other programming language). Can someone suggest how I might be able to proceed with this? I know its possible sinc... | 0 | 2016-06-01T11:53:39Z | 37,568,209 | <p>Using JQuery you can achieve this by the following code</p>
<pre><code>$(document).ready(function(){
var html = "<html>"+$('html').html()+"</html>";
});
</code></pre>
| 0 | 2016-06-01T12:07:57Z | [
"javascript",
"python",
"html",
"dom"
] |
Get fully qualified name of a Python class (Python 3.3+) | 37,568,128 | <p>How can I get name of class including full path from its module root? For Python 3.3 and up?</p>
<p>Here is example of Python code:</p>
<pre><code>class A:
class B:
class C:
def me(self):
print(self.__module__)
print(type(self).__name__)
print... | 5 | 2016-06-01T12:04:01Z | 37,568,382 | <p>You are looking for <a href="https://docs.python.org/3/library/stdtypes.html#class.__qualname__" rel="nofollow"><code>__qualname__</code></a> (introduced in Python 3.3):</p>
<pre><code>class A:
class B:
class C:
def me(self):
print(self.__module__)
print(type(... | 4 | 2016-06-01T12:15:52Z | [
"python",
"inspect"
] |
Python: test empty set intersection without creation of new set | 37,568,341 | <p>I often find myself wanting to test the intersection of two sets without using the result of the intersections.</p>
<pre><code>set1 = set([1,2])
set2 = set([2,3])
if(set1 & set2):
print("Non-empty intersection")
else:
print("Empty intersection")
</code></pre>
<p>The problem is that a new set is created to ... | 1 | 2016-06-01T12:13:41Z | 37,568,469 | <p>You are looking for <a href="https://docs.python.org/3.4/library/stdtypes.html?highlight=sets#set.isdisjoint" rel="nofollow"><code>set.isdisjoint()</code></a>, as sets are <a href="https://en.wikipedia.org/wiki/Disjoint_sets" rel="nofollow">disjoint</a> if and only if they have an empty intersection. </p>
<pre><cod... | 3 | 2016-06-01T12:19:45Z | [
"python",
"set",
"intersection"
] |
Python: test empty set intersection without creation of new set | 37,568,341 | <p>I often find myself wanting to test the intersection of two sets without using the result of the intersections.</p>
<pre><code>set1 = set([1,2])
set2 = set([2,3])
if(set1 & set2):
print("Non-empty intersection")
else:
print("Empty intersection")
</code></pre>
<p>The problem is that a new set is created to ... | 1 | 2016-06-01T12:13:41Z | 37,568,474 | <p>You can use <a href="https://docs.python.org/3/library/stdtypes.html#set.isdisjoint" rel="nofollow"><code>set.isdisjoint()</code></a> to test wheather two sets have an empty intersection, just negate for the oposite:</p>
<pre><code>set1 = set([1,2])
set2 = set([2,3])
if not set1.sidisjoint(set2):
print("Non-empt... | 0 | 2016-06-01T12:19:57Z | [
"python",
"set",
"intersection"
] |
Optimal SVM parameters for high recall | 37,568,388 | <p>I'm using <code>scikit-learn</code> to perform classification using SVM. I'm performing a binary classification task. </p>
<p><code>0</code>: Does not belong to class A<br>
<code>1</code>: Belongs to class A </p>
<p>Now, I want to optimize the parameters such that I get high recall. I don't care much about a few... | 3 | 2016-06-01T12:16:10Z | 37,570,800 | <p>The choice of the kernel is really dependent on the data, so picking the kernel based on a plot of the data might be the way to go. This could be automated by running through all kernel types and picking the one that gives you either high/low recall or bias, whatever you're looking for. You can see for yourself <a h... | 1 | 2016-06-01T13:55:20Z | [
"python",
"machine-learning",
"scikit-learn",
"svm"
] |
Optimal SVM parameters for high recall | 37,568,388 | <p>I'm using <code>scikit-learn</code> to perform classification using SVM. I'm performing a binary classification task. </p>
<p><code>0</code>: Does not belong to class A<br>
<code>1</code>: Belongs to class A </p>
<p>Now, I want to optimize the parameters such that I get high recall. I don't care much about a few... | 3 | 2016-06-01T12:16:10Z | 37,571,374 | <p>Generally speaking you can tackle this problem by penalizing the two types of errors differently during the learning procedure. If you take a look at the loss function, in particular in the primal/parametric setting, you can think of scaling the penalty of false-negatives by alpha and penalty of false-positives by (... | 0 | 2016-06-01T14:20:31Z | [
"python",
"machine-learning",
"scikit-learn",
"svm"
] |
python: filter a nested list of strings with list comprehension | 37,568,484 | <p>I am trying to use list comprehension to filter this list:</p>
<pre><code>inp = [['Fire 46.0.1', 'vlc 2.2.3','opt 0.9.9.10'],
['opt 0.9.9.11', 'notepad 6.9', 'adobe. 6.9', 'vlc 2.3.3']]
</code></pre>
<p>into</p>
<pre><code>out = [['Fire 46.0.1', 'vlc 2.2.3',],
['notepad 6.9', 'adobe. 6.9', 'vlc 2.3.... | 0 | 2016-06-01T12:20:20Z | 37,568,543 | <p>This should do:</p>
<pre><code>[[s for s in item if not s.startswith('opt')] for item in inp ]
</code></pre>
<p>Use <code>startswith</code> to filter out items with <code>opt</code> from the sublists</p>
| 3 | 2016-06-01T12:22:45Z | [
"python",
"list-comprehension"
] |
python: filter a nested list of strings with list comprehension | 37,568,484 | <p>I am trying to use list comprehension to filter this list:</p>
<pre><code>inp = [['Fire 46.0.1', 'vlc 2.2.3','opt 0.9.9.10'],
['opt 0.9.9.11', 'notepad 6.9', 'adobe. 6.9', 'vlc 2.3.3']]
</code></pre>
<p>into</p>
<pre><code>out = [['Fire 46.0.1', 'vlc 2.2.3',],
['notepad 6.9', 'adobe. 6.9', 'vlc 2.3.... | 0 | 2016-06-01T12:20:20Z | 37,568,563 | <p>You need a nested list comprehension for filtering a nested list.</p>
<pre><code>[[y for y in x if not y.startswith('opt')] for x in inp]
</code></pre>
| 1 | 2016-06-01T12:23:42Z | [
"python",
"list-comprehension"
] |
Failing compiling on windows a simple python script (using py2exe) | 37,568,662 | <p>First of all sorry for my bad English.</p>
<p>I made a script that connects to a Mikortik RB750 and executes commands by SSH.
When I run it (without compiling), it works well and meets the objective.
The problem I'm having is that when I try to compile it on Windows fails. Works fine until it try to run the SSH con... | 0 | 2016-06-01T12:27:47Z | 37,624,658 | <p>When compiling a python program, I tend to use cxfreeze instead of py2exe (use the command <code>pip install CX_Freeze</code> from the windows command prompt), where you can use this code to compile the program:</p>
<p><code>cxfreeze "Path\To\File.py" --target-dir "Path\to\exe\file\"</code></p>
<p><code>Path\To\Fi... | 0 | 2016-06-03T23:05:20Z | [
"python",
"windows",
"py2exe",
"paramiko"
] |
Django Form: "Select a valid choice. That choice is not one of the available choices." | 37,568,684 | <p>I'm working with Python2 and Django 1.9.</p>
<p>Basically I have a form that contains two dropdowns. The second dropdown depends on the value of the first one.</p>
<p>For exampe, if dropdown #1 has the option "Category" selected, then dropdown #2 should display options "CategoryA, CategoryB and CategoryC". In the ... | 2 | 2016-06-01T12:28:56Z | 37,568,858 | <p>One option would be to update the queryset dynamically in the <code>__init__</code> method of the form. Keep the rest of your form class as is, then add this code:</p>
<pre><code>def __init__(self, *args, **kwargs):
super(MyClassForm, self).__init__(*args, **kwargs)
if 'dropdown1' in self.data:
self... | 4 | 2016-06-01T12:37:42Z | [
"python",
"django",
"python-2.7",
"django-forms",
"django-1.9"
] |
Django Form: "Select a valid choice. That choice is not one of the available choices." | 37,568,684 | <p>I'm working with Python2 and Django 1.9.</p>
<p>Basically I have a form that contains two dropdowns. The second dropdown depends on the value of the first one.</p>
<p>For exampe, if dropdown #1 has the option "Category" selected, then dropdown #2 should display options "CategoryA, CategoryB and CategoryC". In the ... | 2 | 2016-06-01T12:28:56Z | 37,582,074 | <p>In the init method</p>
<pre><code> def __init__(self, *arts, **kwargs):
super(MyClassForm, self).__init__(*args, **kwargs)
self.fields['dropdown2'].queryset = Department.objects.none()
if self.is_bound:
self.fields['dropdown2'].queryset = Department.objects.filter(# any value in sel... | 1 | 2016-06-02T03:22:00Z | [
"python",
"django",
"python-2.7",
"django-forms",
"django-1.9"
] |
Set colorbar resized beside each subplots | 37,568,708 | <p>I'm writing my scientific article and I get a problem with my subplots.
Unfortunately, I get a colorbar too much higher than graphs.</p>
<p>I read this post : <a href="http://stackoverflow.com/questions/26034777/matplotlib-same-height-for-colorbar-as-for-plot">Matplotlib: same height for colorbar as for plot</a></p... | 1 | 2016-06-01T12:30:12Z | 37,569,176 | <p>The problem is when you create your 3 <code>divider</code> instances you always use <code>ax1</code>.</p>
<p>Change the second and third <code>dividers</code> to use <code>ax2</code> and <code>ax3</code>, e.g.:</p>
<pre><code>divider = make_axes_locatable(ax2)
</code></pre>
<p>Here's your entire script, with the ... | 1 | 2016-06-01T12:50:06Z | [
"python",
"matplotlib",
"colorbar"
] |
Run code once to create a new file, and use the content in that file remotely? Python | 37,568,757 | <p>I made a program that reads the usr/share/dict/words file and creates key value pairs of words that have the same letters (eg. bkkooorw : ['bookwork', 'workbook'] )</p>
<p>I want to use this dictionary later to find words like<br>
<code>print dictpairs['bkkoorw'] # >>> bookwork workbook</code></p>
<p>This... | 0 | 2016-06-01T12:33:04Z | 37,569,124 | <p>it can be stored in local drive by pickle</p>
<pre><code>import pickle
dictpairs = {'bkkooorw' : ['bookwork', 'workbook']}
#store your dict
with open(fileName, 'wb') as handle:
pickle.dump(dictpairs , handle)
#load your dict
with open(fileName, 'rb') as handle:
dictpairs = pickle.load(handle)
</code></pre>
| 0 | 2016-06-01T12:48:16Z | [
"python",
"dictionary",
"import",
"runtime"
] |
Python: group a list into sublists by a equality of projected value | 37,568,763 | <p>Is there a nice pythonic way of grouping a list into a list of lists where each of the inner lists contain only those elements that have the same projection, defined by the user as a function?</p>
<p>Example:</p>
<pre class="lang-py prettyprint-override"><code>>>> x = [0, 1, 2, 3, 4, 5, 6, 7]
>>>... | 2 | 2016-06-01T12:33:31Z | 37,568,870 | <p>The <code>itertools</code> module in the standard-library contains a <a href="https://docs.python.org/2.7/library/itertools.html#itertools.groupby" rel="nofollow"><code>groupby()</code></a> function that should do what you want.</p>
<p>Note that the input to <code>groupby()</code> should be sorted by the group key ... | 5 | 2016-06-01T12:38:15Z | [
"python",
"grouping"
] |
Python: group a list into sublists by a equality of projected value | 37,568,763 | <p>Is there a nice pythonic way of grouping a list into a list of lists where each of the inner lists contain only those elements that have the same projection, defined by the user as a function?</p>
<p>Example:</p>
<pre class="lang-py prettyprint-override"><code>>>> x = [0, 1, 2, 3, 4, 5, 6, 7]
>>>... | 2 | 2016-06-01T12:33:31Z | 37,569,111 | <p>No need to sort.</p>
<pre><code>from collections import defaultdict
def groupby(iterable, projection):
result = defaultdict(list)
for item in iterable:
result[projection(item)].append(item)
return result
x = [0, 1, 2, 3, 4, 5, 6, 7]
groups = groupby(x, projection=lambda e: e % 3)
print groups
... | 4 | 2016-06-01T12:47:49Z | [
"python",
"grouping"
] |
Python: group a list into sublists by a equality of projected value | 37,568,763 | <p>Is there a nice pythonic way of grouping a list into a list of lists where each of the inner lists contain only those elements that have the same projection, defined by the user as a function?</p>
<p>Example:</p>
<pre class="lang-py prettyprint-override"><code>>>> x = [0, 1, 2, 3, 4, 5, 6, 7]
>>>... | 2 | 2016-06-01T12:33:31Z | 37,569,262 | <p>Here is one approach using <a href="https://docs.python.org/library/itertools.html#itertools.compress" rel="nofollow"><code>compress</code></a> from <code>itertools</code>:</p>
<pre><code>from itertools import compress
import numpy as np
L = [i %3 for i in x]
[list(compress(x, np.array(L)==i)) for i in set(L)]
#[... | 1 | 2016-06-01T12:53:08Z | [
"python",
"grouping"
] |
Python: group a list into sublists by a equality of projected value | 37,568,763 | <p>Is there a nice pythonic way of grouping a list into a list of lists where each of the inner lists contain only those elements that have the same projection, defined by the user as a function?</p>
<p>Example:</p>
<pre class="lang-py prettyprint-override"><code>>>> x = [0, 1, 2, 3, 4, 5, 6, 7]
>>>... | 2 | 2016-06-01T12:33:31Z | 37,569,284 | <p>A <a href="http://pandas.pydata.org/" rel="nofollow">pandas</a> version would be like this:</p>
<pre><code>import pandas as pd
x = [0, 1, 2, 3, 4, 5, 6, 7]
pd.Series(x).groupby(lambda t: t%3).groups
Out[13]: {0: [0, 3, 6], 1: [1, 4, 7], 2: [2, 5]}
</code></pre>
<p>Or</p>
<pre><code>pd.Series(x).groupby(lambda t: ... | 2 | 2016-06-01T12:53:33Z | [
"python",
"grouping"
] |
Sharing URL generation from uuid4? | 37,568,811 | <p>I'm having a bit of a problem figuring out how to generate user friendly links to products for sharing.</p>
<p>I'm currently using <code>/product/{uuid4_of_said_product}</code>
Which is working quite fine - but it's a bit user unfriendly - it's kind of long and ugly.</p>
<p>And I do not wish to use and id as it wo... | 0 | 2016-06-01T12:36:04Z | 37,581,888 | <p>Have you tried these <a href="https://github.com/corpix/shortid" rel="nofollow">https://github.com/corpix/shortid</a> and one for django here <a href="https://github.com/nebstrebor/django-shortuuidfield" rel="nofollow">https://github.com/nebstrebor/django-shortuuidfield</a></p>
| 1 | 2016-06-02T02:57:31Z | [
"python",
"django",
"url",
"sharing"
] |
Sharing URL generation from uuid4? | 37,568,811 | <p>I'm having a bit of a problem figuring out how to generate user friendly links to products for sharing.</p>
<p>I'm currently using <code>/product/{uuid4_of_said_product}</code>
Which is working quite fine - but it's a bit user unfriendly - it's kind of long and ugly.</p>
<p>And I do not wish to use and id as it wo... | 0 | 2016-06-01T12:36:04Z | 37,651,587 | <p>As Seluck suggested I decided to go with base64 encoding and decoding:</p>
<p>In the model my "link" property is now built from the standard url + <code>base64.urlsafe_b64encode(str(media_id))</code></p>
<p>The url pattern I use to match the base64 pattern:</p>
<p><code>base64_pattern = r'(?:[A-Za-z0-9+/]{4})*(?:... | 0 | 2016-06-06T07:17:51Z | [
"python",
"django",
"url",
"sharing"
] |
Indexing a series s2 by a series s1 and keep s1 index | 37,568,830 | <p>I want to construct a series <code>s3</code> from two other series <code>s1</code> and <code>s2</code> as follows:</p>
<pre><code>In [130]: s1
Out[130]:
1 b
2 b
3 c
dtype: object
In [131]: s2
Out[131]:
a x
b y
c z
dtype: object
</code></pre>
<p>I want <code>s3</code> to have the index of <code... | 1 | 2016-06-01T12:36:47Z | 37,568,916 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html" rel="nofollow"><code>map</code></a> <code>Series</code> <code>s1</code> by <code>s2</code>:</p>
<pre><code>import pandas as pd
s1 = pd.Series(['b','b','c'], index=[1,2,3])
s2 = pd.Series(['x','y','z'], index=['a','b','c'])
... | 2 | 2016-06-01T12:40:02Z | [
"python",
"dictionary",
"pandas",
"indexing"
] |
How to fix this indentation error in Python? | 37,568,909 | <p>I have no idea how to fix the indentation error in line 12.</p>
<pre><code>def cube(number):
number=n
cube(n)=n**3
return cube(n)
def by_three(number):
number=n
if n%3==0:
cube(number)
return cube(number)
else:
return False
</code></pre>
| -2 | 2016-06-01T12:39:53Z | 37,569,014 | <pre><code>if n%3==0:
cube(number)
return cube(number)
else:
return False
</code></pre>
| 0 | 2016-06-01T12:43:30Z | [
"python"
] |
How to fix this indentation error in Python? | 37,568,909 | <p>I have no idea how to fix the indentation error in line 12.</p>
<pre><code>def cube(number):
number=n
cube(n)=n**3
return cube(n)
def by_three(number):
number=n
if n%3==0:
cube(number)
return cube(number)
else:
return False
</code></pre>
| -2 | 2016-06-01T12:39:53Z | 37,569,338 | <p>More than indentation let me fix your code.</p>
<ul>
<li>you don't need number=n, you can directly use number instead of n.
The more the number of lines in python, the overhead will increase.</li>
<li>You can not do this cube(n)=n**3, assignment to function. It's illegal.</li>
</ul>
<blockquote>
<pre><code>def cub... | 1 | 2016-06-01T12:55:31Z | [
"python"
] |
Python 3 putpixel (PIL) object to string and reverse | 37,568,938 | <p>I use PIL to read the pixel map of an image and I then store the map on a Postgre database VARCHAR column as a string. I would like to read that database VARCHAR string again from my Python script and transform it to the same pixel map object I get when I use <code>pix=im.load()</code>, so that I can then parse like... | 0 | 2016-06-01T12:40:36Z | 37,614,949 | <p>I worked out my code by converting the mapping into String and <code>.remove()</code> all chars that are not the byte octets. When I store this string to the VARCHAR column I can then get it back, strip again everything but the octets and then use the string with the index[] to parse the octets.</p>
| 1 | 2016-06-03T12:54:04Z | [
"python",
"postgresql",
"object",
"python-imaging-library"
] |
Python34 multithreading and passing a variable | 37,568,955 | <p>So I've never been really good with multithreading and today I'm bumping into a problem I've been trying to dodge for quite some time.</p>
<p>I want to pass a variable to a function that I execute in multiple threads but I have no clue how to do that in a functional manner.</p>
<p>Here is what I made : </p>
<pre>... | 1 | 2016-06-01T12:41:26Z | 37,569,182 | <p>You should read more about the <code>Classes</code> in python.</p>
<p>You forgot to define the <code>payload</code> parameter in the constructor of your <code>Thread</code> implementation.
It's just simple as this:</p>
<pre><code>class myThread (threading.Thread):
def __init__(self, payload): # you have to de... | 1 | 2016-06-01T12:50:16Z | [
"python",
"multithreading",
"python-3.x"
] |
Python34 multithreading and passing a variable | 37,568,955 | <p>So I've never been really good with multithreading and today I'm bumping into a problem I've been trying to dodge for quite some time.</p>
<p>I want to pass a variable to a function that I execute in multiple threads but I have no clue how to do that in a functional manner.</p>
<p>Here is what I made : </p>
<pre>... | 1 | 2016-06-01T12:41:26Z | 37,569,416 | <p>TryToSolveItSimple's answer is correct, but it's worth noting that this is a very common pattern for which there is already a primitive:</p>
<pre><code>from multiprocessing.pool import ThreadPool
from contextlib import closing
def Checker(a):
print(a)
threads = 4
with closing(ThreadPool(threads)) as pool:
... | 1 | 2016-06-01T12:58:40Z | [
"python",
"multithreading",
"python-3.x"
] |
tensorflow cifar10_eval.py error:RuntimeError: Attempted to use a closed Session.RuntimeError: Attempted to use a closed Session | 37,568,980 | <p>I'm running the cifar10 network on my PC and after finishing the training and running eval script the following error appears:</p>
<pre><code>2016-06-01 14:37:14.238317: precision @ 1 = 0.000
Traceback (most recent call last):
File "<ipython-input-1-adf2ca85bb77>", line 1, in <module>
runfile('/h... | 1 | 2016-06-01T12:42:21Z | 37,624,604 | <p>Looking at <a href="https://github.com/JianKangtum/tensorflow_cifar10_test/blob/119fde74c459a55dbacf898ebf9db62407317730/cifar10_eval_test.py" rel="nofollow">the code you posted</a>, the problem is between lines 50 and 51 in <code>eval_once()</code>:</p>
<pre><code>with tf.Session() as sess:
ckpt = tf.train.get... | 0 | 2016-06-03T22:59:22Z | [
"python",
"tensorflow",
"deep-learning"
] |
Limit decimals numbers when writing to csv in python | 37,569,057 | <p>I loop over files and for each of these files, I compute a list of 4000+ (fixed number) features on it. These features are computed by a function and returned as <code>numpy.array</code></p>
<p>I want to write a CSV file with one line per file (each line is one <code>numpy.array</code>with 4000+ elements).</p>
<p>... | 0 | 2016-06-01T12:45:38Z | 37,569,240 | <p>You can use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.savetxt.html#numpy.savetxt" rel="nofollow" title="`numpy.savetxt()`"><code>numpy.savetxt()</code></a> like this:</p>
<pre><code>import numpy as np
with open('output.csv', 'w') as fh:
for i in range(10): # loop over features... | 3 | 2016-06-01T12:52:12Z | [
"python",
"arrays",
"csv",
"numpy",
"decimal"
] |
Python Matplotlib nonlinear scaling in contour plot | 37,569,214 | <p>I'm having some trouble visualizing a certain dataset that I have in a contour plot. The issue is that I have a bunch of datapoints (X,Y,Z) for which the Z values range from about 2 to 0, where a lot of the interesting features are located in the 0 to 0.3 range. Using a normal scaling, they are very difficult to see... | 3 | 2016-06-01T12:51:08Z | 37,590,118 | <p>Excellent question.</p>
<p>Don't scale the data. You'll be looking for compromises in ranges with many scaling functions. </p>
<p>Instead, use a <a href="http://matplotlib.org/examples/pylab_examples/custom_cmap.html" rel="nofollow">custom colormap</a>. That way, you won't have to remap your actual data and can ea... | 1 | 2016-06-02T11:07:25Z | [
"python",
"matplotlib",
"scaling",
"contour"
] |
Unable to get hidden layer activation of ANN | 37,569,280 | <p>I am using python2 and i'm trying to get the activations of hidden layer. I am using the following code which is giving me an error:</p>
<pre><code>get_activations = theano.function([my_model.layers[0].input], my_model.layers[0].get_output(train=False),
allow_input_downcast=True)
</cod... | 1 | 2016-06-01T12:53:26Z | 37,588,729 | <p>attribute <code>get_output</code> is only defined for old versions of keras (0.3). It no longer exists in version 1.0.</p>
<p><a href="http://keras.io/getting-started/faq/#how-can-i-visualize-the-output-of-an-intermediate-layer" rel="nofollow">see new syntax (keras doc FAQ)</a></p>
<p>something like </p>
<pre><co... | 1 | 2016-06-02T10:05:11Z | [
"python",
"theano",
"keras"
] |
Reading text file and drawing grain structure using value available in file | 37,569,294 | <p>I am working in abaqus to create crystal grains geomtries and assemble by using availble co-ordinates present in text file. I am new to python so please someone help me to read this file and assign values.</p>
<p>You can find the file with this link <a href="https://drive.google.com/open?id=0B_hkeWVV98L4MTVCNHMydXl... | -1 | 2016-06-01T12:53:59Z | 38,036,967 | <p>You could make the text into multiple text columns
To read any text with the following code and use it in a list.</p>
<pre><code>id1=open('text1.txt','r')
data1=[]
a=id1.readline()
for i in range (100):
data1.append(float(a))
a=id1.readline()
id1.close()
</code></pre>
| 0 | 2016-06-26T09:17:20Z | [
"python",
"structure",
"abaqus"
] |
QWEB - IndexError: list index out of range | 37,569,444 | <p>I'm trying to create a QWeb report. I have a list of product and I would like to print each etiquette on the same page. This is my code :</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Déclaration des rapports -->
<report
... | 2 | 2016-06-01T13:00:01Z | 37,610,767 | <p>The issue is related to the fact that the report engine expects to have 1 header and footer for each page. You are creating N pages for 1 header+footer.</p>
<p>The call <code><t t-call="report.external_layout"></code> must be put inside the for loop. If you need more than one item in the same page do not use ... | 3 | 2016-06-03T09:31:21Z | [
"python",
"openerp",
"odoo-8",
"qweb"
] |
How to read and write table with extra information as a dataframe and adding new columns from the informations | 37,569,461 | <p>I have a file-like object generated from StringIO which is a table with lines of information ahead the table (see below starting from #TIMESTAMP). </p>
<p>I want to add extra columns to the exisiting table using the information "Date", "UTCoffset - Time (Substraction)" from #Timestamp and "ZenAngle" from #GLOBAL_SU... | -1 | 2016-06-01T13:00:30Z | 37,569,771 | <p>I think you can first use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow"><code>read_csv</code></a> to create 3 <code>DataFrames</code>:</p>
<pre><code>import pandas as pd
import io
temp=u"""#TIMESTAMP
UTCOffset,Date,Time
+00:30:32,2011-09-05,08:32:21
#GLOBAL_SU... | 0 | 2016-06-01T13:13:10Z | [
"python",
"pandas",
"dataframe"
] |
How can I get new results from randint while in a loop? | 37,569,676 | <p>My code thus far:</p>
<pre><code>from random import randint
Dice1 = randint(1,6)
Dice2 = randint(1,6)
Dice3 = randint(1,6)
DiceRoll2 = Dice1 + Dice2
DiceRoll3 = Dice1 + Dice2 + Dice3
class Item(object):
def __init__(self, name, value, desc):
self.name = name
self.value = value
self.de... | 0 | 2016-06-01T13:09:56Z | 37,570,059 | <p>Put your dice-rolling into a separate function and calculate <code>Damage</code> and <code>NewHealth</code> inside your loop. (Also, update your Monster's health. :))</p>
<pre><code>from random import randint
def dice_roll(times):
sum = 0
for i in range(times):
sum += randint(1, 6)
return sum
class Item... | 1 | 2016-06-01T13:25:18Z | [
"python",
"python-3.x",
"while-loop"
] |
How can I get new results from randint while in a loop? | 37,569,676 | <p>My code thus far:</p>
<pre><code>from random import randint
Dice1 = randint(1,6)
Dice2 = randint(1,6)
Dice3 = randint(1,6)
DiceRoll2 = Dice1 + Dice2
DiceRoll3 = Dice1 + Dice2 + Dice3
class Item(object):
def __init__(self, name, value, desc):
self.name = name
self.value = value
self.de... | 0 | 2016-06-01T13:09:56Z | 37,570,241 | <p>You need to make the call to randint everytime. Below is one way to do it</p>
<pre><code>def Dice1(): return randint(1,6)
def Dice2(): return randint(1,6)
def Dice3(): return randint(1,6)
</code></pre>
<p>This isn't great though because of all the repeated code. Here is a better way</p>
<pre><code>class Dice(o... | 1 | 2016-06-01T13:32:32Z | [
"python",
"python-3.x",
"while-loop"
] |
Handling ajax json object in Django - 'QueryDict' object has no attribute 'read' error | 37,569,716 | <p>I am trying to parse json object in my Django view which has been passed through from client by ajax via post method.</p>
<p>JS:</p>
<p><code>$.post ('/update_vendor_merchandise_types/', JSON.stringify(json_obj))</code>; </p>
<p>View:</p>
<pre><code>def update_vendor_merchandise_types(request):
print json_... | 0 | 2016-06-01T13:11:25Z | 37,570,142 | <p><code>request.POST</code> is for form-encoded content. For JSON, you should access the plain body directly:</p>
<pre><code>json_object = json.loads(request.body)
</code></pre>
| 2 | 2016-06-01T13:28:13Z | [
"jquery",
"python",
"json",
"ajax",
"django"
] |
Handling ajax json object in Django - 'QueryDict' object has no attribute 'read' error | 37,569,716 | <p>I am trying to parse json object in my Django view which has been passed through from client by ajax via post method.</p>
<p>JS:</p>
<p><code>$.post ('/update_vendor_merchandise_types/', JSON.stringify(json_obj))</code>; </p>
<p>View:</p>
<pre><code>def update_vendor_merchandise_types(request):
print json_... | 0 | 2016-06-01T13:11:25Z | 37,570,244 | <p>Why do you convert json_obj into string when sending it to server? I think you should do it in this way:</p>
<pre><code>json_obj = {"key1": "value1", "key2": "value2"}
$.post('/update_vendor_merchandise_types/', json_obj)
</code></pre>
<p>In this case on the server side you can access sent data in this way:</p>
... | 3 | 2016-06-01T13:32:41Z | [
"jquery",
"python",
"json",
"ajax",
"django"
] |
How can one use a class method in a class attribute definition | 37,569,798 | <p>All is in the title. I'd like to create a class method and a class attribute, both constructed only once, when the class is created, using the first in the second's definition.</p>
<p>With my best try, I just get a <code>TypeError: 'classmethod' object is not callable</code>.</p>
<p>Here is my code :</p>
<pre><co... | 2 | 2016-06-01T13:14:40Z | 37,569,964 | <p><code>@classmethod</code>s are implemented as a special object that gets processed using <a href="https://docs.python.org/3/howto/descriptor.html" rel="nofollow">the descriptor protocol</a> when looked up on the class; inside the definition, as a raw name (unqualified), it's a special <code>classmethod</code> object... | 3 | 2016-06-01T13:21:27Z | [
"python",
"python-2.7",
"python-2.x"
] |
How can one use a class method in a class attribute definition | 37,569,798 | <p>All is in the title. I'd like to create a class method and a class attribute, both constructed only once, when the class is created, using the first in the second's definition.</p>
<p>With my best try, I just get a <code>TypeError: 'classmethod' object is not callable</code>.</p>
<p>Here is my code :</p>
<pre><co... | 2 | 2016-06-01T13:14:40Z | 37,570,661 | <p>You real problem is that you try to use <code>bar</code> before the class if fully constructed, so you do not get the expected object.</p>
<p>Here is a simplified example:</p>
<pre><code>class Foo:
@classmethod
def bar(cls, x):
print ('bar called in', cls, 'with', x)
barv = str(bar)
print(str(... | 1 | 2016-06-01T13:49:10Z | [
"python",
"python-2.7",
"python-2.x"
] |
How can one use a class method in a class attribute definition | 37,569,798 | <p>All is in the title. I'd like to create a class method and a class attribute, both constructed only once, when the class is created, using the first in the second's definition.</p>
<p>With my best try, I just get a <code>TypeError: 'classmethod' object is not callable</code>.</p>
<p>Here is my code :</p>
<pre><co... | 2 | 2016-06-01T13:14:40Z | 37,570,908 | <p>Your confusion to why this is not an easy work around is understandable, let me elaborate on to why using <code>classmethod</code> in this way isn't going to work...</p>
<p>The way <code>classmethod</code> works is that it creates a descriptor, an object that implements <code>__get__</code> when it is retrieved as ... | 2 | 2016-06-01T14:00:11Z | [
"python",
"python-2.7",
"python-2.x"
] |
Is it possible to completely monkey-patch a class from a library in Python? | 37,569,879 | <p>I'm trying to add some very fundamental functionality to a library (namely scikit-learn). However, I'd prefer to not directly modify the library itself, as a) even in my own testing, I'd rather have the ability to turn the functionality on and off and b) this is very possibly functionality that does not belong in th... | 1 | 2016-06-01T13:17:43Z | 37,575,034 | <p>The problem is that <code>BaseEstimator</code> doesn't define an <code>__init__</code> method, so its children don't call <code>super.__init__</code>. If you monkey patch <code>BaseEnsemble</code> however, you will see the effects. Replacing the class is not very effective as other classes have already subclassed th... | 1 | 2016-06-01T17:16:35Z | [
"python",
"scikit-learn"
] |
Setting values with pandas.DataFrame | 37,569,881 | <p>Having this DataFrame:</p>
<pre><code>import pandas
dates = pandas.date_range('2016-01-01', periods=5, freq='H')
s = pandas.Series([0, 1, 2, 3, 4], index=dates)
df = pandas.DataFrame([(1, 2, s, 8)], columns=['a', 'b', 'foo', 'bar'])
df.set_index(['a', 'b'], inplace=True)
df
</code></pre>
<p><a href="http://i.sta... | 9 | 2016-06-01T13:17:50Z | 37,571,923 | <p>This should work:</p>
<pre><code>df.iat[0, df.columns.get_loc('foo')] = df['foo'][0].resample('D').sum().dropna()
</code></pre>
<p>Pandas is complaining about chained indexing but when you don't do it that way it's facing problems assigning whole series to a cell. With <a href="http://pandas.pydata.org/pandas-docs... | 3 | 2016-06-01T14:44:10Z | [
"python",
"pandas"
] |
Setting values with pandas.DataFrame | 37,569,881 | <p>Having this DataFrame:</p>
<pre><code>import pandas
dates = pandas.date_range('2016-01-01', periods=5, freq='H')
s = pandas.Series([0, 1, 2, 3, 4], index=dates)
df = pandas.DataFrame([(1, 2, s, 8)], columns=['a', 'b', 'foo', 'bar'])
df.set_index(['a', 'b'], inplace=True)
df
</code></pre>
<p><a href="http://i.sta... | 9 | 2016-06-01T13:17:50Z | 37,739,816 | <h1>Hierarchical data in pandas</h1>
<p>It really seems like you should consider restructure your data to take advantage of pandas features such as <a href="http://pandas.pydata.org/pandas-docs/stable/advanced.html" rel="nofollow"><code>MultiIndexing</code></a> and <a href="http://pandas.pydata.org/pandas-docs/stable/... | 0 | 2016-06-10T04:18:15Z | [
"python",
"pandas"
] |
Setting values with pandas.DataFrame | 37,569,881 | <p>Having this DataFrame:</p>
<pre><code>import pandas
dates = pandas.date_range('2016-01-01', periods=5, freq='H')
s = pandas.Series([0, 1, 2, 3, 4], index=dates)
df = pandas.DataFrame([(1, 2, s, 8)], columns=['a', 'b', 'foo', 'bar'])
df.set_index(['a', 'b'], inplace=True)
df
</code></pre>
<p><a href="http://i.sta... | 9 | 2016-06-01T13:17:50Z | 37,747,046 | <p>Simply set <code>df.is_copy = False</code> before asignment of new value.</p>
| 0 | 2016-06-10T11:25:25Z | [
"python",
"pandas"
] |
Display detail page for model using django-mptt-urls | 37,569,895 | <p>Im trying to access the detailpage of a photo instance, but I can't seem to get it to work. (The category detail page works great!)</p>
<p>I would like to access <code>http//domain.com/main-category/sub-cat/sub-sub-cat/photo-slug/</code></p>
<p>Models.py:</p>
<pre><code>from mptt.models import MPTTModel, TreeFore... | 1 | 2016-06-01T13:18:09Z | 37,570,915 | <p>The reason why it doesn't work is that MPTT only works on <strong>one model at a time</strong>, in that case the gallery, not the photo.</p>
<p>So actually, in your models the Gallery is <strong>NOT</strong> the parent of the photo, but just a foreign key on the photo.</p>
<p>If you know that the last element of t... | 1 | 2016-06-01T14:00:33Z | [
"python",
"django",
"django-mptt"
] |
Python: how to draw a normal line to a 2D curve? | 37,570,006 | <p>I have the x,y coordinates of a curve</p>
<p>x = [x1, x2, ..., xn]</p>
<p>y = [y1, y2, ..., yn]</p>
<p>I want to draw a normal line which passes [xk, yk], where xk, yk is coordinate of the k-th point on my curve.</p>
<p>How to realize it in Python?</p>
| -1 | 2016-06-01T13:23:04Z | 37,570,839 | <p><a href="http://matplotlib.org/" rel="nofollow">Matplotlib</a> is the most common library for plotting in python.</p>
<p>A small example to get you started:</p>
<pre><code>import matplotlib.pyplot as plt
x = [1,2,3,4]
y = [5,6,9,13]
plt.plot(x,y)
plt.show()
</code></pre>
| 0 | 2016-06-01T13:57:18Z | [
"python"
] |
Python: how to draw a normal line to a 2D curve? | 37,570,006 | <p>I have the x,y coordinates of a curve</p>
<p>x = [x1, x2, ..., xn]</p>
<p>y = [y1, y2, ..., yn]</p>
<p>I want to draw a normal line which passes [xk, yk], where xk, yk is coordinate of the k-th point on my curve.</p>
<p>How to realize it in Python?</p>
| -1 | 2016-06-01T13:23:04Z | 37,601,875 | <p>Thank you all. I've solved the problem.</p>
<p>First I do a spline, then calculated the differential function and find the tangent slope k using the given point [xk, yk]. The slope of the normal like is -1/k. In the end, the normal line is plotted.</p>
| 0 | 2016-06-02T20:50:23Z | [
"python"
] |
replace text in form python dictionary | 37,570,064 | <pre><code>state_dict = {'Alabama' :'AL' ,'Montana': 'MT', 'Alaska' :'AK', 'Nebraska': 'NE', 'Arizona': 'AZ', 'Nevada': 'NV', 'Arkansas': 'AR', 'New Hampshire': 'NH', 'California': 'CA', 'New Jersey': 'NJ', 'Colorado': 'CO', 'New Mexico': 'NM', 'Connecticut': 'CT', 'New York': 'NY', 'Delawa... | 1 | 2016-06-01T13:25:28Z | 37,570,137 | <p>You're on the right track. Simply loop over the dictionary and make replacements using the <code>replace</code> method. A convenient way to loop over the dictionary in this case is to use the <code>.items()</code> method, which returns <code>(key, value)</code> tuples that you can break apart to give better names to... | 1 | 2016-06-01T13:27:53Z | [
"python",
"dictionary"
] |
replace text in form python dictionary | 37,570,064 | <pre><code>state_dict = {'Alabama' :'AL' ,'Montana': 'MT', 'Alaska' :'AK', 'Nebraska': 'NE', 'Arizona': 'AZ', 'Nevada': 'NV', 'Arkansas': 'AR', 'New Hampshire': 'NH', 'California': 'CA', 'New Jersey': 'NJ', 'Colorado': 'CO', 'New Mexico': 'NM', 'Connecticut': 'CT', 'New York': 'NY', 'Delawa... | 1 | 2016-06-01T13:25:28Z | 37,570,293 | <p>You can try this:</p>
<pre><code>state_dict = {'Alabama' :'AL' ,'Montana': 'MT', 'Alaska' :'AK', 'Nebraska': 'NE', 'Arizona': 'AZ', 'Nevada': 'NV', 'Arkansas': 'AR', 'New Hampshire': 'NH', 'California': 'CA', 'New Jersey': 'NJ', 'Colorado': 'CO', 'New Mexico': 'NM', 'Connecticut': 'CT', ... | 0 | 2016-06-01T13:34:24Z | [
"python",
"dictionary"
] |
How to use raw_input with regular expressions? | 37,570,161 | <p>with <code>raw_input()</code> I need to enter '\t' to split one string. '\t' is regular expression. When provided through <code>raw_input()</code> python transforms <code>\t</code> to <code>'\\t'</code>, so I cannot split the string.</p>
<pre><code>line = '01/09/2015\t02:00\t0\t0\t0\t0\t0\t0\t1150592'
INPUT_separa... | 2 | 2016-06-01T13:29:05Z | 37,570,713 | <p><code>\t</code> is not interpreted as a tab by <code>raw_input()</code> hence decoding it would be necessary. But <code>re</code> treats the literal <code>\t</code> as a tab. Hence you can also use <code>re</code> for this.</p>
<pre><code>import re
line = '01/09/2015 02:00 0 0 0 0 0 ... | 1 | 2016-06-01T13:51:29Z | [
"python",
"regex",
"python-2.7"
] |
How to use raw_input with regular expressions? | 37,570,161 | <p>with <code>raw_input()</code> I need to enter '\t' to split one string. '\t' is regular expression. When provided through <code>raw_input()</code> python transforms <code>\t</code> to <code>'\\t'</code>, so I cannot split the string.</p>
<pre><code>line = '01/09/2015\t02:00\t0\t0\t0\t0\t0\t0\t1150592'
INPUT_separa... | 2 | 2016-06-01T13:29:05Z | 37,571,437 | <p>If you want to use the input <code>\t</code> as a literal tab, you have to decode the escaped string input.</p>
<pre><code>INPUT_separator = raw_input('Separating character = ').decode('string_escape')
</code></pre>
| 0 | 2016-06-01T14:23:00Z | [
"python",
"regex",
"python-2.7"
] |
Concatenating lines to a string in python | 37,570,238 | <p>I have a fasta file as follows:</p>
<pre><code>>scaf1
AAAAAATGTGTGTGTGTGTGYAA
AAAAACACGTGTGTGTG
>scaf2
ACGTGTGTGTGATGTGGY
AAAAAATGTGNNNNNNNNYACGTGTGTGTGTGTGTACACWSK
>scaf3
AAAGTGTGTTGTGAAACACACYAAW
</code></pre>
<p>I want to read it into a dictionary in a away that multiple lines belonging to one sequence... | 1 | 2016-06-01T13:32:27Z | 37,570,654 | <p>Concatenating strings with <code>+</code> requires to create a new string since Python strings are immutable, which is time consumer. </p>
<p>Use <a href="https://docs.python.org/2/library/stdtypes.html#str.join" rel="nofollow"><strong><code>str.join</code></strong></a> to concatenate them after all strings are rea... | 5 | 2016-06-01T13:48:50Z | [
"python",
"string-concatenation"
] |
Deleting a line in multiple files in python | 37,570,300 | <p>i am a beginner in python and i am practicing at the moment.</p>
<p>So what i want to do is a script that finds a line that i am writing with raw_input and that will search this line in multiple files and delete it.
Something like this but for more files:</p>
<pre><code>word = raw_input("word: ")
f = open("file.tx... | -2 | 2016-06-01T13:34:38Z | 37,570,684 | <p>something like this should work:</p>
<pre><code>source = '/some/dir/path/'
for root, dirs, filenames in os.walk(source):
for f in filenames:
this_file = open(os.path.join(source, f), "r")
this_files_data = this_file.readlines()
this_file.close()
# rewrite the file with all line e... | 0 | 2016-06-01T13:50:27Z | [
"python",
"python-2.7",
"delete-row"
] |
Deleting a line in multiple files in python | 37,570,300 | <p>i am a beginner in python and i am practicing at the moment.</p>
<p>So what i want to do is a script that finds a line that i am writing with raw_input and that will search this line in multiple files and delete it.
Something like this but for more files:</p>
<pre><code>word = raw_input("word: ")
f = open("file.tx... | -2 | 2016-06-01T13:34:38Z | 37,571,382 | <p>Instead of reading the entire file into memory, you should iterate through the file and write the lines that are OK to a temporary file. Once you've gone through the entire file, delete it and rename the temporary file to the name of the original file. This is a classic pattern that you'll most likely frequently enc... | 0 | 2016-06-01T14:20:41Z | [
"python",
"python-2.7",
"delete-row"
] |
Animate GMapPlot w/ Python/Bokeh | 37,570,330 | <p>I'm a very nooby programmer and this is my first Stack Overflow question. :)</p>
<p>So I'm trying to animate a car's trip on google maps using Python. I used matplotlib at first and could get a dot animated over the path line... then I tried using bokeh and successfully got the path to overlay on google maps...</p... | 2 | 2016-06-01T13:36:13Z | 37,829,533 | <p>This may not be exactly what you are looking for, but you could have a slider widget that controls the position of your car dot. The slider example found in the bokeh docs (or github repository, I can't remember) helped me when I started using sliders. </p>
<p>Just so you are aware, I was having problems with latln... | 0 | 2016-06-15T08:04:49Z | [
"python",
"google-maps",
"animation",
"coordinates",
"bokeh"
] |
variables not changing when I add an integer | 37,570,425 | <p>I made this code, and when you pick a blueberry, your blueberries stay at one, and I dont know why. I want the user to acquire multiple blueberries, but it seems to stay at one.</p>
<pre><code>def blueberryfound(blueberries):
print(" .-~~~~-.")
print(" / ( ( ' \ ")
print(" | ( ) ) ... | -1 | 2016-06-01T13:39:44Z | 37,570,501 | <p><code>integer</code> variables are immutable, this means</p>
<pre><code>def blueberryfound(val):
val = val + 1
blueberries = 1
blueberryfound(blueberries)
</code></pre>
<p>does not work. Only <code>val</code> inside the function will be incremented, the outside variable <code>blueberries</code> will not be ch... | 0 | 2016-06-01T13:43:18Z | [
"python",
"python-3.x",
"variables"
] |
How can we control the sequence of function execution in Python Nose test | 37,570,427 | <p>In a scenario of Nose tests in python</p>
<pre><code>class test_class(testcase):
def test_a(self):
print 'test1'
def test_b(self):
print 'test2'
def test_c(self):
print 'test3'
</code></pre>
<p>when i execute the nosetest, the sequence of execution keep changing.
Could some one please ad... | 0 | 2016-06-01T13:39:50Z | 37,570,496 | <p>That is by design. Nose will run the tests in random order each time and makes no guarantees of the order they will run in. You can provide a <code>setup</code> method that will run before all tests in that class, and a <code>teardown</code> method that will run after all tests in that class. </p>
<p>The idea is to... | 2 | 2016-06-01T13:42:57Z | [
"python",
"unit-testing",
"nose"
] |
PYTHON Making global variable accessible from every process | 37,570,564 | <p>I am new to python and started using an genetic algorithm (GA) to do some sort of curve fitting. For that GA I am using the (awesome) pyevolve library
(<a href="http://pyevolve.sourceforge.net/" rel="nofollow">http://pyevolve.sourceforge.net/</a>) that is able to reduce the calculation time enormously by using mult... | 7 | 2016-06-01T13:45:26Z | 37,647,432 | <p>Check out <a href="https://docs.python.org/2/library/mmap.html" rel="nofollow">mmap</a>, the Python interface for creating memory mapped files that can be shared between processes. You probably want something like the following:</p>
<pre><code>import mmap
import os
import ctypes
mm = mmap.mmap(-1, 13)
mm.write('He... | 0 | 2016-06-05T22:30:40Z | [
"python",
"multiprocessing",
"global",
"pyevolve"
] |
PYTHON Making global variable accessible from every process | 37,570,564 | <p>I am new to python and started using an genetic algorithm (GA) to do some sort of curve fitting. For that GA I am using the (awesome) pyevolve library
(<a href="http://pyevolve.sourceforge.net/" rel="nofollow">http://pyevolve.sourceforge.net/</a>) that is able to reduce the calculation time enormously by using mult... | 7 | 2016-06-01T13:45:26Z | 38,326,222 | <p>I just wanted to let you know how I solved this problem if anyone else is facing it:</p>
<p>My solution does not apply to the general python related problem but it helps when using pyevolve, which was enough in my case. What I didn't know was, that in pyevolve you can add parameters to your genomes or your genetic ... | 0 | 2016-07-12T10:27:07Z | [
"python",
"multiprocessing",
"global",
"pyevolve"
] |
Python / PyCharm: How to document :rtype: for function that returns multiple possible data types? | 37,570,679 | <p>In PyCharm how should one document the :rtype: for functions that return multiple possible data types? For example, if a function can return defaultdict OR dict OR list, based on the functions parameters, how do you document this?</p>
<p>Code example:</p>
<pre><code>from collections import defaultdict
def read_st... | 1 | 2016-06-01T13:50:07Z | 37,572,172 | <p>I think I just found out myself by stumbling over a similar question: <a href="http://stackoverflow.com/q/33945261/5931892">How to specify multiple return types using type-hints</a></p>
<p>:rtype: can be</p>
<pre><code>:rtype: Union[collections.defaultdict, dict, list]
</code></pre>
| 2 | 2016-06-01T14:53:46Z | [
"python",
"pycharm",
"return-type",
"docstring"
] |
Python / PyCharm: How to document :rtype: for function that returns multiple possible data types? | 37,570,679 | <p>In PyCharm how should one document the :rtype: for functions that return multiple possible data types? For example, if a function can return defaultdict OR dict OR list, based on the functions parameters, how do you document this?</p>
<p>Code example:</p>
<pre><code>from collections import defaultdict
def read_st... | 1 | 2016-06-01T13:50:07Z | 37,726,638 | <p>You can use 'or' explicitly in the rtype</p>
<pre><code>:rtype: collections.defaultdict or dict or list
</code></pre>
<p>variant</p>
<pre><code>:rtype: collections.defaultdict | dict | list
</code></pre>
| 2 | 2016-06-09T12:56:14Z | [
"python",
"pycharm",
"return-type",
"docstring"
] |
Hbase timeout errors keep occuring | 37,570,762 | <p>I'm accessing Hbase using <code>happybase</code> with python.</p>
<p>I've a very simple function:</p>
<pre><code>def connect():
connection = happybase.Connection('myhost',myport)
table = connection.table('MY-TABLE')
try:
return str(table.row('my-row'))
except Exception as ioe:
retu... | 0 | 2016-06-01T13:53:33Z | 37,573,333 | <p>Increase the time-out by setting the property in <code>hbase-site.xml</code> which will be available in <code>hbase/conf</code> </p>
<pre><code><property>
<name>hbase.regionserver.lease.period</name>
<value>900000</value> <!-- 900 000, 15 minutes -->
</property>
... | 0 | 2016-06-01T15:47:02Z | [
"python",
"hadoop",
"timeout",
"hbase",
"happybase"
] |
How can I extract City, Region, Country from a URL? Django | 37,570,768 | <p>My Django app currently serves 7 hard-coded cities and would like to make serve all world cities saved not as one word like "Budapest" but as three levels like "New York, New York, USA".</p>
<p>My Google-powered search field returns results like this:</p>
<pre><code>http://localhost:8000/search/?city=New+York%2C+N... | 0 | 2016-06-01T13:53:47Z | 37,571,145 | <p>You can use <a href="https://docs.python.org/3/library/urllib.parse.html" rel="nofollow"><code>urlparse</code></a> for something like this:</p>
<pre><code>from urllib.parse import urlparse, parse_qs
u = urlparse('http://localhost:8000/search/?city=New+York%2C+NY%2C+United+States')
q = parse_qs(u.query)
city = q['c... | 2 | 2016-06-01T14:10:26Z | [
"python",
"django",
"django-models"
] |
How can I extract City, Region, Country from a URL? Django | 37,570,768 | <p>My Django app currently serves 7 hard-coded cities and would like to make serve all world cities saved not as one word like "Budapest" but as three levels like "New York, New York, USA".</p>
<p>My Google-powered search field returns results like this:</p>
<pre><code>http://localhost:8000/search/?city=New+York%2C+N... | 0 | 2016-06-01T13:53:47Z | 37,571,614 | <p>It's better to extract these components from a well-structured source of data such as the Google Geocoding Service, so you can reliably tell which part of the data maps to an administrative division.
If you take the example from <a href="https://developers.google.com/maps/documentation/javascript/examples/geocoding-... | 0 | 2016-06-01T14:31:00Z | [
"python",
"django",
"django-models"
] |
Manipulating a numpy array | 37,570,790 | <p>I currently have a csv file with approximately 350 lines and 50 columns, of which I want to access four columns. Using <code>genfromtxt</code>, I'm able to do this. Once I have those columns, however, I want to add a new column based off of the existing columns (i.e. <code>newcol=abs(col1-col2)</code>). When I do th... | 2 | 2016-06-01T13:54:59Z | 37,571,725 | <p>I think the reason your code does not work is that numpy.genfromtxt returns a 1D array of tupples or more specifically structured ndarray. read this <a href="http://stackoverflow.com/questions/9534408/numpy-genfromtxt-produces-array-of-what-looks-like-tuples-not-a-2d-array-why">numpy.genfromtxt produces array of wha... | 2 | 2016-06-01T14:35:53Z | [
"python",
"numpy",
"genfromtxt"
] |
How to write pseudo parameters in troposphere? | 37,570,888 | <p>I want to use the pseudo parameter for a TopicConfigurations topics. So that I can allow the selection of a arn. How can I write a pseudo parameter using troposphere? </p>
<p>Topic Configuration: <a href="http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-notificationconfig-topic... | 0 | 2016-06-01T13:59:18Z | 37,572,885 | <p>I think this should be it, from troposphere/<strong>init</strong>.py:</p>
<pre><code>Ref(AWS_NOTIFICATION_ARNS))
</code></pre>
| 0 | 2016-06-01T15:25:42Z | [
"python",
"amazon-web-services",
"troposphere"
] |
How to write pseudo parameters in troposphere? | 37,570,888 | <p>I want to use the pseudo parameter for a TopicConfigurations topics. So that I can allow the selection of a arn. How can I write a pseudo parameter using troposphere? </p>
<p>Topic Configuration: <a href="http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-notificationconfig-topic... | 0 | 2016-06-01T13:59:18Z | 37,579,233 | <p>You would just use the name of the parameter, in a Ref() call, like so:</p>
<pre><code>Ref("AWS::NotificationARNs")
</code></pre>
<p>I use that all the time, mostly with "AWS::NoValue" or "AWS::Region" in most of my use cases.</p>
<p>Good luck!</p>
| 0 | 2016-06-01T21:38:01Z | [
"python",
"amazon-web-services",
"troposphere"
] |
unify python script keeping specific parts | 37,570,913 | <p>I want to unify two slightly different scripts.</p>
<p>My idea was to keep the common part in a file (<em>modX.py</em>) and create two other files to gives two different entry points (<em>A.py</em> and <em>B.py</em>). The common part will be called through an 'import'.</p>
<pre><code>from modX import *
</code></pr... | 0 | 2016-06-01T14:00:28Z | 37,572,338 | <p>The reason that it is not work is because <strong>modX.globals()</strong> is different object the <strong>A.globals()</strong></p>
<p>You do it like that:
In modX.py :</p>
<pre><code>def foo():
if 'is_A' in globals():
return "spam"
else:
return "eggs"
</code></pre>
<p>A.py :</p>
<pre><cod... | 0 | 2016-06-01T15:00:49Z | [
"python",
"module"
] |
unify python script keeping specific parts | 37,570,913 | <p>I want to unify two slightly different scripts.</p>
<p>My idea was to keep the common part in a file (<em>modX.py</em>) and create two other files to gives two different entry points (<em>A.py</em> and <em>B.py</em>). The common part will be called through an 'import'.</p>
<pre><code>from modX import *
</code></pr... | 0 | 2016-06-01T14:00:28Z | 37,573,371 | <p>I've never figured out a way to pass arguments to a module on import â although it would be very useful. However there are ways to work around the limitation which make use of the fact that modules objects are cached in the <code>sys.modules</code> dictionary when they're first imported <strong><em>and</em></stron... | 1 | 2016-06-01T15:48:41Z | [
"python",
"module"
] |
TensorFlow stuck into endless loop using tf.while_loop() | 37,571,017 | <h3>Steps to reproduce</h3>
<p>I am using TensorFlow to implement a network that needs to use <code>tf.while_loop()</code></p>
<pre><code>import tensorflow as tf
import numpy as np
class model(object):
def __init__(self):
self.argmax_ep_gate_array = [ tf.placeholder(tf.int32, [None]) for _ in range(10)]
... | 2 | 2016-06-01T14:04:31Z | 37,573,208 | <p><strong>TL;DR:</strong> You cannot store tensors that were created in the loop body for later use, because that breaks some assumptions about how the loop is structured.</p>
<p>In general, the <code>condition()</code> and <code>body()</code> functions must not have side effects.
Indeed, it is unlikely that your pro... | 2 | 2016-06-01T15:41:52Z | [
"python",
"tensorflow"
] |
How can I make my neural network emphasize that some data is more important than the rest? | 37,571,165 | <p>I looked around online but couldn't find anything, but I may well have missed a piece of literature on this. I am running a basic neural net on a 289 component vector to produce a 285 component vector. In my input, the last 4 pieces of data are critical to change the rest of the input into the resultant 285 for th... | 4 | 2016-06-01T14:11:05Z | 37,571,417 | <p>The neural network should more or less learn this thing by itself. Especially with newer approaches like deep learning & friends, where the amount of hand-tuning is almost zero. However, this does assume that the function which you're trying to learn is learnable and that the system you use has enough power to l... | 2 | 2016-06-01T14:22:12Z | [
"python",
"neural-network",
"tensorflow",
"data-science"
] |
How can I make my neural network emphasize that some data is more important than the rest? | 37,571,165 | <p>I looked around online but couldn't find anything, but I may well have missed a piece of literature on this. I am running a basic neural net on a 289 component vector to produce a 285 component vector. In my input, the last 4 pieces of data are critical to change the rest of the input into the resultant 285 for th... | 4 | 2016-06-01T14:11:05Z | 37,571,456 | <p>I don't think you have any reason doing this since the network will infer that on its own. The weights will be reduced or enhanced for each input according to their importance considering the output.</p>
<p>What you could do though, is to have a preliminary network that is going to have the 285 component as an inpu... | 2 | 2016-06-01T14:23:47Z | [
"python",
"neural-network",
"tensorflow",
"data-science"
] |
How can I make my neural network emphasize that some data is more important than the rest? | 37,571,165 | <p>I looked around online but couldn't find anything, but I may well have missed a piece of literature on this. I am running a basic neural net on a 289 component vector to produce a 285 component vector. In my input, the last 4 pieces of data are critical to change the rest of the input into the resultant 285 for th... | 4 | 2016-06-01T14:11:05Z | 37,574,806 | <h1>To emphasize on any vector elements in your input vector you will have to give less information of the unimportant vector to your neural network.</h1>
<p>Try to encode the first less important 285 numbers into one number or any vector size you like, with a a multiplayer neural network then use that number with oth... | 0 | 2016-06-01T17:04:16Z | [
"python",
"neural-network",
"tensorflow",
"data-science"
] |
How can I make my neural network emphasize that some data is more important than the rest? | 37,571,165 | <p>I looked around online but couldn't find anything, but I may well have missed a piece of literature on this. I am running a basic neural net on a 289 component vector to produce a 285 component vector. In my input, the last 4 pieces of data are critical to change the rest of the input into the resultant 285 for th... | 4 | 2016-06-01T14:11:05Z | 37,575,990 | <p>Theoretically, you can let the network try to learn this relationship. However, there are good reasons to try to rethink the way you're formulating the problem. Also, the difficulty a neural network will have learning this function is going to depend strongly on your specific problem (and the best way to figure it o... | 1 | 2016-06-01T18:14:52Z | [
"python",
"neural-network",
"tensorflow",
"data-science"
] |
hosting python telegram bot on heroku | 37,571,375 | <p>I have a <code>.py</code> file with some code to run a <code>telegram bot</code> and it works fine on my local machine but when i push my code into <code>heroku</code> it doesn't work, i mean the file is not running to receive and send messages but when i enter the bash in <code>heroku</code> and run the <code>.py</... | 1 | 2016-06-01T14:20:32Z | 37,970,694 | <p>Maybe you have to put into <code>Procfile</code> such a string:</p>
<pre><code>web: python web.py
</code></pre>
<p>Where <code>web.py</code> is the name of your script.</p>
<p>Also check <code>requirements.txt</code> file with all dependencies included. Look at this article <a href="https://devcenter.heroku.com/a... | 1 | 2016-06-22T14:14:52Z | [
"python",
"heroku",
"telegram-bot"
] |
Iterate through aws workspaces using python boto3 | 37,571,397 | <p>I am trying to print all the aws workspaces available in a specfic region</p>
<p>I have tried using the code :</p>
<pre><code>import boto3
client = boto3.client('workspaces')
counter = client.describe_workspaces
print counter()
</code></pre>
<p>but "print counter()" is print a lot of values which I am not sure ... | 0 | 2016-06-01T14:21:22Z | 37,574,420 | <p><code>WorkspaceID</code> is part of the response, all you need to do is iterate through the list returned. <a href="http://boto3.readthedocs.io/en/latest/reference/services/workspaces.html#WorkSpaces.Client.describe_workspaces" rel="nofollow">docs</a></p>
| 0 | 2016-06-01T16:44:22Z | [
"python",
"amazon-web-services",
"boto3"
] |
Locating & Clicking button (Selenium) | 37,571,457 | <p>I'm trying to click the link in Selenium (Python 2.7). This is the HTML Code:</p>
<pre><code><div class="buttons">
<a href="https://twitter.com/login?redirect_after_login=%2Flogout" class="btn cancel">Cancel</a>
<button type="submit" class="btn primary-btn js-submit">Log out&... | 1 | 2016-06-01T14:23:53Z | 37,571,578 | <p><em>The "by link text" locator would only work with links - <code>a</code> elements</em>. Here you can use an XPath to check the text of the button:</p>
<pre><code>driver.find_element_by_xpath("//button[. = 'Log out']").click()
</code></pre>
<hr>
<p>As a side note, in this code:</p>
<blockquote>
<p><code>elem ... | 0 | 2016-06-01T14:29:15Z | [
"python",
"selenium"
] |
Increase download speed of requests | 37,571,466 | <p>I'm writing a script that download some videos from dropbox. Usually my downloading speed is around 150 kb/sec, this when using normal downloader on firefox or IDM. But while using this Python script, things get too slow: less than 10 kb / sec.</p>
<p>Here's the code I'm using : </p>
<pre><code>def download(url,i... | 1 | 2016-06-01T14:24:05Z | 37,577,059 | <p>I believe that 1000000mb is to large of a value to load at one time. You can't do anything with chunk while all that data is buffering into memory. I would reduce the size to 512mb or 1gb if the file size is smaller than 512mb then the chunk size should be smaller than that, otherwise you're not really loading chu... | 0 | 2016-06-01T19:18:08Z | [
"python",
"python-requests"
] |
Replace line in C file, python | 37,571,472 | <p>I have a C file which contains these lines two lines:</p>
<pre><code>(*Something_something_XXXName_1()) = 3.54324E+7;
(*Something_something_XXXName_2()) = 7.13123E+7;
</code></pre>
<p>When I run my script (will present it later) I want to replace it with new values, for example:</p>
<pre><code>(*Something_somethi... | 0 | 2016-06-01T14:24:29Z | 37,572,177 | <p><strong>Using sed</strong></p>
<pre><code>sed s/'(*Something_something_XXXName_1())'/'(*Something_something_XXXName_1())=1.53493E+7;\/\/'/g file.c >new_file.c
</code></pre>
<p>OR</p>
<pre><code>#define NEW_VAL 1.53493E+7
sed s/'(*Something_something_XXXName_1())'/'(*Something_something_XXXName_1())=NEW_VALUE;... | 0 | 2016-06-01T14:54:06Z | [
"python",
"regex"
] |
Replace line in C file, python | 37,571,472 | <p>I have a C file which contains these lines two lines:</p>
<pre><code>(*Something_something_XXXName_1()) = 3.54324E+7;
(*Something_something_XXXName_2()) = 7.13123E+7;
</code></pre>
<p>When I run my script (will present it later) I want to replace it with new values, for example:</p>
<pre><code>(*Something_somethi... | 0 | 2016-06-01T14:24:29Z | 37,572,430 | <p>Something is wrong with your regular expression.
In the first argument you have <code>Something_something_XXXName_{0}</code>, but this will not match <code>Something_something_XXXName_1</code>. Instead it should be something like <code>Something_something_XXXName_\d</code> or <code>Something_something_XXXName_(\d+)<... | 0 | 2016-06-01T15:05:34Z | [
"python",
"regex"
] |
Matlab range in Python | 37,571,622 | <p>I must translate some Matlab code into Python 3 and I often come across ranges of the form start:step:stop. When these arguments are all integers, I easily translate this command with np.arange(), but when some of the arguments are floats, especially the step parameter, I don't get the same output in Python. For exa... | 3 | 2016-06-01T14:31:28Z | 37,571,844 | <p>You don't actually need to add your entire step size to the max limit of <code>np.arange</code> but just a very tiny number to make sure that that max is enclose. For example the <a href="http://stackoverflow.com/a/19141711/1011724">machine epsilon</a>:</p>
<pre><code>eps = np.finfo(np.float32).eps
</code></pre>
<... | 7 | 2016-06-01T14:40:35Z | [
"python",
"matlab",
"numpy",
"range"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.