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 |
|---|---|---|---|---|---|---|---|---|---|
Python and Matplotlib: Plot multiple graphs on the same figure fast | 37,787,432 | <p>Is there a faster way of plotting multiple curves over the same x range than the following?</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
N = 100 # trajectories
p = 1e3 # points
x = np.linspace(0, 2*np.pi, p)
y = [np.sin(x)**i for i in range(N)]
color = iter(plt.cm.rainbow(np.linspace(0, 1, ... | 0 | 2016-06-13T10:31:52Z | 37,789,520 | <p>I doubt whether you will find a significantly faster solution. You could try to remove the loop around <code>plot</code> with something like:</p>
<pre><code>N = 200
x = np.linspace(0, 2*np.pi, 1e5)
y = np.array([np.sin(x)**i for i in range(N)])
plt.plot(x, y.transpose()) # I left out the colors for now..
</code></... | 2 | 2016-06-13T12:10:23Z | [
"python",
"matplotlib"
] |
How to make sudo execute in current python virtual environment? | 37,787,435 | <p>I have a django website setup and configured in a python virtual environment (venv) on Ubuntu and all is working fine. Now in order to to run my server on port80 I need to use "sudo" which does not execute in the context of the virtual environment, raising errors (i.e no module named django ...)</p>
<p>Is there a w... | 0 | 2016-06-13T10:32:06Z | 37,787,526 | <p>No, you don't need to do this. You shouldn't be trying to run the development server on port 80; if you're setting up a production environment, use a proper server.</p>
| 3 | 2016-06-13T10:36:02Z | [
"python",
"django",
"sudo",
"port80"
] |
How to make sudo execute in current python virtual environment? | 37,787,435 | <p>I have a django website setup and configured in a python virtual environment (venv) on Ubuntu and all is working fine. Now in order to to run my server on port80 I need to use "sudo" which does not execute in the context of the virtual environment, raising errors (i.e no module named django ...)</p>
<p>Is there a w... | 0 | 2016-06-13T10:32:06Z | 37,787,596 | <p><a href="http://stackoverflow.com/a/9527553">This should be the solution.</a>
Even tho I really don't recomment doing this. If you need sudo within Python you are probably on a wrong way.</p>
| -1 | 2016-06-13T10:39:26Z | [
"python",
"django",
"sudo",
"port80"
] |
How to make sudo execute in current python virtual environment? | 37,787,435 | <p>I have a django website setup and configured in a python virtual environment (venv) on Ubuntu and all is working fine. Now in order to to run my server on port80 I need to use "sudo" which does not execute in the context of the virtual environment, raising errors (i.e no module named django ...)</p>
<p>Is there a w... | 0 | 2016-06-13T10:32:06Z | 37,788,226 | <p>this did the trick:</p>
<pre><code>$ sudo -- sh -c './venv-bin-path/activate; gunicorn <params> -b 0.0.0.0:80'
</code></pre>
| -1 | 2016-06-13T11:08:44Z | [
"python",
"django",
"sudo",
"port80"
] |
How to make sudo execute in current python virtual environment? | 37,787,435 | <p>I have a django website setup and configured in a python virtual environment (venv) on Ubuntu and all is working fine. Now in order to to run my server on port80 I need to use "sudo" which does not execute in the context of the virtual environment, raising errors (i.e no module named django ...)</p>
<p>Is there a w... | 0 | 2016-06-13T10:32:06Z | 37,789,743 | <p>As @DanielRoseman said you should not be using the Django development server in production.</p>
<p>But if you need to run the development server on port 80 you have to reference the use the virtual environment python executable directly.</p>
<pre><code>sudo ../bin/python manage.py runserver localhost:80
</code></p... | 1 | 2016-06-13T12:21:21Z | [
"python",
"django",
"sudo",
"port80"
] |
Selenium Python: How to wait for a page to load after a click? | 37,787,453 | <p>I want to grab the page source of the page after I make a click. And then go back using browser.back() function. But Selenium doesn't let the page fully load after the click and the content which is generated by JavaScript isn't being included in the page source of that page.</p>
<pre><code>element[i].click()
#Need... | 0 | 2016-06-13T10:32:59Z | 37,787,765 | <p>As Alan mentioned - you can wait for some element to be loaded. Below is an example code</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
browser = webdriver.Firefox()
element = WebDriverWait(bro... | 1 | 2016-06-13T10:47:17Z | [
"python",
"selenium"
] |
Starting iterate from specific column | 37,787,471 | <p>This is my .xslx file:</p>
<p><a href="http://i.stack.imgur.com/YcWQU.png" rel="nofollow">data.xlsx</a></p>
<pre><code>from openpyxl import load_workbook
workbook = load_workbook('/path/', read_only=True)
first_sheet = workbook.sheetnames()[0]
worksheet = workbook[first_sheet]
for row in worksheet:
for cell ... | 0 | 2016-06-13T10:33:42Z | 37,789,314 | <p>You can use <a href="http://openpyxl.readthedocs.io/en/2.3.3/tutorial.html" rel="nofollow"><code>iter_rows</code></a>, either by specifying the offset or the range</p>
<pre><code>for row in worksheet.iter_rows('A4:B9'):
for cell in row:
print(cell.value)
</code></pre>
<p>Btw: <code>sheetnames()[0]</cod... | 0 | 2016-06-13T12:00:15Z | [
"python",
"openpyxl"
] |
Sending hexadecimal commands to serial port of relay board using bytearray in python 2.7 | 37,787,507 | <p>I need to send to send hexadecimal commands to serial port of a relay board.</p>
<p>I previously used commands like:</p>
<pre><code>relay.write(bytearray([0xFF]))
</code></pre>
<p>This worked,
but if I want to use a variable like</p>
<pre><code>m = 255
</code></pre>
<p>and</p>
<pre><code>relay.write(bytea... | 1 | 2016-06-13T10:35:02Z | 37,788,085 | <p>In your first snippet, <code>[0xff]</code> is a list containing the integer 255 written in hexadecimal form. You could have written <code>[255]</code> instead of <code>[0xff]</code>, they compile to identical bytecode. So to replace that integer by a variable <code>m</code> you can do </p>
<pre><code>m = 255
relay.... | 1 | 2016-06-13T11:01:53Z | [
"python",
"bytearray"
] |
Different color for line depending on corresponding values in Pyplot | 37,787,632 | <p>I want to show parts of a line chart in different colors depending on the values of a corresponding boolean array (in this case <code>annotation</code>). So far i've tried this:</p>
<pre><code>plt.figure(4)
plt.title("Signal with annotated data")
plt.plot(resampledTime, modulusOfZeroNormalized, 'r-', )
walkIndex = ... | 1 | 2016-06-13T10:41:02Z | 37,788,057 | <p>I solved it using the following code, but i think it quite a 'rough' solution </p>
<pre><code>plt.figure(4)
plt.title("Signal with annotated data")
walkIndex = annotation == True
positive = modulusOfZeroNormalized.copy()
negative = modulusOfZeroNormalized.copy()
positive[walkIndex] = np.nan
negative[~walkIndex] =... | 1 | 2016-06-13T11:00:33Z | [
"python",
"matplotlib"
] |
Different color for line depending on corresponding values in Pyplot | 37,787,632 | <p>I want to show parts of a line chart in different colors depending on the values of a corresponding boolean array (in this case <code>annotation</code>). So far i've tried this:</p>
<pre><code>plt.figure(4)
plt.title("Signal with annotated data")
plt.plot(resampledTime, modulusOfZeroNormalized, 'r-', )
walkIndex = ... | 1 | 2016-06-13T10:41:02Z | 37,790,834 | <p>The following is a valid solution for your problem:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
# construct some data
n = 30
x = np.arange(n+1) # resampledTime
y = np.random.randn(n+1) # modulusOfZeroNormalized
annotation = [True... | 1 | 2016-06-13T13:15:33Z | [
"python",
"matplotlib"
] |
Replace value after Nth delimiter | 37,787,644 | <p>Original string looks like this:</p>
<pre><code>a,b,c,d,e
</code></pre>
<p>How can I replace the comma separated value that comes after the Nth comma?</p>
<p>So for example how can i replace the value that comes after 3rd comma with <code>x</code> to create a following string? </p>
<p><code>a,b,c,x,e</code></p>
| 0 | 2016-06-13T10:41:36Z | 37,787,814 | <p>Yes It is possible</p>
<p><code>def replaceNthComma(data, indexOfComma, newVal):
_list = list(data)
_list[indexOfComma*2] = newVal
return ''.join(_list)</code></p>
<p>Which will return the exact ouput as you expect.</p>
<p><code>ouput: replaceNthComma("a,b,c,x,e", 3, 'x') ==> 'a,b,c,x,e'</code></p>... | 0 | 2016-06-13T10:49:30Z | [
"python",
"string",
"python-3.x"
] |
Replace value after Nth delimiter | 37,787,644 | <p>Original string looks like this:</p>
<pre><code>a,b,c,d,e
</code></pre>
<p>How can I replace the comma separated value that comes after the Nth comma?</p>
<p>So for example how can i replace the value that comes after 3rd comma with <code>x</code> to create a following string? </p>
<p><code>a,b,c,x,e</code></p>
| 0 | 2016-06-13T10:41:36Z | 37,787,822 | <pre><code>mystr = 'a,b,c,d,e'
mystr = mystr.split(',')
mystr[3] = 'x'
mystr = ','.join(mystr)
print mystr
</code></pre>
| 1 | 2016-06-13T10:49:49Z | [
"python",
"string",
"python-3.x"
] |
Replace value after Nth delimiter | 37,787,644 | <p>Original string looks like this:</p>
<pre><code>a,b,c,d,e
</code></pre>
<p>How can I replace the comma separated value that comes after the Nth comma?</p>
<p>So for example how can i replace the value that comes after 3rd comma with <code>x</code> to create a following string? </p>
<p><code>a,b,c,x,e</code></p>
| 0 | 2016-06-13T10:41:36Z | 37,787,881 | <p>It depends how you want to do it, there are several ways, e.g.:</p>
<p>using split</p>
<pre><code>list = "a,b,c,d,e".split(",")
list[3] = "x"
print ",".join(list)
</code></pre>
<p>using regex</p>
<pre><code>import re
print re.sub(r"^((?:[^,]+,){3})([^,]+)(.*)$", "\\1x\\3", "a,b,c,d,e")
</code></pre>
<p>in the r... | 1 | 2016-06-13T10:52:21Z | [
"python",
"string",
"python-3.x"
] |
Replace value after Nth delimiter | 37,787,644 | <p>Original string looks like this:</p>
<pre><code>a,b,c,d,e
</code></pre>
<p>How can I replace the comma separated value that comes after the Nth comma?</p>
<p>So for example how can i replace the value that comes after 3rd comma with <code>x</code> to create a following string? </p>
<p><code>a,b,c,x,e</code></p>
| 0 | 2016-06-13T10:41:36Z | 37,788,214 | <p>The code I am posting here should be self-explanatory, if not, feel free to ask for explanations with a comment.</p>
<pre><code>s = 'a,b,c,d,e'
n = 3
to_replace_with = 'x'
l = s.split(',')
l[n] = to_replace_with
result = ','.join(l)
>>>print(result)
'a,b,c,x,e'
</code></pre>
| 0 | 2016-06-13T11:08:12Z | [
"python",
"string",
"python-3.x"
] |
Draw image grid in python | 37,787,661 | <p>i have this exercise in school, make a function that draws a grid in an existing image. draw_grid(img, s, c)
img - image
s - spacing of lines
c - color</p>
<pre><code> def draw_grid(img, s, c):
a = s
b = s
for i in range(len(img)):
for j in range(len(img[0])):
... | 0 | 2016-06-13T10:42:46Z | 37,789,359 | <p>I think your problem is with <code>if img[i].index(j) == b:</code>, index return the index of the first occurrence of its argument in the list, but j should already be an index, and not an element that you're looking for in your image.</p>
<p>Your loops seems too complicated, you don't need a, b or any 'if', if you... | 0 | 2016-06-13T12:02:20Z | [
"python",
"grid"
] |
Autocomplete blender script using jedi-vim | 37,787,679 | <p>I recently added jedi-vim to my plug-in arsenal. It works just fine for the standard modules, but is unable to find bpy and bmesh stuff.</p>
<p>So in the blender console I took the output of <code>print(sys.path)</code> and added it to a vimscript function in a <code>.lvimrc</code> file, like this:</p>
<pre><code>... | 0 | 2016-06-13T10:43:41Z | 37,795,615 | <p>I just realized that there's not a lot of hope, because you're already talking to a compiled (C/C++) module.</p>
<p>If <code>dir(bpy.context)</code> (in a Python shell) doesn't give you the completions that you want, Jedi will also not be able to infer this information. If <code>dir</code> gives you something reaso... | 1 | 2016-06-13T17:18:07Z | [
"python",
"vim",
"blender",
"jedi-vim"
] |
Autocomplete blender script using jedi-vim | 37,787,679 | <p>I recently added jedi-vim to my plug-in arsenal. It works just fine for the standard modules, but is unable to find bpy and bmesh stuff.</p>
<p>So in the blender console I took the output of <code>print(sys.path)</code> and added it to a vimscript function in a <code>.lvimrc</code> file, like this:</p>
<pre><code>... | 0 | 2016-06-13T10:43:41Z | 37,809,087 | <p>This often catches people out. Blender's <code>bpy</code> module is a compiled module created from source code within blender. The binary for the module is merged into blender's binary and is not made available outside of the python interpreter within blender.</p>
<p>It is possible to compile blender yourself and e... | 1 | 2016-06-14T10:11:40Z | [
"python",
"vim",
"blender",
"jedi-vim"
] |
Extracting phrase n-grams from a sentence corresponding to the main verb | 37,787,708 | <p>I am working on a project which needs me to extract similarity between sentences. So given a sentence, I need the phrase n-gram of that sentence, which is 'a combination of the main verb and the noun phrase left and right of the verb'. Any idea how to extract this? I am given the dependency and constituency parse tr... | 0 | 2016-06-13T10:44:22Z | 37,796,247 | <p>Have you tried <a href="http://nlp.stanford.edu/software/openie.html" rel="nofollow">Stanford OpenIE</a>? Or, for that matter, any OpenIE system (<a href="https://knowitall.github.io/ollie/" rel="nofollow">Ollie</a> / ReVerb / etc.).</p>
<p><strong>Minimal usage (via <a href="http://stanfordnlp.github.io/CoreNLP/si... | 0 | 2016-06-13T17:56:15Z | [
"python",
"graph",
"nlp",
"stanford-nlp"
] |
UnboundLocalError: local variable "tries" referenced before assignment | 37,787,794 | <p>I'm very new to programming and throwing myself in the deep end.
Trying to write a simple number guessing game, still very rough, but I'm getting an error I'm not sure how to fix.</p>
<p>This is the code:</p>
<p>import random
guessestaken= 0
print "You've got to guess a random number between 1 and 20"</p>
... | 0 | 2016-06-13T10:48:24Z | 37,787,866 | <p>You cannot check an undefined variable for <code>None</code>:</p>
<pre><code>def main():
while True:
if tries is None:
tries = 0
tries = tries + 1
</code></pre>
<p>instead you should define it beforehand</p>
<pre><code>def main():
tries = 0
while True:
tries = trie... | 0 | 2016-06-13T10:51:47Z | [
"python"
] |
UnboundLocalError: local variable "tries" referenced before assignment | 37,787,794 | <p>I'm very new to programming and throwing myself in the deep end.
Trying to write a simple number guessing game, still very rough, but I'm getting an error I'm not sure how to fix.</p>
<p>This is the code:</p>
<p>import random
guessestaken= 0
print "You've got to guess a random number between 1 and 20"</p>
... | 0 | 2016-06-13T10:48:24Z | 37,787,899 | <p>With the following statement:</p>
<pre><code>if tries is None:
tries = 0
tries = tries + 1
</code></pre>
<p>you are checking the value of a variable that doesn't exist. You can fix that by adding a value to <code>tries</code> at the beginning of the function, thus creating it. For example: <code>tries = 0<... | 0 | 2016-06-13T10:53:01Z | [
"python"
] |
UnboundLocalError: local variable "tries" referenced before assignment | 37,787,794 | <p>I'm very new to programming and throwing myself in the deep end.
Trying to write a simple number guessing game, still very rough, but I'm getting an error I'm not sure how to fix.</p>
<p>This is the code:</p>
<p>import random
guessestaken= 0
print "You've got to guess a random number between 1 and 20"</p>
... | 0 | 2016-06-13T10:48:24Z | 37,805,239 | <p>I have done what I intended, not sure if it's a good way about it. I have added the tries in the while loop, to count how many times it goes through this loop.</p>
<pre><code> tries = 0
x = 1
while x is 1:
tries = tries + 1
print tries
# if tries is 3: break
guessestaken = 0
ma... | 0 | 2016-06-14T07:10:19Z | [
"python"
] |
URLError: urlopen error [Errno 2] No such file or directory | 37,787,915 | <p>I was perfectly able to use pandas <code>read_csv</code> for reading files in Windows. However I cannot figure out how to set local path in Ubuntu?</p>
<p>If I do this:</p>
<pre><code>data = pd.read_csv(r'file://home/gosper/Desktop/test.csv')
</code></pre>
<p>... it throws the error: <code>URLError: <urlopen e... | 0 | 2016-06-13T10:53:58Z | 37,787,975 | <p>this should work for Windows's and UNIX's Desktop folder:</p>
<pre><code>data = pd.read_csv(os.path.expanduser('~') + '/Desktop/test.csv')
</code></pre>
| 2 | 2016-06-13T10:56:28Z | [
"python",
"pandas"
] |
To get coordinates in the red colored line | 37,787,933 | <p>I want to get coordinates in the detected red color lines in the following image.
But when I run the below code, I get all coordinates (red color lines and other identified objects):</p>
<pre><code>import cv2
import numpy as np
import matplotlib.pyplot as plt
filename = 'detectedRoof.jpg'
img = cv2.imread(filename... | 1 | 2016-06-13T10:54:42Z | 37,788,528 | <p>Firstly, what do mean by "red"? I'm asking since natural red objects (i.e. corners) will always have components in the green and blue channel, too.</p>
<p>Secondly, you detect corners in the gray-scaled image which means corners in all colors. After that you set these objects to blue pixels.</p>
<p>(Thirdly, are y... | 0 | 2016-06-13T11:23:29Z | [
"python",
"opencv"
] |
get data from URL XML with python and xmltodict | 37,787,958 | <p>I'm trying in python2.7 with xmltodict ext. get data from app engine API (XML type).
Got no idea of how doing that...
I tried to do so with local XML (I download it from source url) with success
my local code look like this:</p>
<pre><code>import xmltodict
document = open("my local path\API_GETDATA.xml", "r")
... | -1 | 2016-06-13T10:55:37Z | 37,789,178 | <p>Use the python library <a href="http://docs.python-requests.org/en/master/" rel="nofollow"><code>requests</code></a>:</p>
<p>Install with <code>pip install requests</code> and use like this:</p>
<pre><code>import requests
r = requests.get("url")
xmltodict.parse(r.content)
</code></pre>
| 0 | 2016-06-13T11:53:53Z | [
"python",
"xml",
"api",
"xml-parsing",
"xmltodict"
] |
wx python 3.0.2 classic 'CheckListBox' object has no attribute 'GetItemHeight' | 37,788,095 | <p>Investigating porting my wx 2.8 python app to wx 3.0.2 classic (it's about time) and run into this hurdle. Apparently the GetItemHeight is not part of CheckListBox class anymore:</p>
<pre><code>bash\basher\patcher_dialog.py:519: wxPyDeprecationWarning: Accessing deprecated property.
mouseItem = (event.m_y/self.g... | 1 | 2016-06-13T11:02:33Z | 37,789,893 | <h1>Hi you can try the following trick to do this.</h1>
<blockquote>
<p>I couldn't try this with your code but it is also the way you can find the height of CheckListBox</p>
</blockquote>
<pre><code> self.gPatchers.GetClientRect()[3]
</code></pre>
<blockquote>
<p>It will return the height in pixel.
GetClientRe... | -1 | 2016-06-13T12:29:07Z | [
"python",
"python-2.7",
"wxpython"
] |
wx python 3.0.2 classic 'CheckListBox' object has no attribute 'GetItemHeight' | 37,788,095 | <p>Investigating porting my wx 2.8 python app to wx 3.0.2 classic (it's about time) and run into this hurdle. Apparently the GetItemHeight is not part of CheckListBox class anymore:</p>
<pre><code>bash\basher\patcher_dialog.py:519: wxPyDeprecationWarning: Accessing deprecated property.
mouseItem = (event.m_y/self.g... | 1 | 2016-06-13T11:02:33Z | 37,812,316 | <p>You can simply use <a href="http://wxpython.org/Phoenix/docs/html/wx.ListBox.html#wx.ListBox.HitTest" rel="nofollow"><code>HitTest</code></a> from the underlying class <code>ListBox</code> to find which item is at the given x/y coordinate. Item is the <code>int</code> index of list element. The documentation is for ... | 0 | 2016-06-14T12:40:02Z | [
"python",
"python-2.7",
"wxpython"
] |
ImportError: No module named sendgrid local development server windows 10 | 37,788,113 | <p>this is my code:</p>
<pre><code>import sendgrid
from sendgrid import SendGridClient, Mail
import Message
s = sendgrid.SendGridClient("2HXwPrNlQX-5RBJ61webMA")
message = sendgrid.Mail()
message.add_to('Jhon Doe <jdoe@test.com>')
message.set_subject('Example')
message.set_html('Body')
message.set_text('Body')... | 0 | 2016-06-13T11:03:35Z | 37,789,838 | <p>There's no point in installing things with <code>pip</code> when you're using GAE. It runs in a sandbox, and doesn't look at the things installed outside there. As <a href="https://cloud.google.com/appengine/docs/python/runtime#adding_third_party_python_libraries" rel="nofollow">the docs</a> show, if you need to ins... | 2 | 2016-06-13T12:26:13Z | [
"python",
"google-app-engine",
"sendgrid"
] |
ImportError: No module named sendgrid local development server windows 10 | 37,788,113 | <p>this is my code:</p>
<pre><code>import sendgrid
from sendgrid import SendGridClient, Mail
import Message
s = sendgrid.SendGridClient("2HXwPrNlQX-5RBJ61webMA")
message = sendgrid.Mail()
message.add_to('Jhon Doe <jdoe@test.com>')
message.set_subject('Example')
message.set_html('Body')
message.set_text('Body')... | 0 | 2016-06-13T11:03:35Z | 37,804,769 | <p>Python App on App Engine</p>
<p>You can add a third-party library to your app in one of two ways: requesting the library or installing the library.</p>
<p>You can get the reference from link give below to <strong>Installing a library</strong></p>
<p><a href="https://cloud.google.com/appengine/docs/python/tools/us... | 0 | 2016-06-14T06:45:04Z | [
"python",
"google-app-engine",
"sendgrid"
] |
ImportError: No module named sendgrid local development server windows 10 | 37,788,113 | <p>this is my code:</p>
<pre><code>import sendgrid
from sendgrid import SendGridClient, Mail
import Message
s = sendgrid.SendGridClient("2HXwPrNlQX-5RBJ61webMA")
message = sendgrid.Mail()
message.add_to('Jhon Doe <jdoe@test.com>')
message.set_subject('Example')
message.set_html('Body')
message.set_text('Body')... | 0 | 2016-06-13T11:03:35Z | 37,824,222 | <p>App Engine runs in a sandbox, so if you install new libraries globally, they aren't accessible to your app. That's because App Engine isn't going to upload all your local libraries, just your application ones.</p>
<p>You probably want to consider using <a href="https://github.com/jonparrott/Darth-Vendor" rel="nofol... | 0 | 2016-06-15T00:23:33Z | [
"python",
"google-app-engine",
"sendgrid"
] |
how to zoom the plot in pyqtgraph | 37,788,156 | <p>I don't know how to operate the plot to be zoomed.<br>
This plot draw random function in real time.<br>
I want to zoom the plot in real time for specified region.<br>
This code is example code in pyqtgraph. This code works right for fixed data.<br>
Is it impossible the plot moving in real time to zoom?
Would you pl... | -1 | 2016-06-13T11:05:51Z | 37,917,768 | <p>I solved this problem with adding "updateZoom()" function marked '# added ..'.<br>
Code revised is shown as below.<br>
And another problem occurred as the console message below.<br>
What is the reason?<br>
Would you please help me? </p>
<p>Console message : </p>
<p>C:\Python27\lib\site-packages\pyqtgraph\graphi... | 0 | 2016-06-20T08:29:28Z | [
"python",
"numpy",
"pyqt",
"pyqtgraph"
] |
how to zoom the plot in pyqtgraph | 37,788,156 | <p>I don't know how to operate the plot to be zoomed.<br>
This plot draw random function in real time.<br>
I want to zoom the plot in real time for specified region.<br>
This code is example code in pyqtgraph. This code works right for fixed data.<br>
Is it impossible the plot moving in real time to zoom?
Would you pl... | -1 | 2016-06-13T11:05:51Z | 37,948,147 | <p>I also solved this problem. I revised the code as shown below line. </p>
<p>Before revision: </p>
<pre><code>curveZoom.setData(dataRnd[:ptrDataRnd])
</code></pre>
<p>revised code: </p>
<pre><code>curveZoom.setData(dataRnd[0:ptrDataRnd])
</code></pre>
<p>I wonder the convention of the numpy array.
The mean... | 0 | 2016-06-21T15:07:56Z | [
"python",
"numpy",
"pyqt",
"pyqtgraph"
] |
Python/Django global name 'x' is not defined | 37,788,388 | <p>I don't know why but I'm calling a method from another view but now It doesn't work since I modified a try/except on my view. The except is used in all my views and it works perfecty.</p>
<p>This view should modify elements of a menu via a pre-filled form. Actually I can't access to this form with the error :</p>
... | 0 | 2016-06-13T11:16:32Z | 37,788,832 | <p>Plain simply: <code>logoutUser</code> isn't defined nor imported anywhere in your view. Remember Python has no real "global" namespace.</p>
| 0 | 2016-06-13T11:36:48Z | [
"python",
"django",
"model",
"django-views"
] |
Blank Result When Filtering ForeignKey values in Django ModelchoiceField | 37,788,444 | <p>I have three models and they serve as 'Foreignkey' to each other.</p>
<p>Hotel models</p>
<pre><code>class Hotel(model.Models):
user= models.ForeignKey(User)
name= models.CharField(max_length=100, verbose_name='hotel_name')
address= models.CharField(max_length=100, verbose_name='hotel_address')
#more fiel... | 1 | 2016-06-13T11:19:28Z | 37,791,403 | <p>You should modify the line </p>
<pre><code>self.fields['hotelrooms'].queryset = HotelRooms.objects.filter(hotel=self.instance.hotel_id)
</code></pre>
<p>to </p>
<pre><code>self.fields['hotelrooms'].queryset = HotelRooms.objects.filter(hotel=self.instance.hotel)
</code></pre>
<p>When you are filtering on foreign ... | 1 | 2016-06-13T13:44:05Z | [
"python",
"django",
"django-models",
"django-views"
] |
Blank Result When Filtering ForeignKey values in Django ModelchoiceField | 37,788,444 | <p>I have three models and they serve as 'Foreignkey' to each other.</p>
<p>Hotel models</p>
<pre><code>class Hotel(model.Models):
user= models.ForeignKey(User)
name= models.CharField(max_length=100, verbose_name='hotel_name')
address= models.CharField(max_length=100, verbose_name='hotel_address')
#more fiel... | 1 | 2016-06-13T11:19:28Z | 37,836,610 | <p>It seems you are trying to populate the <code>hotelrooms</code> field with the filtered results by the hotel when the form is loaded on a GET request. If that's the case the field wont load any data as the <code>instance</code> variable will be <code>None</code>.</p>
<p>For the initial data you need to pass the hot... | 1 | 2016-06-15T13:17:13Z | [
"python",
"django",
"django-models",
"django-views"
] |
AttributeError: 'Dlink' object has no attribute 'browser_driver' | 37,788,567 | <p>I have created a class in python:</p>
<pre><code>class Dlink(object):
def __init__(self, server_ip):
self.broswer_driver = webdriver.Chrome()
self.base_url = "http://" + server_ip
self.broswer_driver.implicitly_wait(30)
def dlink_change_channel(self, channel):
.......
actions = ActionChains(... | 0 | 2016-06-13T11:25:12Z | 37,788,686 | <p>I think your attribute is <code>broswer_driver</code> and not <code>browser_driver</code>. You have made a spelling mistake there.</p>
| 2 | 2016-06-13T11:30:02Z | [
"python"
] |
Updating a Dictionary from another dictionary | 37,788,618 | <p>So I have a dictionary, Which is something like this.</p>
<pre><code>data1 = {"00:08:22:24:f8:02": {
"mac_address" : "00:08:22:24:f8:02",
"cities" :
[
{'name': 'Bhubaneswar', 'count': 12},
{'name': 'Kolkata', 'count': 4},
... | -1 | 2016-06-13T11:27:21Z | 37,789,283 | <pre><code>data3=data2.update(data1)
data4={}
for k, v in data2.items():
data4[k]=sum(v['count'] for v in v['cities'])
print data4
</code></pre>
<p>output is :</p>
<pre><code>{'00:08:22:1c:50:07': 4, '00:08:22:24:cc:fb': 1, '00:03:7f:05:c0:06': 1, '00:08:22:24:f8:02': 22}
</code></pre>
| 0 | 2016-06-13T11:58:26Z | [
"python",
"dictionary"
] |
Updating a Dictionary from another dictionary | 37,788,618 | <p>So I have a dictionary, Which is something like this.</p>
<pre><code>data1 = {"00:08:22:24:f8:02": {
"mac_address" : "00:08:22:24:f8:02",
"cities" :
[
{'name': 'Bhubaneswar', 'count': 12},
{'name': 'Kolkata', 'count': 4},
... | -1 | 2016-06-13T11:27:21Z | 37,789,566 | <p>First of all, your data structure is highly inefficient. Why not</p>
<pre><code>{
"00:08:22:24:f8:02": {
"cities": {
"Bhubaneswar": 12,
"Kolkata": 4,
"Mumbai": 6
}
}
}
</code></pre>
<p>Given that data structure, the update becomes trivial (it would be even easier using a <a href="http... | 1 | 2016-06-13T12:12:30Z | [
"python",
"dictionary"
] |
replace semicolon by newline in python code | 37,788,633 | <p>I would like to parse Python code that contains semicolons <code>;</code> for separating commands and produce code that replaces those by newlines <code>\n</code>. E.g., from</p>
<pre class="lang-py prettyprint-override"><code>def main():
a = "a;b"; return a
</code></pre>
<p>I'd like to produce</p>
<pre class... | 6 | 2016-06-13T11:28:03Z | 37,788,839 | <p>Use the <a href="https://docs.python.org/2/library/tokenize.html" rel="nofollow"><code>tokenize</code> library</a> to look for <a href="https://docs.python.org/2/library/token.html#token.OP" rel="nofollow"><code>token.OP</code> tokens</a>, where the second element is a <code>;</code> <sup>*</sup>. Replace these toke... | 4 | 2016-06-13T11:37:04Z | [
"python",
"parsing",
"compilation"
] |
replace semicolon by newline in python code | 37,788,633 | <p>I would like to parse Python code that contains semicolons <code>;</code> for separating commands and produce code that replaces those by newlines <code>\n</code>. E.g., from</p>
<pre class="lang-py prettyprint-override"><code>def main():
a = "a;b"; return a
</code></pre>
<p>I'd like to produce</p>
<pre class... | 6 | 2016-06-13T11:28:03Z | 37,790,823 | <p>Here's a pyparsing solution - see comments in the code below:</p>
<pre><code>from pyparsing import Literal, restOfLine, quotedString, pythonStyleComment, line
SEMI = Literal(';')
patt = SEMI + restOfLine
patt.ignore(quotedString)
patt.ignore(pythonStyleComment)
def split_at(s, locs):
"""
break up s into p... | 1 | 2016-06-13T13:15:13Z | [
"python",
"parsing",
"compilation"
] |
Windows: Odoo not working : ImportError :No module named tools | 37,788,758 | <p>I have manually tried to install odoo in my windows system using souce link <a href="https://nightly.odoo.com/8.0/nightly/src/odoo_8.0.latest.zip" rel="nofollow">https://nightly.odoo.com/8.0/nightly/src/odoo_8.0.latest.zip</a> .Could any one help me to figure out why the following error was resulted while running od... | 0 | 2016-06-13T11:33:19Z | 37,803,221 | <p>Pls ensure your openerp folder has a directory named 'tools', if not try this link to download new instance
for windows: <a href="https://nightly.odoo.com/8.0/nightly/exe/" rel="nofollow">https://nightly.odoo.com/8.0/nightly/exe/</a>
for Linux: <a href="https://nightly.odoo.com/8.0/nightly/src/" rel="nofollow">https... | 0 | 2016-06-14T04:50:56Z | [
"python",
"pip",
"openerp",
"odoo-8"
] |
Error in the coding : TypeError : list indices must be integer, not str | 37,788,799 | <p>Code is importing another file, which is working perfectly.</p>
<p>But, there is a problem in the line where I try to import the csv file, with a column called 'account key', returning the TypeError above.</p>
<pre><code>import file_import as fi
</code></pre>
<p>Function for collectively finding data necessary fr... | -2 | 2016-06-13T11:35:01Z | 37,788,889 | <p><code>csv_file["account_key"]</code></p>
<p>Lists expect a numeric index. As far as I know, only dictionaries accept String indices. </p>
<p>I'm not entirely sure what this is supposed to do; I think your logic is flawed. You bind <code>information</code> in the <code>for</code> loop, then never use it. Even if th... | 2 | 2016-06-13T11:39:57Z | [
"python",
"csv"
] |
Plotting custom text as xlabels | 37,788,849 | <p>I am trying to rename my x labels with a text and wrote the following code: </p>
<pre><code>dow=pd.to_datetime(df1['Dates']).dt.dayofweek
Weekdays= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
df2 = df1.groupby([dow,'Category'])['Category'].count().unstack('Category').fillna(0)
df2... | 1 | 2016-06-13T11:37:38Z | 37,788,990 | <p>Try:</p>
<pre><code>plt.xticks(range(len(Weekdays)),Weekdays)
</code></pre>
| 1 | 2016-06-13T11:45:23Z | [
"python",
"numpy",
"matplotlib"
] |
Plotting custom text as xlabels | 37,788,849 | <p>I am trying to rename my x labels with a text and wrote the following code: </p>
<pre><code>dow=pd.to_datetime(df1['Dates']).dt.dayofweek
Weekdays= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
df2 = df1.groupby([dow,'Category'])['Category'].count().unstack('Category').fillna(0)
df2... | 1 | 2016-06-13T11:37:38Z | 37,789,569 | <p>try:</p>
<pre><code>ax = plt.gca()
ax.set_xticks([day for day in Weekdays])
</code></pre>
<p>or:</p>
<pre><code>plt.xticks([day for day in Weekdays])
</code></pre>
| 1 | 2016-06-13T12:12:38Z | [
"python",
"numpy",
"matplotlib"
] |
pandas: Why does the dtype of a column change on assignment to a data frame | 37,788,914 | <p>I have a pandas DataFrame <code>bla</code> with a MultiIndex for columns:</p>
<pre><code>ipdb> bla.dtypes
phases end datetime64[ns]
name object
start datetime64[ns]
parameters scanFrequency float64
tideFile ... | 3 | 2016-06-13T11:41:31Z | 37,791,489 | <p>I am not sure if it is a bug or expected behaviour, but the problem is that you are assigning multiple columns at once with mixed dtypes (object and float64) and because of this they are 'upcasted' to a common dtype, i.e. object dtype. </p>
<p>A workaround is to perform the <code>ffill</code> on separate columns. I... | 2 | 2016-06-13T13:48:58Z | [
"python",
"pandas"
] |
Python sum 2D list column coincident | 37,788,962 | <p>I'm looking for the most efficient method to do the following calculation:</p>
<p>I have three matrix, like this:</p>
<pre><code>[[Brand1, operationCost], [Brand2, operationCost],...]
[[Brand1, maintenanceCost],[Brand2, maintenanceCost]...]
[[Brand1, replacementCost],[Brand2, replacementCost]...]
</code></pre>
... | 1 | 2016-06-13T11:44:01Z | 37,789,177 | <p>Numpy should solve your problems:</p>
<p>example:</p>
<pre><code>import numpy as np
c = np.array([[1, 2, 3], [1, 2, 3]])
c.sum(0)
Out[5]: array([2, 4, 6])
</code></pre>
<p>If you want to keep your brands combined with the variables I would use pandas:</p>
<p>example:</p>
<pre><code>import pandas as pd
In[9]: df... | 2 | 2016-06-13T11:53:52Z | [
"python",
"matrix",
"sum",
"zip"
] |
Python sum 2D list column coincident | 37,788,962 | <p>I'm looking for the most efficient method to do the following calculation:</p>
<p>I have three matrix, like this:</p>
<pre><code>[[Brand1, operationCost], [Brand2, operationCost],...]
[[Brand1, maintenanceCost],[Brand2, maintenanceCost]...]
[[Brand1, replacementCost],[Brand2, replacementCost]...]
</code></pre>
... | 1 | 2016-06-13T11:44:01Z | 37,789,265 | <p>As you don't seem to use python dictionaries, this should work:</p>
<pre><code>operation = [[Brand1, operationCost], [Brand2, operationCost],...]
maintenance = [[Brand1, maintenanceCost], [Brand2, maintenanceCost],...]
replacement = [[Brand1, replacementCost], [Brand2, replacementCost],...]
total = [ [ope[0], ope[... | 1 | 2016-06-13T11:57:37Z | [
"python",
"matrix",
"sum",
"zip"
] |
Python sum 2D list column coincident | 37,788,962 | <p>I'm looking for the most efficient method to do the following calculation:</p>
<p>I have three matrix, like this:</p>
<pre><code>[[Brand1, operationCost], [Brand2, operationCost],...]
[[Brand1, maintenanceCost],[Brand2, maintenanceCost]...]
[[Brand1, replacementCost],[Brand2, replacementCost]...]
</code></pre>
... | 1 | 2016-06-13T11:44:01Z | 37,790,229 | <p>This solution is pure Python (it does not rely on third party dependencies) and should work even if the length of the lists is not the same:</p>
<pre><code>oc = [['Brand1', <operationCost>],
['Brand2', <operationCost>],
...,
]
mc = [['Brand1', <maintenanceCost>],
['Brand2... | 1 | 2016-06-13T12:46:24Z | [
"python",
"matrix",
"sum",
"zip"
] |
Install PIL/Pillow for ubuntu python 2.7 | 37,789,018 | <p>I have successfully installed PIL/Pillow for python <code>3.4</code> but I want it for python <code>2.7</code>. I thought it might be automatically downloaded for <code>2.7</code> as well but when I tried the python shell from the terminal, it keeps saying <code>No module named PIL</code> and <code>No module named P... | 0 | 2016-06-13T11:46:27Z | 37,789,157 | <p>Install PIL using <code>pip install pillow</code> </p>
<p>Then in the shell try <code>import PIL</code> or <code>from PIL import ...</code></p>
| 0 | 2016-06-13T11:52:53Z | [
"python",
"python-2.7",
"python-imaging-library"
] |
Install PIL/Pillow for ubuntu python 2.7 | 37,789,018 | <p>I have successfully installed PIL/Pillow for python <code>3.4</code> but I want it for python <code>2.7</code>. I thought it might be automatically downloaded for <code>2.7</code> as well but when I tried the python shell from the terminal, it keeps saying <code>No module named PIL</code> and <code>No module named P... | 0 | 2016-06-13T11:46:27Z | 37,789,346 | <p>In python 2.7 there is no module named PIL,
you can use PIL features through Pillow,so <strong>PIL</strong> aka <strong>Pillow</strong><br>
Your output shows you are still using python3<br>
Switch to python 2.7 and try <code>pip install pillow</code><br>
Then you can directly import <strong>PIL</strong> and use its ... | 0 | 2016-06-13T12:01:28Z | [
"python",
"python-2.7",
"python-imaging-library"
] |
pass json file as command line argument through parser , is this possible? | 37,789,120 | <p>I need to overwrite json file parameters to a python dictionary through command line argument parser. Since, json file is located in the current working directory but its name can be dynamic , so i want something like below :-</p>
<blockquote>
<p>python python_script --infile json_file</p>
</blockquote>
<h1>p... | 0 | 2016-06-13T11:50:56Z | 37,834,787 | <p>Read the JSON file with the name given to <code>--infile</code> and update your <code>profileInfo</code>:</p>
<pre><code>import json
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--infile', nargs=1,
help="JSON file to be processed",
type=argparse.Fi... | 0 | 2016-06-15T11:56:04Z | [
"python",
"json"
] |
Python-Django: save seen items in order to not show them again? | 37,789,129 | <p>I have a site that gives you random jokes, and the problem is that sometimes it shows the same joke too often. I have a Joke model, and I want to save the ids of these jokes and for every visitor make sure that the same joke is not shown for, let's say, 20 rounds. But how can I save such data and pass them around?
H... | 0 | 2016-06-13T11:51:22Z | 37,789,406 | <p>You could store the <em>seen</em> jokes in the user's session:</p>
<pre><code>seen_joke_ids = request.session.get('seen_joke_ids', [])
joke = Joke.objects.exclude(pk__in=seen_joke_ids).order_by('?')[0]
seen_joke_ids.append(joke.pk)
request.session['seen_joke_ids'] = seen_joke_ids[-20:]
# your logic to display/redi... | 2 | 2016-06-13T12:04:43Z | [
"python",
"django",
"cookies"
] |
replace text from docx using Python | 37,789,196 | <p>I have a little side project I'm doing at work to help me with the "manual" labor of creating welcome documents for employees.</p>
<p>What I'm trying to do is:
1) Extract cell contents from a CSV file (username, first name, password)
2) Take cell contents and replace the strings [FirstName], [Username] and [Passwor... | 0 | 2016-06-13T11:55:05Z | 37,808,926 | <p>IIUC You are not replacing the keyword strings after checking for their presence:</p>
<p>Do this change and it shall have the strings replaced.</p>
<pre><code>for paragraph in document.paragraphs:
if '[FirstName]' in paragraph.text:
print(first_name)
paragraph.text = paragraph.text.... | 1 | 2016-06-14T10:03:19Z | [
"python",
"csv",
"docx"
] |
Does python allow me to pass dynamic variables to a decorator at runtime? | 37,789,212 | <p>I am attempting to integrate a very old system and a newer system at work. The best I can do is to utilize an RSS firehouse type feed the system utilizes. The goal is to use this RSS feed to make the other system perform certain actions when certain people do things. </p>
<p>My idea is to wrap a decorator around ce... | 0 | 2016-06-13T11:55:37Z | 37,789,334 | <p>First lets create a decorator that can perform a permission check before executing a function:</p>
<pre><code>import functools
def check_permissions(user_id):
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kw):
if has_permissions(user_id):
return f(*args,... | 1 | 2016-06-13T12:00:53Z | [
"python",
"decorator",
"python-decorators"
] |
Does python allow me to pass dynamic variables to a decorator at runtime? | 37,789,212 | <p>I am attempting to integrate a very old system and a newer system at work. The best I can do is to utilize an RSS firehouse type feed the system utilizes. The goal is to use this RSS feed to make the other system perform certain actions when certain people do things. </p>
<p>My idea is to wrap a decorator around ce... | 0 | 2016-06-13T11:55:37Z | 37,789,411 | <p>The inputs to decorators (arguments, wrapped function) are rather static in python. There is no way to dynamically pass an argument like you're asking. If the user id can be extracted from somewhere at runtime inside the decorator function however, you can achieve what you want..</p>
<p>In Django for example, thing... | 0 | 2016-06-13T12:04:59Z | [
"python",
"decorator",
"python-decorators"
] |
Does python allow me to pass dynamic variables to a decorator at runtime? | 37,789,212 | <p>I am attempting to integrate a very old system and a newer system at work. The best I can do is to utilize an RSS firehouse type feed the system utilizes. The goal is to use this RSS feed to make the other system perform certain actions when certain people do things. </p>
<p>My idea is to wrap a decorator around ce... | 0 | 2016-06-13T11:55:37Z | 37,798,083 | <p>In your question, you've named both, the check of the <code>user_id</code>, as well as the wanted decorator <code>has_permissions</code>, so I'm going with an example where names are more clear: Let's make a decorator that calls the underlying (decorated) function when the color (a string) is <code>'green'</code>.</... | 3 | 2016-06-13T19:53:33Z | [
"python",
"decorator",
"python-decorators"
] |
How to efficiently add a new key to an RDD in pyspark | 37,789,227 | <p>I have 2 RDDs formats, the first one is <code>((provider, currency), value)</code> where the key is <code>(provider, currency)</code> and the second one <code>(provider, value)</code> where the key is <code>provider</code>.</p>
<p>What I want to do is transform an RDD <strong>A</strong> from the <code>(provider, va... | 2 | 2016-06-13T11:56:00Z | 37,813,330 | <p>Try this:
Given <code>Ardd = RDD[(provider, value)]</code> and <code>Brdd = RDD[((provider, currency), value)]</code>, what you want to do is join <code>Ardd</code> and <code>Brdd</code> such that <code>newRDD</code> would be of the form <code>RDD[((provider, currency), value)]</code>. Where <code>value</code> refe... | 3 | 2016-06-14T13:21:51Z | [
"python",
"apache-spark",
"pyspark",
"rdd"
] |
Passing bytes as parameter to c#? | 37,789,281 | <p>I am currently stuck while trying to call a c# methods from python. I am using python 3.2 and not IronPython. I used pip to install the latest version of python.net</p>
<p>Problem occurs (as often discussed) while using ref or out parameters.</p>
<p>Here is my code so far:</p>
<pre><code>import clr
path = clr.Fi... | 3 | 2016-06-13T11:58:20Z | 37,791,267 | <p>Python.Net doesn't handle ref/out parameters like IronPython.<br>
<code>status, readData = gpio.gpioReadWrite(b'\x01',b'\x00',b'\x00')</code> call is not quite correct since Python.Net will not return an updated readData as second result.<br>
You can handle ref parameters using reflection. Check out my answer to sim... | 1 | 2016-06-13T13:37:49Z | [
"c#",
"python",
".net",
"python-3.x",
"python.net"
] |
How to use different fonts for two lines within the same cell in Excel? | 37,789,285 | <p>I have an excel file with a table A6:E233. I had to concatenate columns A and B so that values from B are displayed in a new line. I have achieved that with the CONCATENATE function (and CHAR(10) for new line) that is built into Excel.</p>
<p>After concatenation the spreadsheets looks like this:</p>
<p><a href="ht... | 0 | 2016-06-13T11:58:31Z | 37,789,697 | <p>With Excel VBA, you need to use the <code>Characters</code> property of the <code>Range</code> object. For example:</p>
<pre><code>Sub Test()
Dim rngCell As Range
Dim lngPos As Long
'get cell
Set rngCell = Sheet1.Range("A1")
'find linebreak
lngPos = InStr(1, rngCell.Value, vbLf, vbBinaryCo... | 1 | 2016-06-13T12:19:13Z | [
"python",
"excel",
"vba",
"excel-vba"
] |
How to use different fonts for two lines within the same cell in Excel? | 37,789,285 | <p>I have an excel file with a table A6:E233. I had to concatenate columns A and B so that values from B are displayed in a new line. I have achieved that with the CONCATENATE function (and CHAR(10) for new line) that is built into Excel.</p>
<p>After concatenation the spreadsheets looks like this:</p>
<p><a href="ht... | 0 | 2016-06-13T11:58:31Z | 37,789,703 | <p>Here, try this code. I built this according to your screenshot.</p>
<pre><code>Sub partialFormatting()
Dim tws As Worksheet
Dim fr, lr As Integer
Dim pos As Integer
Set tws = ThisWorkbook.Worksheets("Sheet1")
fr = 7
lr = tws.Range("A1000000").End(xlUp).Row
For r = fr To lr
With tws... | 0 | 2016-06-13T12:19:29Z | [
"python",
"excel",
"vba",
"excel-vba"
] |
using string.strip() in python to extract specific coloumns | 37,789,330 | <pre><code>import requests
from bs4 import BeautifulSoup
f = open('path to create /Price.csv','w')
errorFile = open('path to create /errorPrice.txt','w')
year = 2012; month = 1; day =1
if year<= 2016:
if day > 32:
month += 1
day = 1
if month >12:
year += 1
month = 1
... | 1 | 2016-06-13T12:00:39Z | 37,789,727 | <p>A few things about your code before your actual error:</p>
<p>Use the <a href="http://effbot.org/zone/python-with-statement.htm" rel="nofollow"><code>with</code></a> statement to open files. Manually opening and closing files is unnecessary.</p>
<p>Use <code>res.content</code> instead of <code>res.text</code> if y... | 1 | 2016-06-13T12:20:36Z | [
"python",
"python-3.x",
"web-scraping",
"beautifulsoup",
"bs4"
] |
using string.strip() in python to extract specific coloumns | 37,789,330 | <pre><code>import requests
from bs4 import BeautifulSoup
f = open('path to create /Price.csv','w')
errorFile = open('path to create /errorPrice.txt','w')
year = 2012; month = 1; day =1
if year<= 2016:
if day > 32:
month += 1
day = 1
if month >12:
year += 1
month = 1
... | 1 | 2016-06-13T12:00:39Z | 37,789,798 | <p>You just need to index the list returned <code>SN = row.findAll('td')[3]</code>, there is also no point removing the newline to then put it back on, this is will get all the table data:</p>
<pre><code> r = requests.get("http://nepalstock.com.np/main/todays_price/index/1/stock-name/desc/YTozOntzOjk6InN0YXJ0RGF0ZSI7c... | 1 | 2016-06-13T12:24:18Z | [
"python",
"python-3.x",
"web-scraping",
"beautifulsoup",
"bs4"
] |
Import CSV as float in a List (Python 3.5) | 37,789,412 | <p>I need to import a csv file, which contains about 1.000.000 numbers. they are all separated with decimals (,) so: 1,2,3,4,...</p>
<p>they just ordered easily in the file: no blanks no paragraphs.</p>
<p>This is my actual code:</p>
<pre><code>import statistics
import csv
with open('test.csv', 'r') as f:
reade... | -1 | 2016-06-13T12:05:06Z | 37,789,479 | <p>The items in your <code>zahlenliste</code> are characters, you'll need to cast them to numbers (<code>int</code> or <code>float</code>). A <a href="https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a> comes in handy here:</p>
<pre><code>zahlenliste = [[in... | 2 | 2016-06-13T12:08:16Z | [
"python",
"csv",
"import"
] |
In which event loop does a coroutine run when using yield from? | 37,789,420 | <p>When I call <code>yield from some_coroutine()</code> from with in a couroutine <code>foo</code>, is <code>some_coroutine</code> scheduled in the same even-loop as <code>foo</code> is currently running in? An example:</p>
<pre><code>async def foo():
yield from asyncio.sleep(5)
loop = asyncio.get_event_loop() # ... | 3 | 2016-06-13T12:05:45Z | 37,791,628 | <p>Citing docs of <a href="https://docs.python.org/3/library/asyncio-eventloops.html#asyncio.AbstractEventLoopPolicy.get_event_loop" rel="nofollow"><code>get_event_loop</code></a> </p>
<blockquote>
<p>Get the event loop for the current context.</p>
</blockquote>
<p>Implementation of <a href="https://docs.python.org... | 3 | 2016-06-13T13:55:57Z | [
"python",
"python-3.x",
"python-asyncio"
] |
regex - python extracting email header names | 37,789,503 | <p>hi am looking for a way to extract header names (what is in bold) from this block of text (originaly from mbox file)
i tried this regex that worked on sublime text regex search but didnt work on python
^\w+-?(\w+)?-?(\w+)?:</p>
<pre><code>rgex = re.findall('^\w+-?(\w+)?-?(\w+)?:', mail);
</code></pre>
<p>THIS IS W... | 0 | 2016-06-13T12:09:30Z | 37,789,778 | <p>A simpler approach than devising an appropriate regex might be to use a more appropriate tool that comes with python ... the <a href="https://docs.python.org/3/library/email.parser.html" rel="nofollow"><code>email.parser</code></a> module, which is designed to parse rcf822 messages such as this.</p>
<pre><code>>... | 1 | 2016-06-13T12:23:27Z | [
"python",
"regex"
] |
regex - python extracting email header names | 37,789,503 | <p>hi am looking for a way to extract header names (what is in bold) from this block of text (originaly from mbox file)
i tried this regex that worked on sublime text regex search but didnt work on python
^\w+-?(\w+)?-?(\w+)?:</p>
<pre><code>rgex = re.findall('^\w+-?(\w+)?-?(\w+)?:', mail);
</code></pre>
<p>THIS IS W... | 0 | 2016-06-13T12:09:30Z | 37,789,883 | <p>If you're running a regex over the entire mbox file then a regex will not work - you're going to have to write a program. The reason is that the body of the message has the potential to have tokens that will match exactly what a header token will look like.</p>
<p>Assuming that you're ONLY running the regex over t... | 0 | 2016-06-13T12:28:18Z | [
"python",
"regex"
] |
regex - python extracting email header names | 37,789,503 | <p>hi am looking for a way to extract header names (what is in bold) from this block of text (originaly from mbox file)
i tried this regex that worked on sublime text regex search but didnt work on python
^\w+-?(\w+)?-?(\w+)?:</p>
<pre><code>rgex = re.findall('^\w+-?(\w+)?-?(\w+)?:', mail);
</code></pre>
<p>THIS IS W... | 0 | 2016-06-13T12:09:30Z | 37,789,895 | <p>Your <code>'^\w+-?(\w+)?-?(\w+)?:'</code> regex matches the beginning of a string (<code>^</code>), then 1+ word chars, followed by an optional <code>-</code>, then 1+ word chars are captured into an optional Group 1 (and those are returned by <code>re.findall</code> as the first item in each tuple returned as a lis... | 0 | 2016-06-13T12:29:14Z | [
"python",
"regex"
] |
regex - python extracting email header names | 37,789,503 | <p>hi am looking for a way to extract header names (what is in bold) from this block of text (originaly from mbox file)
i tried this regex that worked on sublime text regex search but didnt work on python
^\w+-?(\w+)?-?(\w+)?:</p>
<pre><code>rgex = re.findall('^\w+-?(\w+)?-?(\w+)?:', mail);
</code></pre>
<p>THIS IS W... | 0 | 2016-06-13T12:09:30Z | 37,790,467 | <p>Python provides the email package that can do those low-level tasks for you, but if you want to learn email headers the hard way, the reference is the <a href="https://tools.ietf.org/html/rfc5322" rel="nofollow">RFC5322</a> (formely RFC822)</p>
<p>Among other sensible information, you find the definition of header ... | 0 | 2016-06-13T12:57:30Z | [
"python",
"regex"
] |
How to send json data from Angularjs post to Django view? | 37,789,511 | <p>I need to send json data using POST request from Angularjs to my Django view , need get data from database using this json as json format. I tried some examples using from net resources:</p>
<p>JS Code:</p>
<pre><code>$http({
method: 'POST',
url: '/mycard/list',
data: $.param({test: json})
});
</code></p... | 0 | 2016-06-13T12:10:03Z | 37,789,710 | <p>Service Code</p>
<pre><code>var promise = $http({
method: 'post',
url: '/mycard/list',
data:data,
contentType:'application/json; charset=UTF-8',
});
return promise;
</code></pre>
<p>Python rest api</p>
<pre... | 0 | 2016-06-13T12:19:46Z | [
"javascript",
"python",
"angularjs",
"json",
"django"
] |
How to send json data from Angularjs post to Django view? | 37,789,511 | <p>I need to send json data using POST request from Angularjs to my Django view , need get data from database using this json as json format. I tried some examples using from net resources:</p>
<p>JS Code:</p>
<pre><code>$http({
method: 'POST',
url: '/mycard/list',
data: $.param({test: json})
});
</code></p... | 0 | 2016-06-13T12:10:03Z | 37,789,735 | <p>your json data should be formatted by <code>JSON.stringify()</code> like this:</p>
<pre><code>$http({
method: 'POST',
url: '/mycard/list',
data: JSON.stringify({test: json})
});
</code></pre>
| 0 | 2016-06-13T12:20:46Z | [
"javascript",
"python",
"angularjs",
"json",
"django"
] |
How to send json data from Angularjs post to Django view? | 37,789,511 | <p>I need to send json data using POST request from Angularjs to my Django view , need get data from database using this json as json format. I tried some examples using from net resources:</p>
<p>JS Code:</p>
<pre><code>$http({
method: 'POST',
url: '/mycard/list',
data: $.param({test: json})
});
</code></p... | 0 | 2016-06-13T12:10:03Z | 37,790,433 | <ul>
<li>403 Forbidden maybe because of an invalid CSRF token </li>
<li>500 : You might be not posting the data in the format that the backend is expecting. Can you please inspect and see what is the error response it is giving.</li>
</ul>
| 0 | 2016-06-13T12:55:58Z | [
"javascript",
"python",
"angularjs",
"json",
"django"
] |
Can't install mahotas, and installing python-dev didn't fix the error | 37,789,572 | <p>I was working through a textbook, and one of the examples required mahotas for python. I immediately tried to install it with pip, and immediately got this error: </p>
<pre><code> x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat ... | 0 | 2016-06-13T12:12:42Z | 37,806,267 | <p>(Author of mahotas here).</p>
<p>Your Ubuntu installation is now in some weird state wrt the Python-dev packages. My recommendation to get out of the rabbit hole is to use Anaconda: <a href="https://www.continuum.io/why-anaconda" rel="nofollow">https://www.continuum.io/why-anaconda</a></p>
<p>Then you can get maho... | 1 | 2016-06-14T08:01:51Z | [
"python",
"gcc",
"compiler-errors",
"g++",
"mahotas"
] |
Annotation of horizontal bar graphs in matplotlib | 37,789,747 | <p>I need to annotate horizontal bar graphs.
I am able to annotate vertical bar graphs using the example shown in matplotlib website but a similar idea for horizonatl doesn't seem to working.</p>
<p>The following is small working example for vertical</p>
<pre><code>from pylab import *
ops = 90*rand(4) # the bar l... | 0 | 2016-06-13T12:21:41Z | 37,793,396 | <pre><code>def autolabel(rects):
for rect in rects:
width = rect.get_width()
plt.text(1.05*rect.get_width(), rect.get_y()+0.5*rect.get_height(),
'%d' % int(width),
ha='center', va='center')
</code></pre>
<p><a href="http://i.stack.imgur.com/mU6kZ.png" rel="nofollow... | 0 | 2016-06-13T15:16:15Z | [
"python",
"matplotlib"
] |
Include batch file when creating a standalone executable from a python script (py2exe) | 37,789,769 | <p>I've been using py2exe to create executables from python scripts. I have one script now that uses a .bat file, and I'm struggling to create a standalone executable for it that can run without the .bat file in the same directory (or anywhere on the computer for that matter).</p>
<p>My setup.py that I'm trying basica... | 1 | 2016-06-13T12:23:05Z | 37,791,874 | <p>I don't think you need that batch file. Everything(?) that can be done with batch file can be done with python (built-in or external) libraries.</p>
<hr>
<p><a href="https://docs.python.org/2/library/functions.html#open" rel="nofollow" title="https://docs.python.org/2/library/functions.html#open">open</a> is a use... | 0 | 2016-06-13T14:07:30Z | [
"python",
"batch-file",
"executable",
"py2exe"
] |
What happens when a python function that takes arguments called without defining parameters? | 37,789,860 | <pre><code>L=[5,10,4,2,8,7]
def compare(a,b):
return cmp(b,a)
L.sort(compare)
print (L[-2])
L.sort()
print (L[2])
</code></pre>
<p>When this code is run, why a exception is not thrown since the function compare called within sort function has not been given exactly two arguments?
when the code is run it gives the... | -2 | 2016-06-13T12:27:15Z | 37,789,910 | <p>You are not calling compare in L.sort(compare). You are just passing a reference to the function that will be called internally by sort. </p>
<p>You don't need any other arguments for that. Remember that in order to call a function you use (), so if you were actually calling it you would have written L.sort(compare... | 0 | 2016-06-13T12:29:48Z | [
"python",
"function",
"sorting"
] |
What happens when a python function that takes arguments called without defining parameters? | 37,789,860 | <pre><code>L=[5,10,4,2,8,7]
def compare(a,b):
return cmp(b,a)
L.sort(compare)
print (L[-2])
L.sort()
print (L[2])
</code></pre>
<p>When this code is run, why a exception is not thrown since the function compare called within sort function has not been given exactly two arguments?
when the code is run it gives the... | -2 | 2016-06-13T12:27:15Z | 37,790,281 | <p>You are not calling directly the function</p>
<p>You are passing to the sort function a 'pointer' or a 'reference' to the function that will be used as a comparator</p>
<p>if you need more debugging info add a line that print what is being compared as follow</p>
<pre><code>L=[5,10,4,2,8,7]
def compare(a,b):
p... | 1 | 2016-06-13T12:48:32Z | [
"python",
"function",
"sorting"
] |
My stereo rectified (OpenCV) images are wrong. PYTHON | 37,789,904 | <p>I am using OpenCV to compute a disparity map of a scene. I have already calibrate the stereo camera by finding the intrinsic parameters individually with <code>cv2.calibrateCamera</code> and then with <code>cv2.stereoCalibrate</code> to find the rotation matrix and the translation vector.
I copy my calibration code... | 1 | 2016-06-13T12:29:34Z | 38,393,744 | <p>Try to switch height and width, namely change this line of your code:</p>
<pre><code>w, h = lFrame.shape[:2] # both frames should be of same shape
</code></pre>
<p>to this:</p>
<pre><code>h, w = lFrame.shape[:2] # both frames should be of same shape
</code></pre>
<p>I ran into the same problem and it helped me. ... | 1 | 2016-07-15T10:24:20Z | [
"python",
"python-2.7",
"opencv",
"opencv3.0",
"stereo-3d"
] |
Python Unit Testing: Avoiding API Calls | 37,789,981 | <p>I've written some code that makes calls to the SalesforceIQ API. I'm now trying to unit test my code (writing a unit test for each of my functions). I'm a little unsure how to go about this since I need to do <em>something</em> to avoid making API calls.</p>
<p>Here's an example function I'm trying to test:</p>
... | 0 | 2016-06-13T12:34:14Z | 37,790,122 | <p>You can use <code>patch</code> (<code>mock.patch</code> in python2, <code>unittest.mock.patch</code> in python3) to patch that method:</p>
<pre><code>@patch.object(Contact, 'update')
def test_api_call(self, update):
# "update" is the patched method, instace of `MagicMock`
update_contact('name', 'phone', 'ad... | 1 | 2016-06-13T12:40:36Z | [
"python",
"unit-testing"
] |
Python Unit Testing: Avoiding API Calls | 37,789,981 | <p>I've written some code that makes calls to the SalesforceIQ API. I'm now trying to unit test my code (writing a unit test for each of my functions). I'm a little unsure how to go about this since I need to do <em>something</em> to avoid making API calls.</p>
<p>Here's an example function I'm trying to test:</p>
... | 0 | 2016-06-13T12:34:14Z | 37,790,127 | <p>Is there a <code>__repr__()</code> or <code>__str__()</code> method for the <code>Contact</code> object? If not, why not write one? Then you can just print the <code>contact</code> and see what it is. Or do something else with the string it returns if you want to further automate your testing.</p>
| 0 | 2016-06-13T12:41:00Z | [
"python",
"unit-testing"
] |
Fastest way with parallelization to compute distances between two points with Python code | 37,790,062 | <p>I have a data frame 'data' with millions of rows. Each row has coordinates ('x','y'), I would like to compute distances among consecutive pairs of the coordinates in the most efficient way python can provide. Will parallelization help here? </p>
<p>I saw approaches here that suggests to use cython. However I would ... | 2 | 2016-06-13T12:37:46Z | 37,790,736 | <p>Here is a quick example to help you get started:</p>
<pre class="lang-python prettyprint-override"><code>from scipy.spatial import distance
from multiprocessing import Pool
processes = 4
# Group data into pairs in order to compute distance
pairs = [(points[i], points[i+1]) for i in range(len(points)-1)]
print pai... | 1 | 2016-06-13T13:10:31Z | [
"python",
"performance",
"parallel-processing"
] |
Fastest way with parallelization to compute distances between two points with Python code | 37,790,062 | <p>I have a data frame 'data' with millions of rows. Each row has coordinates ('x','y'), I would like to compute distances among consecutive pairs of the coordinates in the most efficient way python can provide. Will parallelization help here? </p>
<p>I saw approaches here that suggests to use cython. However I would ... | 2 | 2016-06-13T12:37:46Z | 37,926,841 | <p>You said python, but since you're already using scipy for the distance calculation I assume that a numpy solution is ok.</p>
<p>Using a vectorized, single-threaded operation on a 28 million point numpy array takes only 1 second on my laptop. Using a 32-bit integer data type, the array occupies about 200MB in memor... | 1 | 2016-06-20T15:55:15Z | [
"python",
"performance",
"parallel-processing"
] |
Where can I find the PyBluez API | 37,790,084 | <p>I understood from <a href="http://people.csail.mit.edu/rudolph/Teaching/Articles/BTBook.pdf" rel="nofollow">Bluetooth for Programmers</a> chapter 2, that the PyBluez API does provide functions like <strong>discover_devices</strong> and <strong>lookup_name</strong>. <br> <br> However I have not found any API document... | 0 | 2016-06-13T12:39:05Z | 37,793,077 | <p>Found it: </p>
<ul>
<li>Download the PyBluez sources from it <a href="https://github.com/karulis/pybluez" rel="nofollow">git repository</a></li>
<li>Extract the sources</li>
<li>Open the file pybluez\docs\index.html - Everything is available from there</li>
</ul>
| 1 | 2016-06-13T14:59:57Z | [
"python",
"bluetooth",
"bluez",
"pybluez"
] |
seaborn heatmap using pandas dataframe | 37,790,429 | <p>I am struggling to massage a dataframe in pandas into the correct format for seaborn's heatmap (or matplotlib really) to make a heatmap.</p>
<p>My current dataframe (called data_yule) is:</p>
<pre><code> Unnamed: 0 SymmetricDivision test MutProb value
3 3 1.0 sackin_y... | 1 | 2016-06-13T12:55:50Z | 37,790,707 | <p>The data needs to be <a href="http://pandas.pydata.org/pandas-docs/stable/reshaping.html" rel="nofollow">"pivoted"</a> to look like</p>
<pre><code>In [96]: result
Out[96]:
MutProb 0.001 0.005 0.010 0.050 0.100
SymmetricDivision
0.2... | 5 | 2016-06-13T13:09:25Z | [
"python",
"pandas",
"matplotlib",
"seaborn"
] |
Python: list comprehension based on previous value? | 37,790,464 | <p>Say I want to create a list <em>using list comprehension</em> like:</p>
<pre><code>l = [100., 50., 25., 12.5, ..., a_n]
</code></pre>
<p>â¦i.e., start with some number and generate the n "halves" from that in the same list. I might either be missing some straightforward pythonic way of doing that, or I'll simply ... | 3 | 2016-06-13T12:57:28Z | 37,790,553 | <p>Define a generator, and use it in the list comprehension:</p>
<pre><code>def halve(n):
while n >= 1:
yield n
n /= 2
print([_ for _ in halve(100)])
>> [100, 50.0, 25.0, 12.5, 6.25, 3.125, 1.5625]
</code></pre>
<p>Or simply convert it to a list:</p>
<pre><code>print(list(halve(100)))
&... | 4 | 2016-06-13T13:01:49Z | [
"python",
"list-comprehension"
] |
Python: list comprehension based on previous value? | 37,790,464 | <p>Say I want to create a list <em>using list comprehension</em> like:</p>
<pre><code>l = [100., 50., 25., 12.5, ..., a_n]
</code></pre>
<p>â¦i.e., start with some number and generate the n "halves" from that in the same list. I might either be missing some straightforward pythonic way of doing that, or I'll simply ... | 3 | 2016-06-13T12:57:28Z | 37,790,570 | <p>The following code works with int but not floats. </p>
<pre><code>[100>>i for i in range(10)]
</code></pre>
<p>this returns:</p>
<pre><code>[100, 50, 25, 12, 6, 3, 1, 0, 0, 0]
</code></pre>
| 0 | 2016-06-13T13:02:36Z | [
"python",
"list-comprehension"
] |
Python: list comprehension based on previous value? | 37,790,464 | <p>Say I want to create a list <em>using list comprehension</em> like:</p>
<pre><code>l = [100., 50., 25., 12.5, ..., a_n]
</code></pre>
<p>â¦i.e., start with some number and generate the n "halves" from that in the same list. I might either be missing some straightforward pythonic way of doing that, or I'll simply ... | 3 | 2016-06-13T12:57:28Z | 37,790,670 | <p>How about this?</p>
<pre><code>start = 2500.0
n = 50
halves = [start / 2.0**i for i in range(n)]
</code></pre>
<p>equal to this:</p>
<pre><code>[start * 2.0**(-i) for i in range(n)]
</code></pre>
<p>probably less efficient in contrast to @DeepSpace's answer but a one-liner</p>
| 4 | 2016-06-13T13:07:33Z | [
"python",
"list-comprehension"
] |
Access Siebel WSDL through Python Packages (SOAPpy, suds, requests) | 37,790,630 | <p>I am trying to access Siebel WSDL through python module.
My End Scenario is creating Service request in Siebel through external link.</p>
<p>I have tried,</p>
<p>Requests, Suds and soapPY.</p>
<p>When Importing WSDL file to SOAP-UI after making changes to URL and appending user-name and password to same and makin... | 0 | 2016-06-13T13:05:44Z | 37,802,185 | <p>If you are getting a 500 error, that means the request is stuck at the web server, and has not yet hit the siebel server behind it. If the error is due to something missing in the xml, you will get a "SBL-" error code in the response. Until you get that, and are getting 500 errors, the request SOAP has not yet hit t... | 0 | 2016-06-14T02:52:48Z | [
"python",
"soap",
"wsdl",
"siebel",
"soappy"
] |
Cython Compile Error: Python3 Compatibility | 37,790,718 | <p>I am running <code>Python 3.4.4 :: Anaconda 4.0.0 (x86_64)</code> on <code>OS X Yosemite</code>. My Cython's version is <code>0.23.4</code>. I'm trying to embed some very trivial Cython code <code>test.pyx</code> into C code <code>testcc.c</code>. The problem is, if I use <code>python2.7-config</code> then everythin... | 2 | 2016-06-13T13:09:51Z | 37,791,209 | <p>This is probably due to the fact that in Python <code>3.x</code> initialization of modules is not performed by calling <code>init<module_name></code> but rather with <code>PyInit_<module_name></code> (See <a href="https://www.python.org/dev/peps/pep-3121/#specification" rel="nofollow"><strong><code>PEP 3... | 2 | 2016-06-13T13:34:51Z | [
"python",
"cython",
"anaconda"
] |
Deploy in multiple environment (DEV, UAT, PROD) in Jenkins | 37,790,742 | <p>I have a Python app , I want to deploy it first in DEV, then in UAT and finally on PROD. I could build it using Jenkins with Webhooks so that when It's pushed to DEV it triggers a build(It runs the nosetests suit). I want this app to be promoted in UAT and PROD subsequently if build in DEV and UAT passes respectivel... | 1 | 2016-06-13T13:11:00Z | 37,791,592 | <p>One option is to add your UAT and PROD remote environments as Jenkins slaves.
<a href="https://wiki.jenkins-ci.org/display/JENKINS/Distributed+builds" rel="nofollow">Check this documentation for more on that</a> </p>
<p>When adding a new node you could set an expression label for each environment you add as slave s... | 1 | 2016-06-13T13:54:27Z | [
"python",
"jenkins"
] |
Deploy in multiple environment (DEV, UAT, PROD) in Jenkins | 37,790,742 | <p>I have a Python app , I want to deploy it first in DEV, then in UAT and finally on PROD. I could build it using Jenkins with Webhooks so that when It's pushed to DEV it triggers a build(It runs the nosetests suit). I want this app to be promoted in UAT and PROD subsequently if build in DEV and UAT passes respectivel... | 1 | 2016-06-13T13:11:00Z | 37,791,726 | <p>Best practice would be to use <a href="https://jenkins.io/pipeline/getting-started-pipelines/" rel="nofollow">Jenkins pipeline</a>. You could necessitate progression between your environments by using <a href="https://jenkins.io/doc/pipeline/steps/pipeline-input-step/" rel="nofollow">input step</a> and have your (I ... | 1 | 2016-06-13T14:01:18Z | [
"python",
"jenkins"
] |
Reducing dimensions for supervised learning | 37,790,839 | <p>I have this type of numpy array. Here i have shown 2 elements of the array. I have converted a .jpeg file to numpy array.</p>
<pre><code>[[[130 130 130 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
...,
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
[ 68... | -1 | 2016-06-13T13:15:51Z | 37,790,999 | <p>Using reshape:</p>
<pre><code>new_img = np.reshape(old_data,(2,243*320))
</code></pre>
| 0 | 2016-06-13T13:24:43Z | [
"python",
"numpy",
"scikit-learn",
"scikit-image"
] |
Reducing dimensions for supervised learning | 37,790,839 | <p>I have this type of numpy array. Here i have shown 2 elements of the array. I have converted a .jpeg file to numpy array.</p>
<pre><code>[[[130 130 130 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
...,
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
[ 68... | -1 | 2016-06-13T13:15:51Z | 37,791,358 | <p>The problem with your code is simple, you are not sending the list in the required format.... The format which <code>.fit</code> requires is a 2 dimensional array. What you are sending is a 3 dimensional... There was no need of using dimensionality reduction because its totally a different issue...(for preventing ov... | 1 | 2016-06-13T13:41:54Z | [
"python",
"numpy",
"scikit-learn",
"scikit-image"
] |
pytest mysql db fixture: cannot create database | 37,790,847 | <p>I'm trying to use <code>mysql</code> from pytest-dbfixtures. I have a test file with example from documentation:</p>
<pre><code>def test_using_mysql(mysql):
mysql.query("SELECT CURRENT_USER()")
</code></pre>
<p>and when I run it via <code>$ py.test test_example.py</code>, I get this error:</p>
<pre><code> ... | 1 | 2016-06-13T13:16:13Z | 37,815,517 | <p>Some info about my set up:</p>
<ul>
<li>Mac OS X 10.11.5 </li>
<li>Python 3.4.4 </li>
<li>MySQL Community Edition 5.7.13</li>
</ul>
<p>I wasn't exactly able to reproduce the issue you are running into, but I think some of the information below should be useful.</p>
<p>Packages required:</p>
<pre><code>pytest==2.... | 0 | 2016-06-14T14:55:34Z | [
"python",
"mysql",
"mysql-python",
"py.test",
"fixtures"
] |
How to download CSV with unicode characters in Django | 37,790,938 | <p>I am downloading and saving in a CSV data using Django but I have problems when the text is not a simple string but Unicode.</p>
<p>This is what I do:</p>
<pre><code>writer = csv.writer(response)
writer.writerow(tuple(corresponding_data[btn]["columns"].split(',')))
for row in rows:
writer.writerow(row)
return ... | 0 | 2016-06-13T13:21:19Z | 37,791,022 | <p>You need to change</p>
<pre><code>writer = csv.writer(response)
</code></pre>
<p>to </p>
<pre><code>writer = csv.writer(response, encoding='utf-8')
</code></pre>
| -1 | 2016-06-13T13:25:53Z | [
"python",
"django",
"csv",
"unicode"
] |
How to download CSV with unicode characters in Django | 37,790,938 | <p>I am downloading and saving in a CSV data using Django but I have problems when the text is not a simple string but Unicode.</p>
<p>This is what I do:</p>
<pre><code>writer = csv.writer(response)
writer.writerow(tuple(corresponding_data[btn]["columns"].split(',')))
for row in rows:
writer.writerow(row)
return ... | 0 | 2016-06-13T13:21:19Z | 37,792,865 | <p>After lot of searching I managed to solve the issue by doing the following:</p>
<pre><code>for row in rows:
field_1 = row[0]
field_2 = row[1].encode(encoding='UTF-8')
fields = [field_1, field_2]
writer.writerows([fields])
</code></pre>
<p>Explanation:
The first column of the CSV contain... | 0 | 2016-06-13T14:51:05Z | [
"python",
"django",
"csv",
"unicode"
] |
Variable checking, something not right | 37,791,034 | <p>I have spent some time searching the internet for sections this code to solve it, however once onto my code it doesn't seem to work. After the program comes to this bit, instead of showing the password strength it comes up with a blank space, no matter what I put in.</p>
<pre><code>if EnteredPassword.isupper() or E... | -3 | 2016-06-13T13:26:36Z | 37,791,213 | <p>There is no else statement in your code.
So in case it does not match any condition it will print nothing</p>
<pre><code>if EnteredPassword.isupper() or EnteredPassword.islower() or EnteredPassword.isdigit():
print ("Your password is weak")
elif EnteredPassword.isupper()and EnteredPassword.islower():
print... | 0 | 2016-06-13T13:35:05Z | [
"python"
] |
weighted average of rows dataframe pandas | 37,791,073 | <p>I would like to the the following more efficiently:</p>
<p>For data collected by "name", "date", "time", and an additional indicator variable "id", I would like to calculate the <strong>daily weighted average</strong> of the column "value", using the column "weights" as the weights in the average, by "id". An examp... | 1 | 2016-06-13T13:28:33Z | 37,791,167 | <p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.html" rel="nofollow"><code>reset_index</code></a> and then substract:</p>
<pre><code>df3 = df1.reset_index()
df3['diff'] = df3['B'] - df3['S']
print (df3)
id name date B S ... | 1 | 2016-06-13T13:33:27Z | [
"python",
"pandas"
] |
Merge width x height x 3 numpy uint8 array into width x height x 1 uint32 array | 37,791,134 | <p>I have a width x height x 3 channel array, like</p>
<pre><code>import numpy as np
aa = np.array(np.random.randint(0, 255, 300), dtype=np.uint8).reshape((10, 10, 3))
</code></pre>
<p>Now, I want to put these numbers in an <code>np.uint32</code> array. I can do it by creating a new array and bitwise shift and or op... | 1 | 2016-06-13T13:31:37Z | 37,791,477 | <p>You can use the <a href="http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.ndarray.view.html" rel="nofollow"><code>.view</code> method</a>:</p>
<pre><code>In [94]: X = numpy.array([10, 2, 4, 8], "uint8")
In [95]: X.view("uint32")
Out[95]: array([134480394], dtype=uint32)
</code></pre>
<p>In your ca... | 1 | 2016-06-13T13:48:11Z | [
"python",
"arrays",
"numpy"
] |
Identify curve in binary image | 37,791,198 | <p>I have a few screenshots from experiments which display curves, and I want to extract that curve into an array to analyze the data.</p>
<p>The first part of my method is to transform the image into a binary one with a well chosen threshold that only leaves the curve. This works fine, but the second part consisting ... | 0 | 2016-06-13T13:34:24Z | 37,814,444 | <p>Thanks guys, the method now works, the solution was in the correct assignation of i and j to their respective dimensions. Thanks to @Matt Cremens for pointing it out.<br>
But the plot thickens, it detects some non-existing pixels, like the ones visibles in the left side of the picture : <a href="http://s31.postimg.o... | 0 | 2016-06-14T14:09:43Z | [
"python",
"python-2.7",
"matplotlib"
] |
Python - Running code over (iterating?) only works once | 37,791,219 | <p>please excuse any errors as this is my first post. </p>
<p>I'm a Computing student and I've missed out on several weeks of teaching so I'm not properly prepared for my task. I'm making a population model which needs to be able to do a number of calculations a variable number of times, then add the result of each ca... | 1 | 2016-06-13T13:35:29Z | 37,791,328 | <p><code>(0, NumberGens)</code> is literally a tuple with two numbers: 0 and whatever NumberGens is. Presumably you actually wanted to iterate over a range from one to the other, in which case you need to use the <code>range</code> function.</p>
<pre><code>for x in range(0, numberGens):
</code></pre>
<p>Note that nor... | 3 | 2016-06-13T13:40:35Z | [
"python",
"list",
"loops",
"iteration",
"python-3.5"
] |
calculate accuracy using r value | 37,791,338 | <p>I'm using a linear regression model to predict the weather data for one year. Prediction is done using Python's <code>sklearn</code> library. The problem is that I need to find the accuracy of the prediction. After a quick internet search I found out that r^2 is the way to find out the accuracy. I calculated the r ... | -3 | 2016-06-13T13:40:54Z | 37,791,723 | <p>Maybe this question is more complicated than I think, but why not just</p>
<pre><code>r = str((r**2) * 100) + '%'
</code></pre>
| 1 | 2016-06-13T14:01:12Z | [
"python",
"scikit-learn"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.