title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Convert RGB triplets to LAB triplets using skimage.color.rgb2lab()
37,504,857
<p>I can convert an image from RGB color space to LAB color space using skimage.color.rgb2lab(). But when I try converting a single RGB triplet to LAB triplet</p> <pre><code>rgb_color = [0.1,0.2,0.3] lab_color = color.rgb2lab(rgb_color) </code></pre> <p>I get the following error:</p> <pre><code>ValueError: the input...
1
2016-05-28T23:59:57Z
37,504,906
<p><code>rgb2lab()</code> expects a 3D (or 4D) image; you're passing it a 1D list of numbers.</p> <p>Try giving it a one-pixel image:</p> <pre><code>&gt;&gt;&gt; from skimage import color &gt;&gt;&gt; rgb_color = [[[0.1,0.2,0.3]]] # Note the three pairs of brackets &gt;&gt;&gt; lab_color = color.rgb2lab(rgb_color) &...
3
2016-05-29T00:09:34Z
[ "python", "python-2.7", "colors" ]
Finding the largest and the smallest in Python 2.7
37,504,860
<p>I had an assignment, where I let users choose random numbers, and this program would find the smallest and the largest between all these numbers, and if a number is not entered it would consider it an invalid input. Here's the code I wrote:</p> <pre><code>largest = None smallest = None while True: inp = raw_input(...
0
2016-05-29T00:00:47Z
37,504,883
<p>You've mixed up <code>&lt;</code> and <code>&gt;</code> and you're comparing <code>inp</code> which is a string to <code>smallest</code> and <code>largest</code> instead of <code>num</code>.</p>
1
2016-05-29T00:05:15Z
[ "python", "python-2.7" ]
Finding the largest and the smallest in Python 2.7
37,504,860
<p>I had an assignment, where I let users choose random numbers, and this program would find the smallest and the largest between all these numbers, and if a number is not entered it would consider it an invalid input. Here's the code I wrote:</p> <pre><code>largest = None smallest = None while True: inp = raw_input(...
0
2016-05-29T00:00:47Z
37,504,911
<p>Your indentation is wrong and you made a lot of misprints. Look at this code. In if-then-else you have to compare <code>num</code> with <code>smallest</code> and <code>largest</code> but not <code>inp</code>.</p> <pre><code>largest = None smallest = None while True: inp = raw_input("Enter a number: ") if ...
1
2016-05-29T00:10:19Z
[ "python", "python-2.7" ]
Split a string within a list python
37,504,960
<p>I have a list in python, which is from a text document that I split at new line characters. The end of data is indicated with <code>#</code> in the text document. I need to count each of element of the list and then split the strings in the list at tab characters, creating a two dimensional list.</p> <p>I thought t...
0
2016-05-29T00:19:26Z
37,504,974
<p>You're just reassigning a local variable. This doesn't affect the contents of the list. Try this:</p> <pre><code>for i, item in enumerate(records): if item != '#': recordcount += 1 records[i] = item.split('\t') </code></pre>
3
2016-05-29T00:21:35Z
[ "python", "arrays", "string", "list" ]
Split a string within a list python
37,504,960
<p>I have a list in python, which is from a text document that I split at new line characters. The end of data is indicated with <code>#</code> in the text document. I need to count each of element of the list and then split the strings in the list at tab characters, creating a two dimensional list.</p> <p>I thought t...
0
2016-05-29T00:19:26Z
37,504,989
<p>You can replace list items in-place, but <code>item = item.split('\t')</code> just re-assigns the local variable <code>item</code>. You can easily replace the list item by e.g. <code>records[index] = item</code>. You can get the right <code>index</code> by using the <a href="https://docs.python.org/3/library/funct...
1
2016-05-29T00:25:23Z
[ "python", "arrays", "string", "list" ]
Read from two serial ports asynchronously
37,505,062
<p>I'd like to read from two (or more) serial ports (/dev/ttyUSB0 etc) at the same time in python on Linux. I want to read complete lines from each port (whichever has data) and process the results in the order received (without race conditions). As a simple example could just write the lines to a single merged file....
0
2016-05-29T00:39:42Z
37,506,560
<p>You could try to take the values in order and memorise it in variables:</p> <pre><code>a = data1.read () b = data2.read () </code></pre> <p>And after process it in order:</p> <pre><code>If len (a) != 0 or len (b ) != 0: Process a Process b </code></pre> <p>Using this method if one or bo...
0
2016-05-29T05:34:18Z
[ "python", "pyserial", "uart" ]
Read from two serial ports asynchronously
37,505,062
<p>I'd like to read from two (or more) serial ports (/dev/ttyUSB0 etc) at the same time in python on Linux. I want to read complete lines from each port (whichever has data) and process the results in the order received (without race conditions). As a simple example could just write the lines to a single merged file....
0
2016-05-29T00:39:42Z
38,672,294
<p>As suggested by @AlexHall in a comment, here is a solution that uses one thread for each serial port and a queue to synchronize access:</p> <pre><code>import serial import Queue import threading queue = Queue.Queue(1000) def serial_read(s): while True: line = s.readline() queue.put(line) seri...
0
2016-07-30T09:14:03Z
[ "python", "pyserial", "uart" ]
MongoDB + K means clustering
37,505,192
<p>I'm using MongoDB as my datastore and wish to store a "clustered" configuration of my documents in a separate collection.</p> <p>So in one collection, I'd have my original set of objects, and in my second, it'd have</p> <pre><code>kMeansCollection: { 1: [mongoObjectCopy1], [mongoObjectCopy2]... 2: [mongo...
2
2016-05-29T01:04:48Z
37,505,318
<p>You would need to have some identifier for the documents. It is probably a good idea to include the <code>_id</code> field in your query so that you do have a unique document identifier. Then you can create parallel lists of <code>ids</code> and <code>tag_data</code>.</p> <pre><code>docs = collection.find({}, {'tag...
3
2016-05-29T01:29:39Z
[ "python", "mongodb", "machine-learning", "scikit-learn", "nltk" ]
MongoDB + K means clustering
37,505,192
<p>I'm using MongoDB as my datastore and wish to store a "clustered" configuration of my documents in a separate collection.</p> <p>So in one collection, I'd have my original set of objects, and in my second, it'd have</p> <pre><code>kMeansCollection: { 1: [mongoObjectCopy1], [mongoObjectCopy2]... 2: [mongo...
2
2016-05-29T01:04:48Z
37,507,083
<p>The efficient way to do this is to use the aggregation framework to create the list of "_id" and "tag-data" using server-side operation. This also reduces both the amount of data sent over the wire and the time and memory used to decode documents on the client-side.</p> <p>You need to <a href="https://docs.mongodb....
1
2016-05-29T06:53:06Z
[ "python", "mongodb", "machine-learning", "scikit-learn", "nltk" ]
add a space between each word in the string
37,505,224
<p>I've been trying to make this more challenging for myself but I couldn't find a way to achieve this goal. So I wonder if its possible to separate words that have no space <code>betweenThemLikeThisJustInASingleString</code> Here's my code:</p> <pre><code>def translate_morse(string): morse_a = { 'a':'.-','b'...
2
2016-05-29T01:11:52Z
37,505,253
<p>If you want to insert a space before every capital letter:</p> <pre><code>import re string = 'betweenThemLikeThisJustInASingleString' print(re.sub('([A-Z])', r' \1', string)) </code></pre> <p>Output:</p> <pre><code>between Them Like This Just In A Single String </code></pre> <p>There's no perfect solution for sp...
2
2016-05-29T01:16:10Z
[ "python" ]
Extract tuple containing 'PERSON' in StanforNER list result
37,505,245
<p>I am trying to create a name filter to filter out names from a given text. I am using the StanfordNER and NLTK to do so and doing this actually gives me a list containing tuples. (As shown below)</p> <pre><code> [(u'I', u'O'), (u'met', u'O'), (u'with', u'O'), (u'Alan', u'PERSON'), (u'yesterday', u'O')] </code></...
0
2016-05-29T01:15:18Z
37,505,274
<pre><code>weird_list = [(u'I', u'O'), (u'met', u'O'), (u'with', u'O'), (u'Alan', u'PERSON'), (u'yesterday', u'O')] for item in weird_list: if 'PERSON' in item: print item[0] #will return item number 1 of the tuple </code></pre> <p>consider reading pythons documentation on <a href="https://docs.python.o...
1
2016-05-29T01:19:58Z
[ "python", "nlp", "nltk", "stanford-nlp" ]
Extract tuple containing 'PERSON' in StanforNER list result
37,505,245
<p>I am trying to create a name filter to filter out names from a given text. I am using the StanfordNER and NLTK to do so and doing this actually gives me a list containing tuples. (As shown below)</p> <pre><code> [(u'I', u'O'), (u'met', u'O'), (u'with', u'O'), (u'Alan', u'PERSON'), (u'yesterday', u'O')] </code></...
0
2016-05-29T01:15:18Z
37,505,308
<pre><code>weird_list = [(u'I', u'O'), (u'met', u'O'), (u'with', u'O'), (u'Alan', u'PERSON'), (u'yesterday', u'O')] for word, tag in weird_list: if tag == 'PERSON': print word </code></pre>
2
2016-05-29T01:26:09Z
[ "python", "nlp", "nltk", "stanford-nlp" ]
Pandas replace full word string
37,505,283
<p>I have a dataframe:</p> <pre><code>df = pd.DataFrame({'id' : ['abarth 1.4 a','abarth 1 a','land rover 1.3 r','land rover 2', 'land rover 5 g','mazda 4.55 bl'], 'series': ['a','a','r','','g', 'bl'] }) </code></pre> <p>I would like to remove the 'series' string from the...
1
2016-05-29T01:21:36Z
37,505,573
<p>You could use <code>str.rpartition</code> to split the <code>id</code>s on the last space.</p> <pre><code>In [169]: parts = df['id'].str.rpartition(' ')[[0,2]]; parts Out[169]: 0 2 0 abarth 1.4 a 1 abarth 1 a 2 land rover 1.3 r 3 land rover 2 4 land rover 5 g 5 ...
1
2016-05-29T02:25:36Z
[ "python", "pandas" ]
Pandas replace full word string
37,505,283
<p>I have a dataframe:</p> <pre><code>df = pd.DataFrame({'id' : ['abarth 1.4 a','abarth 1 a','land rover 1.3 r','land rover 2', 'land rover 5 g','mazda 4.55 bl'], 'series': ['a','a','r','','g', 'bl'] }) </code></pre> <p>I would like to remove the 'series' string from the...
1
2016-05-29T01:21:36Z
37,505,612
<p>Using <code>re</code>, in case you want to specify the <code>series</code> string:</p> <pre><code>df.apply(lambda x: re.sub('\s*{}$'.format(x['series']), '', x['id']), axis=1) </code></pre> <p>In case the the <code>series</code> string is always a predictable pattern (i.e. <code>[a-z]</code>) you can also try:</p>...
1
2016-05-29T02:34:48Z
[ "python", "pandas" ]
How to determine the clockwise order of triangles based on their vertices in Python
37,505,323
<p>I have several instances of Triangle that look something like this: <code>Triangle([1, 3, 2], [30, 40, 90])</code>. The first list are labels for each point, and the second are the angles of the vertices. If I have five triangles like this, how can I tell the clockwise order that they are in? For example,</p> <pr...
0
2016-05-29T01:31:23Z
37,505,665
<p>No. Below are two valid representations of your sample triangles. One is a reflection of the other, and the order of the triangles going clockwise around point 3 is reversed. Thus the problem is ambiguous and more information is needed.</p> <p><a href="http://i.stack.imgur.com/4acO0.png" rel="nofollow"><img src="ht...
1
2016-05-29T02:45:51Z
[ "python", "computational-geometry" ]
Python regex in lists
37,505,398
<p>I have a lists which contains the lists of different softwares that are build in the build-server. I want the specific one only. I have written the regex for it but getting the empty string. The code is here:</p> <pre><code>#!/usr/bin/env python import re lists = ['sw_apple-mc-stded-date.dat', 'sw_apple-mc-prod-da...
-2
2016-05-29T01:47:58Z
37,505,424
<p>I don't know why you are using <code>regex = re.compile('sw_apple-mc-stdeb')</code> when you can simply check if there is a string match withing your list items</p> <pre><code>weird_lists = ['sw_apple-mc-stded-date.dat', 'sw_apple-mc-prod-date.dat', 'sw_android-mc-prod-date.dat', 'sw_android-mc-stded-date.dat'] fo...
1
2016-05-29T01:54:03Z
[ "python", "regex", "list" ]
Python regex in lists
37,505,398
<p>I have a lists which contains the lists of different softwares that are build in the build-server. I want the specific one only. I have written the regex for it but getting the empty string. The code is here:</p> <pre><code>#!/usr/bin/env python import re lists = ['sw_apple-mc-stded-date.dat', 'sw_apple-mc-prod-da...
-2
2016-05-29T01:47:58Z
37,505,523
<p><code>findall()</code> will only return the matching part of the string. The bigger problem is that you are overwriting <code>firmware</code> in every loop iteration, which is why it is empty in the end if there is no match in the last list element:</p> <pre><code>regex = re.compile('sw_apple-mc-stded.*') # add wi...
1
2016-05-29T02:12:45Z
[ "python", "regex", "list" ]
python - split array of objects
37,505,430
<p>I have a data structure that looks like this</p> <pre><code>arrayObjects = [{id: 1, array1: [a,b,c]}, {id: 2, array1: [d,e,f]}] </code></pre> <p>and would like to transform it into this:</p> <pre><code>newArrayObjects = [{id: 1, term: a}, {id:1, term: b}, ... {id:2, term: f} ] </code></pre> <p>any idea on how to...
0
2016-05-29T01:55:12Z
37,505,469
<p>You can use list comprehension:</p> <pre><code>&gt;&gt;&gt; a = [{'id': 1, 'array': ['a','b','c']}, {'id': 2, 'array': ['d','e','f']}] &gt;&gt;&gt; [{'id': d['id'], 'term': v } for d in a for v in d['array']] [{'term': 'a', 'id': 1}, {'term': 'b', 'id': 1}, {'term': 'c', 'id': 1}, {'term': 'd', 'id': 2}, {'term': '...
4
2016-05-29T02:03:14Z
[ "python" ]
iGraph won't plot from function - Python
37,505,487
<p>So I'm setting up iGraph, and I'm having issues with the plot showing up. The simple code is this</p> <pre><code>import iGraph igraph.plot(igraph.Graph.Tree(127,2), layout='tree') </code></pre> <p>this will plot when i type it directly into python compiler (i'm using canopy) But when trying to run it through the i...
0
2016-05-29T02:07:12Z
37,516,248
<p>The Canopy GUI's default graphical backend is Qt. Most likely igraph uses a different graphical backend which conflicts with Qt. Try disabling Canopy's default Pylab mode in the Preferences dialog (Python tab). For more information, see <a href="https://support.enthought.com/hc/en-us/articles/204469880" rel="nofollo...
0
2016-05-30T00:34:24Z
[ "python", "igraph", "canopy" ]
CParserError: Error tokenizing data
37,505,577
<p>I'm having some trouble reading a csv file </p> <pre><code>import pandas as pd df = pd.read_csv('Data_Matches_tekha.csv', skiprows=2) </code></pre> <p>I get </p> <blockquote> <p>pandas.io.common.CParserError: Error tokenizing data. C error: Expected 1 fields in line 526, saw 5</p> </blockquote> <p>and when I ...
1
2016-05-29T02:25:55Z
37,506,472
<p>In your actual code, the line is:</p> <pre><code>&gt;&gt;&gt; pandas.read_csv("Data_Matches_tekha.xlsx", sep=None) </code></pre> <p>You are trying to read an Excel file, and not a plain text CSV which is why things are not working.</p> <p>Excel files (xlsx) are in a special binary format which cannot be read as s...
1
2016-05-29T05:17:40Z
[ "python", "csv", "pandas", "dataframe", "data-analysis" ]
CParserError: Error tokenizing data
37,505,577
<p>I'm having some trouble reading a csv file </p> <pre><code>import pandas as pd df = pd.read_csv('Data_Matches_tekha.csv', skiprows=2) </code></pre> <p>I get </p> <blockquote> <p>pandas.io.common.CParserError: Error tokenizing data. C error: Expected 1 fields in line 526, saw 5</p> </blockquote> <p>and when I ...
1
2016-05-29T02:25:55Z
37,506,499
<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html" rel="nofollow"><code>read_excel</code></a> instead <code>read_csv</code> if <code>Excel</code> file:</p> <pre><code>import pandas as pd df = pd.read_excel("Data_Matches_tekha.xlsx") </code></pre>
1
2016-05-29T05:23:02Z
[ "python", "csv", "pandas", "dataframe", "data-analysis" ]
Python 3.x Reading files with headers (data between identified headers)
37,505,619
<p>I'm using Python 3.4, and I have NunPy/SciPy already installed. I need to read a text file with the following structure:</p> <pre><code>*Node 1, -0.600000024, 1.20000005, 0. 2, -0.600000024, 0.300000012, 0. 3, -0.480560571, 0.1741862, 0. 4, -0.335430175, 0.0791868418, ...
2
2016-05-29T02:36:04Z
37,505,854
<p>Creating a list with the lines in your file, then creating sub lists starting and stopping at the <code>index</code> if <code>'*Node'</code> and <code>'*Element'</code> should work for you:</p> <pre><code>r=[] s = open('File.txt') For line in s: r.append(line.strip('\n')) Node=[] Element=[] For i in r[r.index('*N...
2
2016-05-29T03:23:42Z
[ "python", "numpy", "matrix", "text", "abaqus" ]
Python 3.x Reading files with headers (data between identified headers)
37,505,619
<p>I'm using Python 3.4, and I have NunPy/SciPy already installed. I need to read a text file with the following structure:</p> <pre><code>*Node 1, -0.600000024, 1.20000005, 0. 2, -0.600000024, 0.300000012, 0. 3, -0.480560571, 0.1741862, 0. 4, -0.335430175, 0.0791868418, ...
2
2016-05-29T02:36:04Z
37,506,217
<p><a href="http://stackoverflow.com/a/37505854/1594060">@EoinS</a> has an excellent solution, I wanted to present an alternative that is less dynamic in terms of figuring out where the two lists type begin and end but will handle the various edge cases in CSV formatting and has column names is the following:</p> <pre...
0
2016-05-29T04:34:58Z
[ "python", "numpy", "matrix", "text", "abaqus" ]
Changing marker colour on selection in matplotlib
37,505,674
<p>I'm using matplotlib and I am trying to change the colour of a marker when it is selected. So far I am plotting the markers and adding a <code>pick_event</code> listener that calls an <code>on_pick</code> function, which then modifies the plot's marker properties. This isn't working because I can't figure out how to...
1
2016-05-29T02:46:54Z
37,505,901
<p>This wasn't working because I didn't update the plot using plt.show() and used the incorrect getter method. Here's the correct code:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import interp1d #----------------------------------------------- # Plots several points with ...
1
2016-05-29T03:34:08Z
[ "python", "matplotlib" ]
Changing marker colour on selection in matplotlib
37,505,674
<p>I'm using matplotlib and I am trying to change the colour of a marker when it is selected. So far I am plotting the markers and adding a <code>pick_event</code> listener that calls an <code>on_pick</code> function, which then modifies the plot's marker properties. This isn't working because I can't figure out how to...
1
2016-05-29T02:46:54Z
37,505,998
<p>You can use setp method to manipulate the plot elements and update the cavas. This works:</p> <h2>Code:</h2> <pre><code>import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import interp1d #----------------------------------------------- # Plots several points with cubic interpolation #------...
1
2016-05-29T03:53:32Z
[ "python", "matplotlib" ]
Multiple route mapping to different matplotlib graphs in flask app
37,505,696
<p>I have this "flask app" with two links, each mapping to different matplotlib visualizations, for example: localhost:5000/line_chart and localhost:5000/bar_chart. </p> <p>When I start the server, and click the a route (any of them), I see what I expect.</p> <p>localhost:5000/bar_chart</p> <p><a href="http://i.stac...
0
2016-05-29T02:51:16Z
37,506,134
<p>I guess you need two figures, test this code and tell what happened:</p> <pre><code>@app.route('/bar_chart') def bar_chart(): movies = ["Annie Hall", "Ben-Hur", "Casablanca", "Gandhi", "West Side Story"] num_oscars = [5, 11, 3, 8, 10] # bars are by default width 0.8, so we'll add 0.1 to the left c...
1
2016-05-29T04:23:18Z
[ "python", "matplotlib", "flask" ]
Tensor flow CIFAR10 tutorial: where are image files saved?
37,505,729
<p>I have successfully ran <a href="https://github.com/tensorflow/tensorflow/tree/master/tensorflow/models/image/cifar10" rel="nofollow">Tensorflow's tutorial on the CIFAR10 dataset</a>.</p> <p>However I am unable of identifying the location on my computer to which the CIFAR10 files were downloaded.</p> <p>In the <co...
0
2016-05-29T02:59:26Z
37,508,844
<p><code>/tmp</code> is hidden in Finder by default. </p> <p>Open up Terminal, execute <code>open /tmp</code> and you'll get a Finder window.</p> <p>To show hidden files always, <a href="http://apple.stackexchange.com/questions/5870/how-to-show-hidden-files-and-folders-in-finder">http://apple.stackexchange.com/quest...
1
2016-05-29T10:34:23Z
[ "python", "tensorflow" ]
What does _constructor do in DataFrame class
37,505,784
<p>I'm trying to learn what's under the hood in the pandas library and I am curious about a specific piece of code in the DataFrame class. The following code appears in the class module.</p> <pre><code>@property def _constructor(self): return DataFrame _constructor_sliced = Series </code></pre> <p>Looking at the...
1
2016-05-29T03:09:48Z
37,506,199
<p><code>_constructor(self)</code> is a private member function that returns an empty <code>DataFrame</code> object. This is useful when the result of an operation creates a new <code>DataFrame</code> object. </p> <p>For example, the <code>dot()</code> member function that does matrix multiplication with another <code...
2
2016-05-29T04:32:52Z
[ "python", "pandas" ]
Python-Jira create issue giving Screen error
37,505,917
<p>I am using Jira library with Python to create Jira-issue but getting below error:</p> <blockquote> <p>jira.exceptions.JIRAError: JiraError HTTP 400</p> <p>text: Field 'Component/s' cannot be set. It is not on the appropriate screen, or unknown.</p> <p>url: <a href="http://jira.corp.inmobi.com/rest/api/2...
0
2016-05-29T03:38:19Z
37,506,698
<p>Jira is complaining about the unexpected backslash in <code>'Component\s'</code>.</p> <p>Change it to:</p> <p><code>'components: [{'name' : "ABC"}]'</code></p> <p>and it should solve your issue (pun intended).</p>
0
2016-05-29T05:56:20Z
[ "python", "jira-rest-api", "python-jira" ]
Login form doesn't render for custom Django login page
37,505,957
<p>Django newbie here trying to create a custom login form, view and template. My problem is that the logic in my view is causing the form to not be displayed, and instead, the error message from the else statement always shows up. I'm sure I'm missing something, I just have no idea what it is. Can anyone point me in t...
2
2016-05-29T03:46:51Z
37,506,655
<p>It seems the execution never reaches the last <code>return</code> statement because it is either satisfying <code>if</code> condition, else it returns the <code>Invalid Login</code> response.</p> <pre><code>if user is not None and user.is_active: auth.login(request, user) return HttpResponseRedirect("client...
3
2016-05-29T05:49:20Z
[ "python", "html", "django" ]
Error importing numpy & graphlab after installing ipython
37,505,970
<p>I have got a strange issue.</p> <p>I am now using graphlab/numpy to develop a project via Pycharm 5. OS is Mac OS 10.11.5. I created a p2.7 virtual environment for the project. Programme runs well. But after I install ipython, I can no longer import graphlab and numpy correctly.</p> <p>Error message:</p> <blockqu...
0
2016-05-29T03:49:24Z
37,531,473
<p>Please remember that console applications and GUI application do not share the same environment on OS X. </p> <p>This also means that if you install a Python package from the console, this would probably not be visible to PyCharm. </p> <p>Usually you need to install packages using PyCharm in order to be able to us...
0
2016-05-30T18:06:04Z
[ "python", "python-2.7", "ipython", "graphlab" ]
Error importing numpy & graphlab after installing ipython
37,505,970
<p>I have got a strange issue.</p> <p>I am now using graphlab/numpy to develop a project via Pycharm 5. OS is Mac OS 10.11.5. I created a p2.7 virtual environment for the project. Programme runs well. But after I install ipython, I can no longer import graphlab and numpy correctly.</p> <p>Error message:</p> <blockqu...
0
2016-05-29T03:49:24Z
37,638,250
<p><a href="http://forum.dato.com/discussion/comment/3986/#Comment_3986" rel="nofollow">Upgrading pip itself then reinstalling worked for me</a></p>
0
2016-06-05T03:43:15Z
[ "python", "python-2.7", "ipython", "graphlab" ]
How to keep writing in a moved file with the same file object?
37,506,058
<p>If I open a file </p> <pre><code>fileObj = open(test.txt, 'wb+') </code></pre> <p>and write some stuff in it</p> <pre><code>fileObj.write(someBytes) </code></pre> <p>then decide to move it somewhere else</p> <pre><code>shutil.move('test.txt', '/tempFolder') </code></pre> <p>and then keep writing in it</p> <pr...
0
2016-05-29T04:07:22Z
37,506,114
<p>after moving your file shutil.move('test.txt', '/tempFolder'), and want to continue adding bytes to it, you will need to create a new variable, indicating the new file location.</p> <p>Since you moved the file to a new locations, fileObj.write(someMoreBytes) is not writing bytes anymore since the object you origina...
0
2016-05-29T04:20:04Z
[ "python", "file-io", "filesystems", "python-3.5", "file-move" ]
How to keep writing in a moved file with the same file object?
37,506,058
<p>If I open a file </p> <pre><code>fileObj = open(test.txt, 'wb+') </code></pre> <p>and write some stuff in it</p> <pre><code>fileObj.write(someBytes) </code></pre> <p>then decide to move it somewhere else</p> <pre><code>shutil.move('test.txt', '/tempFolder') </code></pre> <p>and then keep writing in it</p> <pr...
0
2016-05-29T04:07:22Z
37,506,369
<p>fobject does not know that you moved the file. You could do this by adding </p> <pre><code>fileObj = open("tempFolder/test.txt", "wb+") </code></pre> <p>after the move. </p>
0
2016-05-29T05:02:00Z
[ "python", "file-io", "filesystems", "python-3.5", "file-move" ]
Sprite jumping way too high
37,506,089
<p>Earlier, we fixed the lag of the code and before, the game made the sprite lag. We fixed that, but this time it keeps making the sprite fly way too high and out of the screen not coming back down... What can we do so that the sprite(poppy) does not jump so high? </p> <pre><code>import pygame, sys from pygame.loca...
0
2016-05-29T04:14:48Z
37,506,223
<p>You've set the gravity at 0.5 units/second^2, but jump at a velocity of -50 units/second; it will take nearly two minutes for the character to start falling again!</p> <p>Either increase the gravity, or decrease the velocity of the jump to something like -3.</p> <p>EDIT:</p> <p>Call this function somewhere in you...
1
2016-05-29T04:35:49Z
[ "python", "pygame", "sprite", "platform" ]
Python Imaging Library makes an image reddish
37,506,096
<p>I have opened a grayscale image using the Python Imaging Library, copied every pixel value into another image variable of same size and saved it. Now when I open the new image with an image viewer it looks reddish. I have used the Image.new() method with and without the "white" and "black" arguments got the same red...
1
2016-05-29T04:16:18Z
37,507,104
<p>Your problem is that you want to create an RGB image which has three channels. Therefore one pixel value consists of three values and not only one (in your case use the gray value of the original image for each of the channels).</p> <p>I have modified the code accordingly.</p> <p>A side remark: I am almost sure th...
2
2016-05-29T06:56:24Z
[ "python", "image", "python-2.7", "image-processing", "graphics" ]
Adding an item in matplotlib´s toolbar
37,506,260
<p>I created a matplotlib´s figure in a <code>QMainWindow</code>, using PyQt and I am trying to add a button to the matplotlib´s toolbar in my code. This is the <code>NavigationToolbar</code> that I created:</p> <p><a href="http://i.stack.imgur.com/tOYI0.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/tOYI0.j...
1
2016-05-29T04:45:15Z
37,513,382
<p>I have solved the problem. I´ ve found this code:</p> <p><a href="http://www.scriptscoop2.com/t/c9dc65f6cba9/python-matplotlib-tkinter-customizing-toolbar-tooltips.html" rel="nofollow">Matplotlib/Tkinter - customizing toolbar tooltips</a></p> <p>So, I created a subclass and added as it says in the link. This is t...
1
2016-05-29T18:22:01Z
[ "python", "matplotlib", "pyqt4" ]
Triangulation of a polygon using matplotlib
37,506,315
<p>I've tried to use the matplot.Delaunay for the triangulation of a simple polygon in 2D... The problem here is that I need regular triangles. The polygon is randomly created by numpy, maybe Delaunay it's not the way to go.</p> <pre><code>import matplotlib.delaunay as triang import pylab import numpy # 10 random poi...
0
2016-05-29T04:53:57Z
37,506,591
<p>I guess, triangulation by regular triangles is not a trivial task for a random polygon. However if you want to use only regular triangles, you have to define points' coordinate manually. Like in this example:</p> <pre><code>import matplotlib.pyplot as plt import matplotlib.tri as tri import numpy as np import math ...
0
2016-05-29T05:40:36Z
[ "python", "matplotlib", "2d", "polygon", "triangulation" ]
Python/Pandas Dataframe replace 0 with median value
37,506,488
<p>I have a python pandas dataframe with several columns and one column has <code>0</code> values. I want to replace the <code>0</code> values with the <code>median</code> or <code>mean</code> of this column. </p> <p><code>data</code> is my dataframe<br> <code>artist_hotness</code> is the column</p> <pre><code>mean_a...
2
2016-05-29T05:21:26Z
37,506,559
<p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.mask.html" rel="nofollow"><code>mask</code></a> and add parameter <code>skipna=True</code> to <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.mean.html" rel="nofollow"><code>mean</code></a> i...
2
2016-05-29T05:34:07Z
[ "python", "pandas", "dataframe", "mean", "median" ]
Python/Pandas Dataframe replace 0 with median value
37,506,488
<p>I have a python pandas dataframe with several columns and one column has <code>0</code> values. I want to replace the <code>0</code> values with the <code>median</code> or <code>mean</code> of this column. </p> <p><code>data</code> is my dataframe<br> <code>artist_hotness</code> is the column</p> <pre><code>mean_a...
2
2016-05-29T05:21:26Z
37,506,673
<p>use <code>pandas</code> <code>replace</code> method:</p> <pre><code>df = pd.DataFrame({'a': [1,2,3,4,0,0,0,0], 'b': [2,3,4,6,0,5,3,8]}) df a b 0 1 2 1 2 3 2 3 4 3 4 6 4 0 0 5 0 5 6 0 3 7 0 8 df['a']=df['a'].replace(0,df['a'].mean()) df a b 0 1 2 1 2 3 2 3 4 3 4 6 4 1 0 5 1 5...
1
2016-05-29T05:53:32Z
[ "python", "pandas", "dataframe", "mean", "median" ]
Python/Pandas Dataframe replace 0 with median value
37,506,488
<p>I have a python pandas dataframe with several columns and one column has <code>0</code> values. I want to replace the <code>0</code> values with the <code>median</code> or <code>mean</code> of this column. </p> <p><code>data</code> is my dataframe<br> <code>artist_hotness</code> is the column</p> <pre><code>mean_a...
2
2016-05-29T05:21:26Z
37,506,814
<pre><code>data['artist_hotness'] = data['artist_hotness'].map( lambda x : data.artist_hotness.mean() if x == 0 else x) </code></pre>
1
2016-05-29T06:14:01Z
[ "python", "pandas", "dataframe", "mean", "median" ]
how to make a raw_input call a function
37,506,493
<p>I'm tinkering with a game by my own creation and I came across this problem. I am making the game in a very interactive fiction style but I can't make raw_input call a function like <code>take sword</code> to <code>take(sword, room)</code> to remove it from <code>room</code> and into <code>inventory</code>. First h...
0
2016-05-29T05:21:43Z
37,506,540
<p>It looks like you're doing pretty well. I'm not sure if I'm understanding completely, but I think you want to be keeping track of the current room that the user is in (I'm not sure if you're doing that already, it hasn't been specified). Once you do that, you already have the user's input stored in <code>a</code>.</...
1
2016-05-29T05:31:05Z
[ "python", "list", "function", "raw-input" ]
jquery/ajax autologin to website
37,506,597
<p>I have this code in python :</p> <pre><code>import requests session=requests.Session() def login_mps_api(username, password): MyHeaderss = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.32 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.32", "X-GWT-Permutation" : "6FEFBE57C...
0
2016-05-29T05:41:08Z
37,507,008
<p><strong>UPDATED</strong></p> <p>here's how you go about it:</p> <pre><code>var MyHeaderss = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.32 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.32", "X-GWT-Permutation" : "6FEFBE57C6E73F0AB33BD5A4E17945DE", "Content-Type":"...
1
2016-05-29T06:40:18Z
[ "javascript", "jquery", "python", "ajax" ]
can I add message to the tqdm progressbar
37,506,645
<p>When using the tqdm progress bar: can I add message to the same line as the progress bar, while in a loop. I tried using the "tqdm.write" option, but it adds new line on every write. I would like that each iteration will show a short message next to the bar, that will disappear in the next iteration. Is it possible?...
3
2016-05-29T05:47:43Z
37,523,994
<p>You can change the description to show a small message before the progress bar, like this:</p> <pre><code>from tqdm import trange from time import sleep t = trange(100, desc='Bar desc', leave=True) for i in t: t.set_description("Bar desc (file %i)" % i) sleep(0.01) </code></pre>
3
2016-05-30T10:59:04Z
[ "python", "tqdm" ]
I am getting urllib2.HTTPError: HTTP Error 502: Bad Gateway
37,506,648
<p>/* Iam getting urllib2.HTTPError: HTTP Error 502: Bad Gateway.*/</p> <pre><code>import urllib2 import json # locu_api = 'd1dab0b393b10f56532cacf6835d2619973f5f46' url = 'http://cricapi.com/api/cricketNews' /*The above url is used from cricapi.com*/ str = "" json_obj = urllib2.urlopen(url) data = json.load(json_...
1
2016-05-29T05:48:11Z
37,506,765
<blockquote> <p>HTTP Error 502: Bad Gateway</p> </blockquote> <p>This problem is due to poor IP communication between back-end computers, possibly including the server at the site you are trying to visit. It may be that the server is overloaded, if you had visited it last week.</p>
0
2016-05-29T06:06:36Z
[ "python", "json", "url" ]
I am getting urllib2.HTTPError: HTTP Error 502: Bad Gateway
37,506,648
<p>/* Iam getting urllib2.HTTPError: HTTP Error 502: Bad Gateway.*/</p> <pre><code>import urllib2 import json # locu_api = 'd1dab0b393b10f56532cacf6835d2619973f5f46' url = 'http://cricapi.com/api/cricketNews' /*The above url is used from cricapi.com*/ str = "" json_obj = urllib2.urlopen(url) data = json.load(json_...
1
2016-05-29T05:48:11Z
38,451,087
<p>Karthi, the problem you state is common for a lot of API providers. What happens is if the server load exceeds capacity for that instant, you may get a 502 from the reverse proxy and thus experience an error situation.</p> <p>The recommended way to get around this is to have a retry count. For example</p> <pre><co...
0
2016-07-19T06:33:29Z
[ "python", "json", "url" ]
How to make a pygame sprite group move?
37,506,758
<p>I made a pygame.sprite.group for my enemies. I can display them on the screen, but I don't know how to make them all move? I want to have them pacing back and forth on the platforms (like left and right constantly). I know how to work with the movements of one sprite, but not a bunch in a group. </p> <p>Here is ...
1
2016-05-29T06:05:53Z
38,275,787
<p>I would introduce 2 new attributes to your Enemy class: <em>dx</em> and <em>platform</em>. <em>dx</em> being the current speed in the x direction and <em>platform</em> being the platform the enemy is on. You'll have to pass the platform as an argument to your enemy object, which shouldn't be a problem (just pass it ...
0
2016-07-08T21:41:52Z
[ "python", "pygame", "sprite", "group", "move" ]
Pythonic way to lag datetime-indexed columns
37,506,778
<p>I have dataframes with DateTime indices of various types (could be weekly, monthly, annual data). I want to generate columns that are lagged values of other columns. I get these imported from a spreadsheet, I'm not generating the datetime index inside python.</p> <p>I'm struggling to find the 'pythonic' way of do...
5
2016-05-29T06:08:28Z
37,506,895
<p>There is another problem - many <code>NaT</code> in index in <code>toy</code> <code>DataFrame</code>, so <code>index</code> has duplicates values. (Maybe some datetime are duplicated too.)</p> <p>Sample:</p> <pre><code>import pandas as pd import numpy as np rng = pd.date_range('2012-01-01', '2013-1-01', freq="M")...
2
2016-05-29T06:24:21Z
[ "python", "datetime", "pandas" ]
Selenium python clicking on button trouble
37,506,787
<p>I new with selenium, and I am having particular trouble with this button I've tried(submit and click):</p> <pre><code>driver.find_element_by_id("btn").clcik; driver.find_element_by_class_name("eh_prev_img").click </code></pre> <p>The two above find the element though for some reason the click does not work, the ht...
-1
2016-05-29T06:09:41Z
37,506,852
<p>try .click()</p> <p>Look for more examples at <a href="http://selenium-python.readthedocs.io/faq.html" rel="nofollow">http://selenium-python.readthedocs.io/faq.html</a> </p>
0
2016-05-29T06:19:23Z
[ "python", "selenium" ]
How to find word after match containing Swedish characters in python 2.7
37,506,804
<p>For a few days i have been struggling to get a function to work. I want to search for the word "Ort : " ( ort = city in English) and get the word after that. Works great with words without Swedish åäö. It doesn't matter if i read a line from a file written windows machine or i create a file with vim. It the "Ort"...
0
2016-05-29T06:12:01Z
37,507,021
<p>I have taken the liberty to cut down your example according to <a href="http://stackoverflow.com/help/mcve">http://stackoverflow.com/help/mcve</a> </p> <p>For your problem, try this:</p> <pre><code>#!/usr/bin/env python # -*- coding: utf-8 -*- import re line="Brand i byggnad Ort : Örebro alla ute" # Find word...
0
2016-05-29T06:41:56Z
[ "python", "regex", "python-2.7", "character-encoding" ]
How to find word after match containing Swedish characters in python 2.7
37,506,804
<p>For a few days i have been struggling to get a function to work. I want to search for the word "Ort : " ( ort = city in English) and get the word after that. Works great with words without Swedish åäö. It doesn't matter if i read a line from a file written windows machine or i create a file with vim. It the "Ort"...
0
2016-05-29T06:12:01Z
37,532,901
<p>This answer from worked very well</p> <h1>!/usr/bin/env python</h1> <pre><code># -*- coding: utf-8 -*- import re line="Brand i byggnad Ort : Örebro alla ute" # Find word after Ort : ort = re.search('Ort : (.*)', line) print ort.groups()[0].split(' ')[0] </code></pre> <p>My day is saved!! Best regards Stefan<...
0
2016-05-30T19:58:56Z
[ "python", "regex", "python-2.7", "character-encoding" ]
syntax_error:update for dictionary
37,506,824
<p>How can I fix this?</p> <pre><code># E.g. word_count("I am that I am") gets back a dictionary like: # {'i': 2, 'am': 2, 'that': 1} # Lowercase the string to make it easier. # Using .split() on the sentence will give you a list of words. # In a for loop of that list, you'll have a word that you can # check for inclu...
1
2016-05-29T06:15:57Z
37,506,839
<p>To update a key in a dictionary, just assign to the key using <code>[...]</code> subscription syntax:</p> <pre><code>word_dict[word] = word_dict[word] + 1 </code></pre> <p>or even</p> <pre><code>word_dict[word] += 1 </code></pre> <p>Your attempt is not valid syntax, for two reasons:</p> <ul> <li><code>word_dict...
2
2016-05-29T06:17:38Z
[ "python", "string", "dictionary" ]
syntax_error:update for dictionary
37,506,824
<p>How can I fix this?</p> <pre><code># E.g. word_count("I am that I am") gets back a dictionary like: # {'i': 2, 'am': 2, 'that': 1} # Lowercase the string to make it easier. # Using .split() on the sentence will give you a list of words. # In a for loop of that list, you'll have a word that you can # check for inclu...
1
2016-05-29T06:15:57Z
37,507,068
<p>You can implement using <code>dict.update</code>. Here is an example for <code>dict.update</code></p> <pre><code>In [74]: test_dict = {1:'apple',2:'grapes'} In [75]: test_dict.update({3:'orange'}) In [76]: test_dict Out[76]: {1: 'apple', 2: 'test', 3: 'orange'} </code></pre> <p>For your problem change your code li...
1
2016-05-29T06:48:59Z
[ "python", "string", "dictionary" ]
Combining two lists of names and sorting them to make one sorted list of names
37,507,001
<p>The problem that I am currently working on is this:</p> <p>I want to write a function called combine(L1, L2) that takes two sorted lists as input, combines all the elements in the two lists into one sorted list, and then returns that list. For example,</p> <pre><code> L1 = ["Alice", "Bob", "Charlie", "Eve"] ...
-1
2016-05-29T06:39:18Z
37,511,705
<p>You have probably already figured it out, but this is one way you can go about it:</p> <pre><code> L1 = ["Alice", "Bob", "Charlie", "Eve"] L2 = ["Adam", "Chloe", "David"] def merge_sorted_lists(L1, L2): sorted_list = [] # Copy both arg lists to make sure original lists are not ...
0
2016-05-29T15:32:17Z
[ "python", "list", "sorting" ]
Django ) Postgresql model ERROR
37,507,160
<p>In models.py in my app of django, I have a model below : </p> <pre><code>from django.db import models from django.contrib.postgres.fields import * class lkmModel(models.Model): #Profile Image profileUrls = ArrayField(base_field=models.TextField,size=5) #profileUrls = models.TextField() """profileU...
0
2016-05-29T07:04:39Z
37,507,631
<p>None of this has anything whatsoever to do with the code you've posted.</p> <p>You are presumably doing this in a plain Python shell; you should start up the Django shell with <code>python manage.py shell</code> instead.</p>
0
2016-05-29T08:10:02Z
[ "python", "django", "postgresql", "django-models" ]
FLASK - Running Python Scripts
37,507,240
<p>I have made a webpage using bootstrap which is hosted on a raspberry pi. What I would like to do is to, when a certain button is clicked, is to run a python script. This is all being hosted/run/accessed through a FLASK hosting service.</p> <p>Thank you for your time.</p>
-2
2016-05-29T07:17:18Z
37,513,011
<p><a href="http://stackoverflow.com/questions/36713877/run-python-method-in-html-web-page/37512973#37512973">Run python method in HTML web page</a></p> <p>I also encountered same issue, and I solved it really easily using this way. (I answered on my own question in that link) </p> <p>Just redirect button to go any l...
0
2016-05-29T17:47:15Z
[ "python", "html", "button", "flask", "raspberry-pi" ]
Function in view takes 1 positional argument but 2 were given during redirection
37,507,245
<p>So I have the following code in my view for redirection</p> <p><strong>View file:</strong></p> <pre><code>def signIn(request): .... .... return HttpResponseRedirect("/admin_page") </code></pre> <p>Now the <code>admin_page</code> is mapped in the url as such</p> <pre><code>url(r'(admin_page)$',"adminA...
0
2016-05-29T07:17:26Z
37,507,260
<p>You don't need the parentheses in this url:</p> <pre><code>url(r'(admin_page)$',"adminApp.views.show_admin_page"), </code></pre> <p>As, you can see in the <a href="https://docs.djangoproject.com/en/1.9/topics/http/urls/#example" rel="nofollow">examples</a> here:</p> <blockquote> <p>To capture a value from the U...
1
2016-05-29T07:19:47Z
[ "python", "django" ]
python numpy array append not working in .py file, but works in terminal
37,507,247
<p>I am trying to append to a numpy array using np.append.</p> <p>For example,</p> <pre><code>a = np.array([1]) np.append(a, [2]) </code></pre> <p>this code works well in terminal (the result is array([1, 2])), but it won't work when I run a .py file including the same code included in it. When I print a after appe...
2
2016-05-29T07:18:07Z
37,507,315
<p>Are you sure that the version of numpy used within your terminal and for the execution of your .py file the same? According to <a href="http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.append.html" rel="nofollow">http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.append.html</a> np.appe...
2
2016-05-29T07:26:01Z
[ "python", "arrays", "numpy", "append" ]
python numpy array append not working in .py file, but works in terminal
37,507,247
<p>I am trying to append to a numpy array using np.append.</p> <p>For example,</p> <pre><code>a = np.array([1]) np.append(a, [2]) </code></pre> <p>this code works well in terminal (the result is array([1, 2])), but it won't work when I run a .py file including the same code included in it. When I print a after appe...
2
2016-05-29T07:18:07Z
37,507,889
<pre><code>import numpy as np a = np.array([1]) print(a) a = np.append(a, [2]) print(a) </code></pre> <p><code>numpy.append(arr, values, axis=None)</code>, where <code>arr</code> is values are appended to a <strong>copy of this array</strong> (<a href="http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.a...
2
2016-05-29T08:42:01Z
[ "python", "arrays", "numpy", "append" ]
python numpy array append not working in .py file, but works in terminal
37,507,247
<p>I am trying to append to a numpy array using np.append.</p> <p>For example,</p> <pre><code>a = np.array([1]) np.append(a, [2]) </code></pre> <p>this code works well in terminal (the result is array([1, 2])), but it won't work when I run a .py file including the same code included in it. When I print a after appe...
2
2016-05-29T07:18:07Z
37,514,253
<p>You're misunderstanding what the terminal is doing. When you write the following in a terminal:</p> <pre><code>&gt;&gt;&gt; a = np.array([1]) &gt;&gt;&gt; np.append(a, [2]) array([1, 2]) </code></pre> <p>You obviously didn't ask it to print, but it does. So the terminal must have inserted a print statement. The te...
1
2016-05-29T19:49:50Z
[ "python", "arrays", "numpy", "append" ]
Python and IronPython communication inquiry
37,507,283
<p>Purpose of this program is to control two measurement instruments through GPIB using Python. </p> <p><strong>Inst_A</strong>: controlled with CPython and PyVISA (Not yet available in IronPython).<br> <strong>Inst_B</strong>: controlled through DLL library provided by manufacturer; IronPython and its <code>__import ...
0
2016-05-29T07:22:13Z
37,511,881
<p>As per <a href="http://stackoverflow.com/questions/37507283/python-and-ironpython-communication-inquiry#comment62516440_37507283">my comment</a>, I'll focus on your last question: <strong>Preferrable ways to IPC between Python and IronPython.</strong></p> <p>First of all, any IPC involves two things:</p> <ul> <li>...
0
2016-05-29T15:48:36Z
[ "python", ".net", "ironpython", "measurement", "python.net" ]
Python and IronPython communication inquiry
37,507,283
<p>Purpose of this program is to control two measurement instruments through GPIB using Python. </p> <p><strong>Inst_A</strong>: controlled with CPython and PyVISA (Not yet available in IronPython).<br> <strong>Inst_B</strong>: controlled through DLL library provided by manufacturer; IronPython and its <code>__import ...
0
2016-05-29T07:22:13Z
37,517,932
<p>According to <strong>denfromufa</strong> and <a href="http://stackoverflow.com/a/27161639/2137550">this thread</a>, all that was required was to add path of DLL prior to adding the reference (not necessary in IronPython),</p> <pre><code>import clr import os import sys sys.path.append(os.path.dirname('__file__')) </...
1
2016-05-30T05:05:30Z
[ "python", ".net", "ironpython", "measurement", "python.net" ]
Django text game trade table
37,507,368
<p>I'm creating web text game in Django. I'd like to give user option to trade his pets with bank. Exchange table is static and cannot be modified.</p> <blockquote> <p>1 sheep = 6 rabbits</p> <p>1 pig = 2 sheep = 12 rabbits = 1 sheep + 6 rabbits</p> <p>1 cow = 3 pig = 6 sheeps = 36 rabbit etc.</p> </blockq...
0
2016-05-29T07:32:47Z
37,507,816
<p>List item</p> <p>If the table is static then it can be use as a simple dict</p> <p>Here is an example code of you may approach this problem</p> <pre><code>from collections import Counter # 1 sheep = 6 rabbits # # 1 pig = 2 sheep = 12 rabbits = 1 sheep + 6 rabbits # # 1 cow = 3 pig = 6 sheeps = 36 rabbit etc. ...
0
2016-05-29T08:33:24Z
[ "python", "django", "algorithm" ]
Django py.test run on real database?
37,507,458
<p>py.test sets up a test database. </p> <p>I'd like to use the real database set in settings.py file.<br> (Since I'm on test machine with test data already) </p> <p>Would it be possible?</p>
0
2016-05-29T07:46:34Z
37,513,426
<p>yeah you can override the settings on the setUp set the real database for the tests and load your databases fixtures.. but I think, it`s not a good pratice, since you want to run yours tests without modify your "real" app env.</p> <p>you should try the pytest-django. </p> <p>with this lib you can reuse, create dr...
0
2016-05-29T18:26:03Z
[ "python", "django", "py.test" ]
Django py.test run on real database?
37,507,458
<p>py.test sets up a test database. </p> <p>I'd like to use the real database set in settings.py file.<br> (Since I'm on test machine with test data already) </p> <p>Would it be possible?</p>
0
2016-05-29T07:46:34Z
37,513,622
<p>I think <a href="http://stackoverflow.com/users/4488148/ederson-badeca">Ederson Badeca</a> right, you shouldn't use your project_db as test_db. Instead i would propose creating copy of current project_db on database setup and running tests against it instead. In django tests you would need to create custom test runn...
2
2016-05-29T18:48:11Z
[ "python", "django", "py.test" ]
I am trying to extract data from mongodb using bottle in python and use d3.js to visualize it: Mongodb-->Python-->d3.js
37,507,576
<pre><code>import bottle, pymongo from pymongo import MongoClient client = pymongo.MongoClient(some URI) db = client['database'] dbcoll = db['collection'] @bottle.route('/hello') def grab_record(name): bottle.response.headers['Access-Control-Allow-Origin'] = '*' return dbcoll.find_one({'_id':Fals...
-2
2016-05-29T08:02:43Z
37,508,420
<p>The parameters in @bottle.route's URL must match the number of arguments in the function that follows it. In your case it doesn't. @bottle.route has no parameters but the function has one (name) argument.</p> <p>You could either remove name e.g.</p> <pre><code>def grab_record(): bottle.response.headers['Acce...
2
2016-05-29T09:46:02Z
[ "javascript", "python", "mongodb", "d3.js", "bottle" ]
Cleanly asserting a specific part of a config file
37,507,591
<p>I want to <code>assert</code> the existance certain values in my config file, but I don't want to make every other line an <code>assert</code> statement. Is there a cleaner way to do this? </p> <pre><code>assert config["email"]["address"], "You must supply email information." assert config["email"]["address"], "Yo...
1
2016-05-29T08:04:28Z
37,507,683
<p>Typical method for ensuring JSON data conforms specific format is to use <a href="http://json-schema.org" rel="nofollow">JSON Schema</a>.</p> <p>While Python does not have built-in package to handle JSON schemas, there is <a href="https://pypi.python.org/pypi/jsonschema" rel="nofollow"><code>jsonschema</code></a> a...
1
2016-05-29T08:17:32Z
[ "python", "python-3.x", "assert", "python-3.5" ]
Is there any way to use libgpuarray with Intel GPU?
37,507,758
<p>I'm looking for a way to use Intel GPU as a GPGPU with Theano. I've already installed Intel OpenCL and libgpuarray, but a test code 'python -c "import pygpu;pygpu.test()"' crashed the process. And I found out <code>devname</code> method caused it. It seems there would be a lot more errors.</p> <p>Is it easy to fixe...
1
2016-05-29T08:26:49Z
37,516,498
<p>libgpuarray have been made to support OpenCL, but we don't have time to finish it. Many thinks work, but we don't have the time to make sure it work everywhere.</p> <p>In any cases, you must find an OpenCL version that support that GPU, install it and reinstall libgpuarray to have it use it.</p> <p>Also, I'm not s...
1
2016-05-30T01:20:33Z
[ "python", "gpu", "gpgpu", "theano" ]
Python Selenium clicking hyperlink but remaining on same page
37,507,943
<p>Im trying to scrape a javascript page using selenium and having some problems clicking through. The click does not go to another page but uses javascript to bring up the next ten reviews, which I want to scrape.</p> <p>The first click seems to work but the second click never works, always saying there is no element...
0
2016-05-29T08:50:31Z
37,517,474
<p>Here I Will Put Code Which Navigate Page in that I have used Chrome Driver: You can download from here:<a href="http://chromedriver.storage.googleapis.com/index.html?path=2.21/" rel="nofollow">Chrome Driver</a></p> <pre><code>from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait fro...
-1
2016-05-30T04:08:43Z
[ "python", "selenium", "click" ]
Error running Hilbert curve in Python
37,508,013
<p>I'm trying to process an image using a python code.</p> <p>After implementing a Hilbert library I'm getting this error:</p> <pre><code>&gt;&gt;&gt; data.sort(key=hilbert.Hilbert_to_int) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "C:\Users\tomba\hilbert.py", line 30,...
0
2016-05-29T08:59:52Z
37,851,523
<p>You could import it from functools: <code>from functools import reduce</code>. Source:<a href="http://www.artima.com/weblogs/viewpost.jsp?thread=98196" rel="nofollow">http://www.artima.com/weblogs/viewpost.jsp?thread=98196</a></p>
0
2016-06-16T06:33:47Z
[ "python", "image", "hilbert-curve" ]
No module named flask in virtualenv although installed
37,508,020
<p>I want to use Flask to develop a website but I am having already problems getting a simple demo app running.</p> <p>I followed the complete installation tutorial of <a href="http://flask.pocoo.org/docs/" rel="nofollow">the flask website</a><br> Means: </p> <ul> <li>I created a project directory.</li> <li>Inside th...
1
2016-05-29T09:00:52Z
37,508,087
<p>Okay, I solved the issue: If I use python3 instead of python to execute my program or to open python console everything works as expected.<br> Still, this is weird, because (inside venv) doing <em>which python3</em> points to the python3 file inside the bin folder of my venv, but <em>which python</em> points to a sy...
1
2016-05-29T09:09:28Z
[ "python", "flask", "virtualenv" ]
How to get the position in a certain percentile range of 2-d array with np.NAN in it
37,508,030
<p>Here is my question.<br> With some background intro here: </p> <ul> <li><strong>a</strong> is an 2-d numpy array in the size of (50,50) </li> <li>Some elements in <strong>a</strong> are <em>np.NAN</em>, others has its finite values. </li> </ul> <h3>My target</h3> <blockquote> <p>Get the array indice of ...
1
2016-05-29T09:01:48Z
37,508,360
<p>You can use the numpy function <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.nanpercentile.html" rel="nofollow"><code>nanpercentile</code></a> to avoid taking <code>nan</code> values into consideration</p> <pre><code>a_70 = np.nanpercentile(a, 70) a_80 = np.nanpercentile(a, 80) </code></...
2
2016-05-29T09:39:28Z
[ "python", "arrays", "python-2.7", "numpy", "statistics" ]
Google Maps API: JSON response for location with non-English name
37,508,059
<p>While parsing</p> <pre><code>http://maps.googleapis.com/maps/api/geocode/json?sensor=false&amp;address=Inha+Technical+College </code></pre> <p>I get</p> <pre><code>"ZERO_RESULTS" </code></pre> <p>But if I use "인하공업전문대학" (Korean name of this institution) instead of "Inha Technical College" </p> <...
0
2016-05-29T09:05:00Z
37,508,218
<p>When you search based on names (not addresses) of locations request the places-API</p> <p><a href="https://maps.googleapis.com/maps/api/place/textsearch/json?query=Inha+Technical+College&amp;key=[InsertYourKeyHere]" rel="nofollow"><pre>https://maps.googleapis.com/maps/api/place/textsearch/json?query=Inha+Technical...
1
2016-05-29T09:25:10Z
[ "python", "json", "google-maps", "google-maps-api-3" ]
Python - Django - uWSGI NameError: global name 'models' is not defined
37,508,082
<p>I'm trying to start my first Django powered project. I have recompiled an existing project. The migrations are completed without any errors, also the development server runs with no issues. The challenge comes when I try to run the project with a uWSGI server. The project environment is as follows Python 2.7, Django...
0
2016-05-29T09:08:57Z
37,516,539
<p>I think you have the import <code>from smsapp import models</code> incorrect.</p> <p>Take a look at this question it may help: <a href="http://stackoverflow.com/questions/18479134/django-import-class-from-models-py">Django Import Class From models.py</a></p>
0
2016-05-30T01:28:00Z
[ "python", "python-2.7", "nginx", "django-models", "uwsgi" ]
pandas data reader google finance for australian stock exchange
37,508,088
<p>Unable to get quotes from google finance using pandas and the new data reader module for tickers specifically on the australian stock exchange.</p> <p>the relevant google finance page for each stock lists them as: commonwealth bank asx:cba billabong international asx:bbg etc</p> <p>however pandas datareader does n...
2
2016-05-29T09:09:35Z
37,516,212
<p>Google Finance, as Yahoo Finance, places some limits on data offered through their website available via <code>GET</code> request. You can see that for <code>ASX:BBG</code> (and other <code>ASX</code> stocks), the <code>'export to spreadsheet'</code> option is missing on the <code>historical prices</code> site (comp...
0
2016-05-30T00:27:11Z
[ "python", "pandas" ]
Django - Display images in template using for loop
37,508,188
<p>I am working on a product site using django framework with bootstrap. I want to display images in for loop.<br> I have done that using for loop and pictures are being displayed in order but I wanted to display just 20 images at first and then use next button to load more 10 images and so on. <br> Can it been done on...
0
2016-05-29T09:21:26Z
37,510,005
<p>You need to use pagination.</p> <p><a href="https://docs.djangoproject.com/en/1.9/topics/pagination/" rel="nofollow">https://docs.djangoproject.com/en/1.9/topics/pagination/</a></p> <p>Pass the <code>product.types_set.all()</code> object to <code>Paginator</code></p> <pre><code>def listing(request): product =...
0
2016-05-29T12:40:26Z
[ "python", "django", "image", "django-templates", "client" ]
String Replace in csv
37,508,418
<p>Below, I am trying to replace data in a csv. The code works, but it replaces anything matching <code>stocklevel</code>in the file.</p> <pre><code>def updatestocklevel(quantity, stocklevel, code): newlevel = stocklevel - quantity stocklevel = str(stocklevel) newlevel = str(newlevel) s = open("stockco...
2
2016-05-29T09:45:50Z
37,508,551
<p>You need to write changes to new file, like this:</p> <pre><code>... with open("in.csv", "r") as f, open("out.csv", "w") as h: for l in f: l2 = l code, value = l.split(',') if (code == NUMBER): l2 = "{0}, {1}".format(code, newvalue) h.write(l2) ... </code></pre> <p>If you want, you m...
0
2016-05-29T10:02:45Z
[ "python", "python-3.x", "csv" ]
String Replace in csv
37,508,418
<p>Below, I am trying to replace data in a csv. The code works, but it replaces anything matching <code>stocklevel</code>in the file.</p> <pre><code>def updatestocklevel(quantity, stocklevel, code): newlevel = stocklevel - quantity stocklevel = str(stocklevel) newlevel = str(newlevel) s = open("stockco...
2
2016-05-29T09:45:50Z
37,508,754
<p>All the occurances of <code>stocklevel</code> are getting replaced with the value of <code>newlevel</code> as you are calling <code>s.replace (stocklevel ,newlevel)</code>.</p> <blockquote> <p><strong>string.replace(s, old, new[, maxreplace]):</strong> Return a copy of string s with all occurrences of substring...
1
2016-05-29T10:24:40Z
[ "python", "python-3.x", "csv" ]
String Replace in csv
37,508,418
<p>Below, I am trying to replace data in a csv. The code works, but it replaces anything matching <code>stocklevel</code>in the file.</p> <pre><code>def updatestocklevel(quantity, stocklevel, code): newlevel = stocklevel - quantity stocklevel = str(stocklevel) newlevel = str(newlevel) s = open("stockco...
2
2016-05-29T09:45:50Z
37,509,635
<p>Since it's a csv file I'd suggest using Python's <code>csv</code> module. You will need to write to a new file since reading and writing to the same file will turn out bad. You can always rename it afterwards.</p> <p>This example uses <code>StringIO</code> (Python 2) to embed your csv data in the code and treat it ...
0
2016-05-29T11:58:47Z
[ "python", "python-3.x", "csv" ]
String Replace in csv
37,508,418
<p>Below, I am trying to replace data in a csv. The code works, but it replaces anything matching <code>stocklevel</code>in the file.</p> <pre><code>def updatestocklevel(quantity, stocklevel, code): newlevel = stocklevel - quantity stocklevel = str(stocklevel) newlevel = str(newlevel) s = open("stockco...
2
2016-05-29T09:45:50Z
37,513,851
<p>Why not using good old regular expressions?</p> <pre><code>import re code, new_value = '11813651', '885' # e.g, change 85 to 885 for code 11813651 print (re.sub('(^%s,).*'%code,'\g&lt;1&gt;'+new_value,open('stockcontrol.csv').read())) </code></pre>
0
2016-05-29T19:10:48Z
[ "python", "python-3.x", "csv" ]
Control mouse on remote windows server
37,508,467
<p>I need to run GUI application on remote windows host and then do some actions with mouse and keyboard. This should be done from local pc without opening any GUI application (for example "Remote Desktop Connection").</p> <p>So I have a python script on remote server which does all the actions I need (tested on local...
0
2016-05-29T09:52:24Z
37,509,183
<p>Try connecting directly to user32.dll through ctypes and use mouse controlling functions from there. Perhaps win32types problem is that it is mostly statically linked to MS API. So it is programmed for desktop environment.</p> <p>Also, you can try pymouse module that you can find on pypi.python.org, of course, whi...
0
2016-05-29T11:13:43Z
[ "python", "windows", "remote-access", "remote-server", "remote-desktop" ]
Python lambda function with 2 dataframes
37,508,550
<p>This is a fragment of my code in Python. This code perfectly changes dataframe X_real_zeros, but it also changes X, why it happens? </p> <pre><code>X_real_zeros = X for column in numeric_cols: X_real_zeros[column] = X[column].apply(lambda x: 0 if np.isnan(x) == 1 else x) </code></pre> <p>If I apply something ...
1
2016-05-29T10:02:45Z
37,508,664
<p>When you do <code>X_real_zeros = X</code> you don't create a copy of X called X_real_zeros, you create a new binding with your dataframe called X_real_zeros, that is X and X_real_zeros point to the same space in memory. It works the same as with lists or dict, the solution is to use an explicit copy.</p> <pre><code...
1
2016-05-29T10:16:06Z
[ "python", "pandas", "lambda", "dataframe", "apply" ]
Python lambda function with 2 dataframes
37,508,550
<p>This is a fragment of my code in Python. This code perfectly changes dataframe X_real_zeros, but it also changes X, why it happens? </p> <pre><code>X_real_zeros = X for column in numeric_cols: X_real_zeros[column] = X[column].apply(lambda x: 0 if np.isnan(x) == 1 else x) </code></pre> <p>If I apply something ...
1
2016-05-29T10:02:45Z
37,508,709
<p>The problem is with this line <code>X_real_zeros = X</code>, instead of just assign you should use:</p> <pre><code>X_real_zeros = X.copy() </code></pre> <p>You may refer to <a href="http://stackoverflow.com/questions/27673231/why-should-i-make-a-copy-of-a-data-frame-in-pandas">why should I make a copy of a data fr...
1
2016-05-29T10:20:04Z
[ "python", "pandas", "lambda", "dataframe", "apply" ]
Python lambda function with 2 dataframes
37,508,550
<p>This is a fragment of my code in Python. This code perfectly changes dataframe X_real_zeros, but it also changes X, why it happens? </p> <pre><code>X_real_zeros = X for column in numeric_cols: X_real_zeros[column] = X[column].apply(lambda x: 0 if np.isnan(x) == 1 else x) </code></pre> <p>If I apply something ...
1
2016-05-29T10:02:45Z
37,508,806
<p>When you assign</p> <pre><code>X_real_zeros = X </code></pre> <p>X_real_zeros is being assigned an internal reference to object X. So as X_real_zeros gets mutated, X also changes values. To safely copy variables, do:</p> <pre><code>X.copy() </code></pre> <p>This will create a new copy of X and you will be able t...
0
2016-05-29T10:29:39Z
[ "python", "pandas", "lambda", "dataframe", "apply" ]
Calculate a plane from point cloud in Python without Numpy
37,508,559
<p>I've seen several posts on this subject, but I need a pure Python (no Numpy or any other imports) solution that accepts a list of points (x,y,z coordinates) and calculates a normal for the closest plane that to those points. </p> <p>I'm following one of the working Numpy examples from here: <a href="http://stackove...
1
2016-05-29T10:03:12Z
37,510,662
<p>I do not think you can get away without implementing some basic matrix operations. As this is a multivariate linear regression problem, you will definitely need dot product, transpose and norm. These are easy. The difficult part is that you also need matrix inverse <em>or</em> QR decomposition or something similar. ...
0
2016-05-29T13:47:18Z
[ "python", "numpy" ]
Group by and Count distinct words in Pandas DataFrame
37,508,659
<p>By year and name, I am hoping to count the occurrence of words in a dataframe from imported from Excel which results will also be exported to Excel.</p> <p>This is the sample code:</p> <pre><code>source = pd.DataFrame({'Name' : ['John', 'Mike', 'John','John'], 'Year' : ['1999', '2000', '2000','2...
1
2016-05-29T10:15:08Z
37,508,744
<p>I think you can first <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.split.html" rel="nofollow"><code>split</code></a> column <code>Message</code>, create <code>Serie</code> and add it to original <code>source</code>. Last <a href="http://pandas.pydata.org/pandas-docs/stable/generat...
1
2016-05-29T10:22:50Z
[ "python", "pandas", "dataframe", "group-by", "distinct-values" ]
How to setup 2 QDoubleSpinBox depending on each other?
37,508,670
<p>The first combobox holds a number in a currency A and the second one holds the same amount but in currency B. What I want : When I enter a number in the 1st one, the 2nd one must be set automatically to the number converted in the other currency and vice-versa. I use Ubuntu 16.04, Python 3.5.1, Qt 4.8.7. The 2 QComb...
0
2016-05-29T10:16:30Z
37,509,426
<p>I think this could be due to both spin boxes playing "ping pong". A change of value of dspPuAchDT causes it's valueChanged() singal to be emitted, which in turn updates dspPuAchEur, which in turn emits it's valueChanged() signal with in turn leads to an update of dspPuAchDT. Due to rounding, the value you enter seem...
0
2016-05-29T11:35:05Z
[ "python", "qt" ]
Tkinter, custom widget and label updates
37,508,720
<p><strong>Description</strong></p> <p>I want to make a custom <code>"Table Widget"</code> for Tkinter and so far it's almost as I want.</p> <p>The problem I have is that I want the table to consist of <code>"Labels"</code>, I have only found that you have to use <code>"StringVar()'s"</code> in order to update the la...
0
2016-05-29T10:21:17Z
37,509,727
<blockquote> <p>I have only found that you have to use "StringVar()'s" in order to update the labels.</p> </blockquote> <p>This is not a true statement. You can update the attributes of any widget with the <code>config</code> / <code>configure</code> method. Starting with your first example, it would look like this:...
1
2016-05-29T12:08:25Z
[ "python", "tkinter" ]
Tkinter, custom widget and label updates
37,508,720
<p><strong>Description</strong></p> <p>I want to make a custom <code>"Table Widget"</code> for Tkinter and so far it's almost as I want.</p> <p>The problem I have is that I want the table to consist of <code>"Labels"</code>, I have only found that you have to use <code>"StringVar()'s"</code> in order to update the la...
0
2016-05-29T10:21:17Z
37,511,018
<p>As Bryan said, you don't <em>need</em> to use a StringVar as a Label's <code>textvariable</code> option to change its text. It can be more convenient, though, especially if you want to be able to read the current text string from the Label. FWIW, you can read the options of a Tkinter widget by calling its <code>.con...
0
2016-05-29T14:23:49Z
[ "python", "tkinter" ]
Torch lua function to return multiple values
37,508,781
<p>I would like to replicate the following python function in lua/torch. </p> <pre><code>def add_and_multiply(a,b): c=a+b; d=a*b; return c,d </code></pre> <p>How can I return two values simultaneously in lua/torch as above? Also, suppose a and b were matrices(with appropriate dimensions), how would the co...
2
2016-05-29T10:27:52Z
37,508,827
<p>The same thing happens in lua too. You can even skip using two extra <code>local</code> variables:</p> <pre><code>function add_and_multiply(a,b) return a + b, a * b end </code></pre>
1
2016-05-29T10:31:51Z
[ "python", "lua", "torch" ]
I am having problems with Pythons `subprocess.popen` hanging
37,508,802
<p>I have a simple function that calls the same <code>subprocess.popen</code> command on multiple items from a list. It executes the first 2 items in the list no problem, however the action on the third hangs. </p> <p>It seems that the <code>process_null.communicate()</code> never executes or doesnt finish at least as...
0
2016-05-29T10:29:22Z
37,509,038
<p>When <code>rpcclient</code> successfully establishes a connection it starts a shell and waits for commands to be entered on <code>stdin</code> if none are given using the <code>-c</code> flag, which is what happens here. You don't see the prompt because you redirect all output (<code>stdout</code> + <code>stderr</co...
2
2016-05-29T10:57:54Z
[ "python", "subprocess" ]
Is a text file still open after a open(file).read() command?
37,508,850
<p>To shorten the code a little, I used something like:</p> <pre><code>data = open(file).read() </code></pre> <p>It's impossible to close by <code>data.close()</code> since <code>data</code> it's a string, so I ask the question: if after that line is read, is the file still open? Do I need to bother to close it some...
0
2016-05-29T10:35:18Z
37,508,903
<p>It will (probably, see comments) be closed when garbage collected; however the cleanest way to handle it is within a <code>with</code> block:</p> <pre><code>with open(file, "r") as datafile: data = datafile.read() </code></pre> <p>If the process is short-lived, it shouldn't cause too much trouble, but it's goo...
3
2016-05-29T10:40:25Z
[ "python", "python-2.7", "pycharm" ]
Is a text file still open after a open(file).read() command?
37,508,850
<p>To shorten the code a little, I used something like:</p> <pre><code>data = open(file).read() </code></pre> <p>It's impossible to close by <code>data.close()</code> since <code>data</code> it's a string, so I ask the question: if after that line is read, is the file still open? Do I need to bother to close it some...
0
2016-05-29T10:35:18Z
37,508,914
<p>In CPython the result of <code>open(file)</code> will have no references to it after <code>.read()</code> completes if there were no exceptions, so it will be instantly garbage collected which will cause it to close.</p> <p>But don't do this. Make a convenience function:</p> <pre><code>def read_file(path): wit...
3
2016-05-29T10:41:51Z
[ "python", "python-2.7", "pycharm" ]
Is a text file still open after a open(file).read() command?
37,508,850
<p>To shorten the code a little, I used something like:</p> <pre><code>data = open(file).read() </code></pre> <p>It's impossible to close by <code>data.close()</code> since <code>data</code> it's a string, so I ask the question: if after that line is read, is the file still open? Do I need to bother to close it some...
0
2016-05-29T10:35:18Z
37,509,482
<p>yes, it will remain open ,my way to open data like this:</p> <pre><code>with open("file","rb") as f: data=f.readlines() </code></pre> <p>or</p> <pre><code>datas=open("file","rb") data=datas.readlines() </code></pre> <p>wish i could help you</p>
0
2016-05-29T11:41:33Z
[ "python", "python-2.7", "pycharm" ]
Use Python module on the runtime
37,508,912
<pre><code>import os import sys #run get-pip.py os.system("python get-pip.py") #try to import pip try: __import__('pip') except ImportError: input('Could not install pip, please enter any key to quit this window.') sys.exit() #install selenium def install(package): pip.main(['install', package]) if ...
0
2016-05-29T10:41:40Z
37,509,094
<p>You should use the standard <code>import pip</code> unless you are trying to define the module to import dynamically. It will still raise ImportError if pip is not installed.</p>
1
2016-05-29T11:04:00Z
[ "python", "python-3.x", "runtime", "pip" ]
How to reduce the difference in color between stitched images to make a smooth color transition?
37,509,013
<p>I'm stitching multiple images, and I want to improve the color transition between them. Here are the two images:</p> <ol> <li><a href="http://imgur.com/nG5I0nr" rel="nofollow">http://imgur.com/nG5I0nr</a></li> <li><a href="http://imgur.com/EZFzNeL" rel="nofollow">http://imgur.com/EZFzNeL</a></li> </ol> <p>And here...
2
2016-05-29T10:53:56Z
37,517,247
<p>I don't know whether it is a good idea or not, but I think you can use <a href="http://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html" rel="nofollow"><strong>Kmeans</strong></a> to "tune" the color of the image.</p> <p><strong>First</strong>, you convert your images into <strong>RGB</strong><...
0
2016-05-30T03:34:17Z
[ "python", "opencv", "image-processing", "scipy", "computer-vision" ]
Summing several equal size matrices by elements
37,509,021
<p>I've got a problem that I already opened and explained <a href="http://stackoverflow.com/questions/37468787/double-summation-of-matrix-elements-in-python">HERE</a>. To be short, I need to replace the symbols in my analitically matrix with values and sum them all together. For better explanation I made the pic below:...
0
2016-05-29T10:55:39Z
37,509,090
<p>To add several NumPy arrays of the same size element-wise as your hand-written formula shows you can simply write</p> <pre><code>M = M1 + M2 + M3 </code></pre> <p>SymPy matrices are added similarly. You can mix and match the two:</p> <pre><code>import sympy from sympy.abc import x import numpy A = sympy.Matrix([...
1
2016-05-29T11:03:45Z
[ "python", "python-2.7", "python-3.x", "matrix", "sum" ]
Regular Expression for Financial Numbers
37,509,081
<p>I think my chances are slim based on the responses to other questions related to regular expressions.</p> <p>I am try to parse numbers in different representations:</p> <pre><code>12345(234567) 12345(234.56K) </code></pre> <p>from which I cannot control the source format.</p> <p>I suppose I can come up with diff...
2
2016-05-29T11:01:58Z
37,509,225
<p>This kind of thing is often done by iterating over a bunch of regular expressions and stopping when you find one that matches - because your conversion from a string to a number needs special parsing beyond the capabilities of regular expressions. That means you need to order them in a way that you know will give th...
3
2016-05-29T11:17:28Z
[ "python", "regex" ]
Detect english words in text
37,509,086
<p>I have a dataset which is crawled but also contains entries that have a lot of junk in them. </p> <pre><code>Name: sdfsdfsdfsd Location: asdfdgdfjkgdsfjs Education: Science &amp; Literature </code></pre> <p>Currently its being stored in MySQL and Solr.<br> Is there any library that can look for English words in...
-2
2016-05-29T11:03:02Z
37,509,164
<pre><code>with open('/usr/share/dict/words') as f: words = set(word.lower() for word in f.read().split() # Really short words aren't much of an indication if len(word) &gt; 3) def is_english(text): return bool(words.intersection(text.lower().split())) # or return any(wo...
0
2016-05-29T11:11:31Z
[ "java", "python", "mysql", "dictionary", "data-cleaning" ]
Django ModelForm not genrating HTML form
37,509,089
<p>I am trying to generate HTML form using django's ModelForm class. However,, it is not generating.</p> <p>Below are my files :-</p> <p>models.py</p> <pre><code>from __future__ import unicode_literals from django.db import models class Policy(models.Model): policy_number = models.CharField(max_length = 9) ...
0
2016-05-29T11:03:26Z
37,510,599
<p>You need to do <code>{{ policyForm }}</code> not <code>{{ policyform }}</code>.</p>
2
2016-05-29T13:41:42Z
[ "python", "django" ]