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 coordinates into binary image python
40,006,110
<p>I made a GUI in which I can load an image from disk and convert the mouse motion ( drawing the contours ) into coordinates. Now I need to convert the coordinates into a binary image and I don't know how. Here is my code:</p> <pre><code>from Tkinter import * from tkFileDialog import askopenfilename from PIL import ...
0
2016-10-12T18:43:39Z
40,017,903
<p>Your issue is that you are creating a new empty array at each mouse event with the line <code>a = np.zeros(shape=(h,w))</code> in mouseevent. To fix that you should have <code>a</code> declared in the <code>__init__</code> as an attribute (ie <code>self.a = np.zeros(shape=(h,w))</code>) so that you can acces and upd...
0
2016-10-13T09:59:19Z
[ "python", "tkinter" ]
Can this python function be vectorized?
40,006,169
<p>I have been working on this function that generates some parameters I need for a simulation code I am developing and have hit a wall with enhancing its performance.</p> <p>Profiling the code shows that this is the main bottleneck so any enhancements I can make to it however minor would be great.</p> <p>I wanted to...
4
2016-10-12T18:47:04Z
40,008,834
<p>Here's a vectorized approach using <a href="https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html" rel="nofollow"><code>broadcasted</code></a> summations -</p> <pre><code># Gather the elements sorted by the keys in (row,col) order of a dense # 2D array for both nn and nnn sidx0 = np.ravel_multi_index(np.a...
3
2016-10-12T21:40:55Z
[ "python", "performance", "python-2.7", "numpy", "vectorization" ]
storing the facebook login session
40,006,188
<p>I am successfully authenticating the user via facebook and getting their name in def fbconnect()</p> <pre><code>print "username" ,login_session['username'] session.name=login_session['username'] print "session.name",session.name </code></pre> <p>But in my html, when I try check to see whether the user is logged in...
-1
2016-10-12T18:48:29Z
40,008,567
<p>It is working now using <code>session['username']</code> </p> <p>I had to move some code around from one page to another to get it to work though. </p> <p>Thanks for your help. </p>
0
2016-10-12T21:22:11Z
[ "python", "flask", "facebook-login" ]
Keeping order of parameters in Python Post Request
40,006,246
<p>For some reason, I need to influence the ordering of the data in post-Request with the requests-library.</p> <p>Consider this:</p> <pre><code>data = { 'param1': "foo", 'param2': "bar", } print requests.post(url, data=data) </code></pre> <p>So param1 should be in the body before param2. A corresponding c...
0
2016-10-12T18:51:43Z
40,006,303
<p>You can use an <a href="https://docs.python.org/2/library/collections.html#collections.OrderedDict" rel="nofollow"><code>OrderedDict</code></a> instead:</p> <pre><code>from collections import OrderedDict data = OrderedDict(param1="foo", param2="bar") print requests.post(url, data=data) </code></pre>
0
2016-10-12T18:55:33Z
[ "python", "post", "request" ]
How to collect continuous data with Python Telnet
40,006,258
<p>I have a python script that connects to a Power Supply via a Telnet session. The flow of the script is as follows:</p> <pre><code># Connect to Device tn = telnetlib.Telnet(HOST,PORT) # Turn On tn.write("OUT 1\r") # Get Current Voltage current_voltage = tn.write("MV?\r") # Turn Off tn.write("OUT 0\r") </code></pr...
0
2016-10-12T18:52:37Z
40,006,501
<p>Every millisecond is probably more than tkinter can handle. It depends a bit on how expensive it is to fetch the voltage. If it takes longer than a millisecond, you're going to need threads or multiprocessing. </p> <p>The simplest solution is to use <code>after</code> to schedule the retrieval of the data every mil...
2
2016-10-12T19:07:51Z
[ "python", "tkinter", "telnet" ]
How to filter a pandas dataframe based on the length of a entry
40,006,276
<p>In a pandas dataframe I have a field 'amp' that should be populated by a list of length 495. Is there a panda-ic way to quickly filter on this length, such that all rows with field 'amp' are not equal to 495 are dropped?</p> <p>I tried</p> <pre><code>df[len(df['amp']) == 495] </code></pre> <p>and this returned</...
1
2016-10-12T18:53:47Z
40,006,292
<p>Try this:</p> <pre><code>df[df['amp'].str.len() == 495] </code></pre> <p>Demo:</p> <pre><code>In [77]: df Out[77]: a 0 [1, 2, 3, 4, 5] 1 [1, 2, 3] 2 [-1] In [78]: df.a.str.len() Out[78]: 0 5 1 3 2 1 Name: a, dtype: int64 In [79]: df[df.a.str.len() == 3] Out[79]: ...
4
2016-10-12T18:55:04Z
[ "python", "pandas", "dataframe" ]
How to filter a pandas dataframe based on the length of a entry
40,006,276
<p>In a pandas dataframe I have a field 'amp' that should be populated by a list of length 495. Is there a panda-ic way to quickly filter on this length, such that all rows with field 'amp' are not equal to 495 are dropped?</p> <p>I tried</p> <pre><code>df[len(df['amp']) == 495] </code></pre> <p>and this returned</...
1
2016-10-12T18:53:47Z
40,006,452
<p>If you specifically need <code>len</code>, then @MaxU's answer is best.</p> <p>For a more general solution, you can use the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html" rel="nofollow">map</a> method of a Series.</p> <pre><code>df[df['amp'].map(len) == 495] </code></pre> <...
2
2016-10-12T19:04:29Z
[ "python", "pandas", "dataframe" ]
How two recursion function in program works?
40,006,300
<p>I am learning Recursion and understand single recursion like Factorial . I am facing problem to understand how two recursive function works ? I am trying to understand this code :</p> <pre><code>def countdown(n,m): if n == 0: # this is the base case return # return, instead of making more recursive c...
-2
2016-10-12T18:55:24Z
40,006,672
<p>You can visualize the sequence of calls and returns in a tree like this:</p> <p><a href="https://i.stack.imgur.com/yLESp.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/yLESp.jpg" alt="enter image description here"></a></p> <p>The calls traverse this tree left to right, depth first:</p> <p><a href="https:...
0
2016-10-12T19:17:32Z
[ "python", "python-3.x", "recursion" ]
How two recursion function in program works?
40,006,300
<p>I am learning Recursion and understand single recursion like Factorial . I am facing problem to understand how two recursive function works ? I am trying to understand this code :</p> <pre><code>def countdown(n,m): if n == 0: # this is the base case return # return, instead of making more recursive c...
-2
2016-10-12T18:55:24Z
40,007,010
<p><strong>Short answer</strong>: You see "first recursion" and "second recursion" so early in the output because, in the process of making a recursive call to <code>countdown(3)</code> you eventually make a call to <code>countdown(1)</code>, which itself makes two recursive calls to <code>countdown(0)</code> which com...
1
2016-10-12T19:40:57Z
[ "python", "python-3.x", "recursion" ]
How two recursion function in program works?
40,006,300
<p>I am learning Recursion and understand single recursion like Factorial . I am facing problem to understand how two recursive function works ? I am trying to understand this code :</p> <pre><code>def countdown(n,m): if n == 0: # this is the base case return # return, instead of making more recursive c...
-2
2016-10-12T18:55:24Z
40,007,957
<p>Another little trick you can use to see what comes from calls at which level: pass an argument that increases with recursion depth to make it easy to associate output with particular calls. I'm going to use a string argument called <code>indent</code>, and add two spaces for each level of indentation.</p> <p>I've t...
1
2016-10-12T20:39:56Z
[ "python", "python-3.x", "recursion" ]
How two recursion function in program works?
40,006,300
<p>I am learning Recursion and understand single recursion like Factorial . I am facing problem to understand how two recursive function works ? I am trying to understand this code :</p> <pre><code>def countdown(n,m): if n == 0: # this is the base case return # return, instead of making more recursive c...
-2
2016-10-12T18:55:24Z
40,016,427
<p>Again and again I would suggest not to use any visual tool, just have a look at the code itself! First of all the m value for what is needed in this example??? </p> <p>Second and most important...as explained in the other post you have to think about a python STACK and going into iteration. <a href="http://stackove...
0
2016-10-13T08:53:22Z
[ "python", "python-3.x", "recursion" ]
How two recursion function in program works?
40,006,300
<p>I am learning Recursion and understand single recursion like Factorial . I am facing problem to understand how two recursive function works ? I am trying to understand this code :</p> <pre><code>def countdown(n,m): if n == 0: # this is the base case return # return, instead of making more recursive c...
-2
2016-10-12T18:55:24Z
40,050,809
<p>You are confuse because you are visualizing two recursion with single stack , You have to know that Every recursion function store values its own stack , It means if you have two recursion there will be two stack , if you have three recursion there would be three stack. </p> <p>Now back to the question , I have wri...
2
2016-10-14T19:36:57Z
[ "python", "python-3.x", "recursion" ]
Applying UDFs on GroupedData in PySpark (with functioning python example)
40,006,395
<p>I have this python code that runs locally in a pandas dataframe:</p> <pre><code>df_result = pd.DataFrame(df .groupby('A') .apply(lambda x: myFunction(zip(x.B, x.C), x.name)) </code></pre> <p>I would like to run this in PySpark, but having trouble dealing with pys...
3
2016-10-12T19:01:10Z
40,030,740
<p>What you are trying to is write a UDAF (User Defined Aggregate Function) as opposed to a UDF (User Defined Function). UDAFs are functions that work on data grouped by a key. Specifically they need to define how to merge multiple values in the group in a single partition, and then how to merge the results across pa...
0
2016-10-13T20:50:36Z
[ "python", "apache-spark", "pyspark", "spark-dataframe" ]
Efficient way to find the index of repeated sequence in a list?
40,006,438
<p>I have a large list of numbers in python, and I want to write a function that finds sections of the list where the same number is repeated more than n times. For example, if n is 3 then my function should return the following results for the following examples:</p> <blockquote> <p>When applied to example = [1,2,1...
2
2016-10-12T19:03:22Z
40,006,579
<p>Use <code>itertools.groupby</code> and <code>enumerate</code>:</p> <pre><code>&gt;&gt;&gt; from itertools import groupby &gt;&gt;&gt; n = 3 &gt;&gt;&gt; x = [1,2,1,1,1,1,2,3] &gt;&gt;&gt; grouped = (list(g) for _,g in groupby(enumerate(x), lambda t:t[1])) &gt;&gt;&gt; [(g[0][0], g[-1][0] + 1) for g in grouped if l...
2
2016-10-12T19:12:22Z
[ "python", "python-3.x" ]
Efficient way to find the index of repeated sequence in a list?
40,006,438
<p>I have a large list of numbers in python, and I want to write a function that finds sections of the list where the same number is repeated more than n times. For example, if n is 3 then my function should return the following results for the following examples:</p> <blockquote> <p>When applied to example = [1,2,1...
2
2016-10-12T19:03:22Z
40,006,830
<p>You can do this in a single loop by following the current algorithm:</p> <pre><code>def find_pairs (array, n): result_pairs = [] prev = idx = 0 count = 1 for i in range (0, len(array)): if(i &gt; 0): if(array[i] == prev): count += 1 else: ...
1
2016-10-12T19:28:23Z
[ "python", "python-3.x" ]
Efficient way to find the index of repeated sequence in a list?
40,006,438
<p>I have a large list of numbers in python, and I want to write a function that finds sections of the list where the same number is repeated more than n times. For example, if n is 3 then my function should return the following results for the following examples:</p> <blockquote> <p>When applied to example = [1,2,1...
2
2016-10-12T19:03:22Z
40,007,290
<p>You could use this. Note that your question is ambiguous as to the role of n. I assume here that a series of <em>n</em> equal values should be matched. If it should have at least <em>n+1</em> values, then replace <code>&gt;=</code> by <code>&gt;</code>:</p> <pre><code>def monotoneRanges(a, n): idx = [i for i, v...
0
2016-10-12T19:58:35Z
[ "python", "python-3.x" ]
Converting to list of dictionary
40,006,439
<p>I have a text file filled with place data provided by twitter api. Here is the sample data of 2 lines</p> <pre><code>{'country': 'United Kingdom', 'full_name': 'Dorridge, England', 'id': '31fe56e2e7d5792a', 'country_code': 'GB', 'name': 'Dorridge', 'attributes': {}, 'contained_within': [], 'place_type': 'city', 'bo...
0
2016-10-12T19:03:26Z
40,006,546
<p>In your case you should use <code>json</code> to do the data parsing. But if you have a problem with <code>json</code> (which is almost impossible since we are talking about an API ), then in general to convert from string to dictionary you can do:</p> <pre><code>&gt;&gt;&gt; import ast &gt;&gt;&gt; x = "{'country'...
2
2016-10-12T19:10:15Z
[ "python", "dictionary" ]
Converting to list of dictionary
40,006,439
<p>I have a text file filled with place data provided by twitter api. Here is the sample data of 2 lines</p> <pre><code>{'country': 'United Kingdom', 'full_name': 'Dorridge, England', 'id': '31fe56e2e7d5792a', 'country_code': 'GB', 'name': 'Dorridge', 'attributes': {}, 'contained_within': [], 'place_type': 'city', 'bo...
0
2016-10-12T19:03:26Z
40,006,583
<p>You can use list like this</p> <pre><code>mlist= list() for i in ndata.keys(): mlist.append(i) </code></pre>
0
2016-10-12T19:12:32Z
[ "python", "dictionary" ]
Converting to list of dictionary
40,006,439
<p>I have a text file filled with place data provided by twitter api. Here is the sample data of 2 lines</p> <pre><code>{'country': 'United Kingdom', 'full_name': 'Dorridge, England', 'id': '31fe56e2e7d5792a', 'country_code': 'GB', 'name': 'Dorridge', 'attributes': {}, 'contained_within': [], 'place_type': 'city', 'bo...
0
2016-10-12T19:03:26Z
40,006,896
<blockquote> <p>Note: Single quotes are not valid JSON.</p> </blockquote> <p>I have never tried Twitter API. Looks like your data are not valid JSON. Here is a simple preprocess method to replace <code>'</code>(single quote) into <code>"</code>(double quote)</p> <pre><code>data = "{'country': 'United Kingdom', ... ...
1
2016-10-12T19:33:10Z
[ "python", "dictionary" ]
Converting to list of dictionary
40,006,439
<p>I have a text file filled with place data provided by twitter api. Here is the sample data of 2 lines</p> <pre><code>{'country': 'United Kingdom', 'full_name': 'Dorridge, England', 'id': '31fe56e2e7d5792a', 'country_code': 'GB', 'name': 'Dorridge', 'attributes': {}, 'contained_within': [], 'place_type': 'city', 'bo...
0
2016-10-12T19:03:26Z
40,007,167
<p>You should use python json library for parsing and getting the value. In python it's quite easy.</p> <pre><code>import json x = '{"country": "United Kingdom", "full_name": "Dorridge, England", "id": "31fe56e2e7d5792a", "country_code": "GB", "name": "Dorridg", "attributes": {}, "contained_within": [], "place_type": ...
1
2016-10-12T19:51:42Z
[ "python", "dictionary" ]
How to test if WindowStaysOnTopHint flag is set in windowFlags?
40,006,533
<p>Is this supposed to return a boolean value?</p> <pre><code>&gt;&gt;&gt; win.windowFlags() &amp; QtCore.Qt.WindowStaysOnTopHint &lt;PyQt4.QtCore.WindowFlags object at 0x7ad0578&gt; </code></pre> <p>I already knew that</p> <pre><code># enable always on top win.windowFlags() | QtCore.Qt.WindowStaysOnTopHint # disab...
1
2016-10-12T19:09:48Z
40,007,740
<p>The <code>WindowFlags</code> object is an OR'd together set of flags from the <code>WindowType</code> enum. The <code>WindowType</code> is just a subclass of <code>int</code>, and the <code>WindowFlags</code> object also supports <code>int</code> operations.</p> <p>You can test for the presence of a flag like this:...
1
2016-10-12T20:26:19Z
[ "python", "pyqt", "bit-manipulation", "flags", "always-on-top" ]
subplot2grid with seaborn overwrites same ax
40,006,587
<p>What is the correct way of specifying the ax where I want a chart to go?</p> <p>Currently I'm trying to plot different heatmaps, each one in a different ax. But when trying this it just plots the 2 charts one on top of the other. </p> <pre><code>import seaborn as sns import matplotlib.pyplot as plt fig3 = plt.f...
0
2016-10-12T19:12:44Z
40,090,122
<p>You just need to pass your Axes objects to the <code>heatmap</code> function:</p> <pre><code>import seaborn as sns import matplotlib.pyplot as plt fig3 = plt.figure(figsize=(12,10)) ax1 = plt.subplot2grid((11,2),(0,0), rowspan=3, colspan=1) ax2 = plt.subplot2grid((11,2),(4,0), rowspan=3, colspan=1) ax1 = sns.he...
0
2016-10-17T15:20:11Z
[ "python", "matplotlib", "seaborn" ]
Get count of list items that meet a condition with Jinja2
40,006,617
<p>I have a list of dictionaries where each dict has a boolean entry. I want to display the items that are <code>True</code>, along with the count of those items. I'm using the <code>selectattr</code> filter, but it returns a generator, and calling <code>|length</code> on it raise an error. How can I get the length of...
1
2016-10-12T19:14:07Z
40,006,705
<p>There is a <code>list</code> filter that will transform a generator into a list. So:</p> <pre><code>{{ my_list|selectattr('foo')|list|length }} </code></pre>
3
2016-10-12T19:20:09Z
[ "python", "flask", "jinja2" ]
Passing an array where single value is expected?
40,006,652
<p>I am trying to implement simple optimization problem in Python. I am currently struggling with the following error:</p> <p><strong>Value Error</strong>: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()</p> <p>As far as I understand, this means that I am somewhere trying t...
-1
2016-10-12T19:16:11Z
40,009,140
<p>Nimitz14 hit the general explanation: you've supplied an array where a scalar is required. This caused a run-time error. The problem is how to fix it from here.</p> <p>First, try slapping your favourite debugger on the problem, so you can stop the program at useful spots and figure out exactly <em>what</em> array...
0
2016-10-12T22:04:38Z
[ "python", "numpy", "machine-learning", "scipy", "regression" ]
How to check if command were done?
40,006,653
<p>I'am trying to do some stuff with git. I wonder how would I make the <strong>if statement</strong> argument to check if that command were done correctly:</p> <pre><code>git checkout master &amp;&amp; git reset --hard &amp;&amp; git fetch &amp;&amp; git pull </code></pre> <p>I was trying with check if output is equ...
0
2016-10-12T19:16:15Z
40,007,143
<p>Use <a href="https://docs.python.org/3/library/subprocess.html" rel="nofollow">subprocess</a> module, but execute each of your command with <a href="https://docs.python.org/3/library/subprocess.html#subprocess.Popen" rel="nofollow">Popen</a> or <a href="https://docs.python.org/3/library/subprocess.html#subprocess.ru...
0
2016-10-12T19:50:26Z
[ "python", "linux", "python-3.x" ]
How to find the mean of a list
40,006,697
<p>I'm very new to python and trying to write some code so that the user enters something. If it's an integer it's sorted into the Numbers list, if it's a string it goes into the String list. </p> <p>I want to be able to find the mean of all the numbers that are in the list and print out the result. And in the String ...
0
2016-10-12T19:19:18Z
40,006,745
<p>You are using <code>Length</code>, which has not been defined. I think what you wanted was</p> <pre><code>print(sum(Numbers)/len(Numbers)) </code></pre> <p>and you probably don't want it inside the loop, but just after it (although that might be another typo).</p>
0
2016-10-12T19:22:50Z
[ "python", "list", "python-3.x" ]
How to find the mean of a list
40,006,697
<p>I'm very new to python and trying to write some code so that the user enters something. If it's an integer it's sorted into the Numbers list, if it's a string it goes into the String list. </p> <p>I want to be able to find the mean of all the numbers that are in the list and print out the result. And in the String ...
0
2016-10-12T19:19:18Z
40,006,784
<p>There is good thing called <a href="https://docs.python.org/3/library/statistics.html#statistics.mean" rel="nofollow"><code>statistics.mean</code></a>:</p> <pre><code>from statistics import mean mean(your_list) </code></pre>
1
2016-10-12T19:25:09Z
[ "python", "list", "python-3.x" ]
How to find the mean of a list
40,006,697
<p>I'm very new to python and trying to write some code so that the user enters something. If it's an integer it's sorted into the Numbers list, if it's a string it goes into the String list. </p> <p>I want to be able to find the mean of all the numbers that are in the list and print out the result. And in the String ...
0
2016-10-12T19:19:18Z
40,006,897
<pre><code>#use isalpha to check enterted input is string or not #isalpha returns a boolean value Numbers = [] String = [] while(True): user_input = input("input : ") if user_input == "save": break elif user_input.isdigit(): Numbers.append(int(user_input)) print(sum(Numbers)/len(Nu...
1
2016-10-12T19:33:15Z
[ "python", "list", "python-3.x" ]
Sarsa algorithm, why Q-values tend to zero?
40,006,763
<p>I'm trying to implement Sarsa algorithm for solving a Frozen Lake environment from OpenAI gym. I've started soon to work with this but I think I understand it. </p> <p>I also understand how Sarsa algorithm works, there're many sites where to find a pseudocode, and I get it. I've implemented this algorithm in my pro...
3
2016-10-12T19:23:48Z
40,016,555
<p>When a episode ends you are breaking the while loop before updating the Q function. Therefore, when the reward received by the agent is different from zero (the agent has reached the goal state), the Q function is never updated in that reward.</p> <p>You should check for the end of the episode in the last part of t...
1
2016-10-13T08:59:38Z
[ "python", "reinforcement-learning", "sarsa" ]
ActiveMQ Java Broker, Python Client
40,006,811
<p>I have for legacy reasons a Java activeMQ implementation of the Broker/Publisher over vanilla tcp transport protocol. I wish to connect a Python client to it, however all the "stomp" based documentation doesn't seem to have it, not over the stomp protcol, and when I try the basic examples I get the error on the Java...
0
2016-10-12T19:26:41Z
40,009,001
<p>Without seeing the broker configuration it is a bit tricky to answer but from the error I'd guess you are trying to connect a STOMP client to the OpenWire transport which won't work, you need to have a STOMP TransportConnector configured on the broker and point the STOMP client there.</p> <p>See the <a href="http:/...
0
2016-10-12T21:53:24Z
[ "java", "python", "tcp", "activemq", "stomp" ]
cannot install python using brew
40,006,880
<p>Trying to install python using the following command:</p> <p><code>brew install python</code></p> <p>But unfortunately I am getting the following error:</p> <pre><code>&gt;brew install python ==&gt; Downloading https://homebrew.bintray.com/bottles/python-2.7.12_2.el_capitan. Already downloaded: /Users/maguerra/Li...
0
2016-10-12T19:32:01Z
40,015,590
<p>The error message says you don’t have permission to write under <code>/usr/local/lib/python2.7/site-packages/pkg_resources</code>.</p> <p>The following steps should work:</p> <ol> <li><p>Remove your broken Python install:</p> <pre><code>brew uninstall python </code></pre></li> <li><p>Ensure you own that directo...
0
2016-10-13T08:10:29Z
[ "python", "install", "homebrew" ]
Table contents missing during extraction with selenium and phantomjs
40,006,881
<p>I am trying to extract data from the following table. However, the program returns an empty table with the "/table>". Notice that there are two classes with tbpopt, hence I am using "style" as an additional descriptor for the second one. The first tblopt shows up fine, the problem is with the second one. Thanks in a...
0
2016-10-12T19:32:03Z
40,007,628
<p>If there are always two tables of <code>class='tblopt'</code> you could do something along the lines of:</p> <pre><code>from selenium import webdriver from bs4 import BeautifulSoup if __name__ == '__main__': url = 'http://www.moneycontrol.com/stocks/fno/view_option_chain.php?sc_id=IRI&amp;sel_exp_date=2016-10-...
1
2016-10-12T20:19:11Z
[ "python", "selenium", "web-scraping", "phantomjs" ]
Find integer row-index from pandas index
40,006,902
<p>The following code find index where df['A'] == 1</p> <pre><code>import pandas as pd import numpy as np import random index = range(10) random.shuffle(index) df = pd.DataFrame(np.zeros((10,1)).astype(int), columns = ['A'], index = index) df.A.iloc[3:6] = 1 df.A.iloc[6:] = 2 print df print df.loc[df['A'] == 1].in...
1
2016-10-12T19:33:25Z
40,007,069
<p>No need for numpy, you're right. Just pure python with a listcomp:</p> <p>Just find the indexes where the values are 1</p> <pre><code>print([i for i,x in enumerate(df['A'].values) if x == 1]) </code></pre>
1
2016-10-12T19:44:48Z
[ "python", "pandas", "dataframe", "row", "indices" ]
Find integer row-index from pandas index
40,006,902
<p>The following code find index where df['A'] == 1</p> <pre><code>import pandas as pd import numpy as np import random index = range(10) random.shuffle(index) df = pd.DataFrame(np.zeros((10,1)).astype(int), columns = ['A'], index = index) df.A.iloc[3:6] = 1 df.A.iloc[6:] = 2 print df print df.loc[df['A'] == 1].in...
1
2016-10-12T19:33:25Z
40,007,111
<p>Here is one way:</p> <pre><code>df.reset_index().index[df.A == 1].tolist() </code></pre> <p>This re-indexes the data frame with <code>[0, 1, 2, ...]</code>, then extracts the integer index values based on the boolean mask <code>df.A == 1</code>.</p> <hr> <p><strong>Edit</strong> Credits to @Max for the <code>ind...
1
2016-10-12T19:48:09Z
[ "python", "pandas", "dataframe", "row", "indices" ]
Find integer row-index from pandas index
40,006,902
<p>The following code find index where df['A'] == 1</p> <pre><code>import pandas as pd import numpy as np import random index = range(10) random.shuffle(index) df = pd.DataFrame(np.zeros((10,1)).astype(int), columns = ['A'], index = index) df.A.iloc[3:6] = 1 df.A.iloc[6:] = 2 print df print df.loc[df['A'] == 1].in...
1
2016-10-12T19:33:25Z
40,007,170
<p>what about?</p> <pre><code>In [12]: df.index[df.A == 1] Out[12]: Int64Index([3, 7, 1], dtype='int64') </code></pre> <p>or (depending on your goals):</p> <pre><code>In [15]: df.reset_index().index[df.A == 1] Out[15]: Int64Index([3, 4, 5], dtype='int64') </code></pre> <p>Demo:</p> <pre><code>In [11]: df Out[11]: ...
3
2016-10-12T19:51:50Z
[ "python", "pandas", "dataframe", "row", "indices" ]
waitforbuttonpress() matplotlib possible bug
40,006,924
<p>Consider a refreshed figure inside a loop as per the following code:</p> <pre><code>import matplotlib.pyplot as plt def fun_example(): plt.ion() for ite in range(3): x = np.linspace(-2,6,100) y = (ite+1)*x figura = plt.figure(1) plt.plot(x,y,'-b') plt.waitforbutton...
0
2016-10-12T19:34:45Z
40,006,994
<p>As per <a href="http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.waitforbuttonpress" rel="nofollow">the documentation</a>, <code>.waitforbuttonpress()</code> will return <code>True</code> if a key was pressed, and <code>False</code> if a mouse button was pressed. Therefore, what you want is probabl...
1
2016-10-12T19:39:28Z
[ "python", "matplotlib", "figure" ]
PySpark: How to write a Spark dataframe having a column with type SparseVector into CSV file?
40,006,929
<p>I have a spark dataframe which has one column with type spark.mllib.linalg.SparseVector:</p> <p>1) how can I write it into a csv file?</p> <p>2) how can I print all the vectors?</p>
2
2016-10-12T19:35:18Z
40,008,799
<ol> <li><a href="https://github.com/databricks/spark-csv" rel="nofollow">https://github.com/databricks/spark-csv</a></li> <li><p><code>df2 = df1.map(lambda row: row.yourVectorCol)</code></p> <p>OR <code>df1.map(lambda row: row[1])</code></p> <p>where you either have a named column or just refer to the column by its ...
0
2016-10-12T21:38:57Z
[ "python", "apache-spark", "pyspark" ]
has no attribute validate_on_submit: How to use wtforms-alchemy's ModelForm in a flask handler / view
40,006,943
<p>I'm trying to switch <code>from wtforms.ext.sqlalchemy.orm import model_form</code> to using wtforms_alchemy ModelForm: </p> <pre><code>from wtforms_alchemy import ModelForm </code></pre> <p>I'm failing miserably... and I've been unsuccessful searching for a working example of that uses wtforms_alchemy which show...
0
2016-10-12T19:36:11Z
40,028,029
<p>Nevermind.</p> <p>Although I had tried using</p> <pre><code>from wtforms_alchemy import model_form_factory </code></pre> <p>prior to this post, it decided to work when I put it back, but after the ModelForm import instead of before it.</p> <p>Whatever.</p>
0
2016-10-13T18:07:34Z
[ "python", "sqlalchemy", "flask-sqlalchemy", "wtforms" ]
Unwanted looping occurring on first function
40,006,944
<pre><code>def load(): name=0 count=0 totalpr=0 name=input("Enter stock name OR -999 to Quit: ") while name != '-999': count=count+1 shares=int(input("Enter number of shares: ")) pp=float(input("Enter purchase price: ")) sp=float(input("Enter selling price: ")) ...
0
2016-10-12T19:36:13Z
40,007,710
<p>First you have to define all variables globally or pass it as a parameter, and then you have to call your function inside your while loop.For simplicity I am defining it as a global variable.</p> <pre><code>shares = 0 pp = 0 sp = 0 commission = 0 name = "" amount_paid = 0 profit_loss = 0 totalpr = 0 commission_paid...
-1
2016-10-12T20:25:00Z
[ "python", "function", "python-3.x", "while-loop" ]
New to Python 3 - Unable to get program to move to the next module
40,006,949
<p>I am new to Python and am trying to get a program to move from one defined module to the next. The first module is working just fine but will not move to the def calcAverage module. I have attached both the code and the result. I only have the sum set up in the first module to verify that it was calculating correctl...
0
2016-10-12T19:36:27Z
40,007,029
<p>def must be declared before the call of <em>main()</em>. You're OK.</p> <p>But you never called <em>calcAverage()</em> nor <em>determineGrade()</em> into the def of your <strong>main</strong>.</p> <p>If your <em>return(total)</em> into your <strong>main</strong>, then use <em>print(main())</em> (with no sense at a...
0
2016-10-12T19:42:20Z
[ "python", "module" ]
need help to read a file in python
40,007,002
<p>I am new to python but I have learned lots of stuff, but I found difficulty to read a JSON file. I need to read it in a way to access a particular data in this file. The file contain a data as follow: </p> <pre><code>[ 29723, 5426523, "this book need to be printed", "http://amzn.to/U60TaF" ][ 29...
0
2016-10-12T19:40:20Z
40,007,054
<p>Try</p> <pre><code>data = json.load(open(file_name)) </code></pre>
2
2016-10-12T19:43:50Z
[ "python" ]
Pandas DataFrame shift columns by date to create lag values
40,007,033
<p>I have a dataframe:</p> <pre><code>df = pd.DataFrame({'year':[2000,2000,2000,2001,2001,2002,2002,2002],'ID':['a','b','c','a','b','a','b','c'],'values':[1,2,3,4,5,7,8,9]}) </code></pre> <p><a href="https://i.stack.imgur.com/lKcOh.png" rel="nofollow"><img src="https://i.stack.imgur.com/lKcOh.png" alt="enter image de...
1
2016-10-12T19:42:32Z
40,007,751
<p>Suppose the <code>year</code> column is unique for each id, i.e, there are no duplicated years for each specific id, then you can shift the value firstly and then replace shifted values where the difference between the year at the current row and previous row is not equal to <code>1</code> with <code>NaN</code>:</p>...
2
2016-10-12T20:27:09Z
[ "python", "pandas", "dataframe", "panel-data" ]
Pandas DataFrame shift columns by date to create lag values
40,007,033
<p>I have a dataframe:</p> <pre><code>df = pd.DataFrame({'year':[2000,2000,2000,2001,2001,2002,2002,2002],'ID':['a','b','c','a','b','a','b','c'],'values':[1,2,3,4,5,7,8,9]}) </code></pre> <p><a href="https://i.stack.imgur.com/lKcOh.png" rel="nofollow"><img src="https://i.stack.imgur.com/lKcOh.png" alt="enter image de...
1
2016-10-12T19:42:32Z
40,009,361
<p>a <code>reindex</code> approach</p> <pre><code>def reindex_min_max(df): mn = df.year.min() mx = df.year.max() + 1 d = df.set_index('year').reindex(pd.RangeIndex(mn, mx, name='year')) return pd.concat([d, d['values'].shift().rename('pre_value')], axis=1) df.groupby('ID')[['year', 'values']].apply(re...
0
2016-10-12T22:23:57Z
[ "python", "pandas", "dataframe", "panel-data" ]
Converting DictVectorizer to TfIdfVectorizer
40,007,062
<p>I need to convert some data that I have in this format into a term document matrix: <a href="http://pastebin.com/u1A7v1CV" rel="nofollow">http://pastebin.com/u1A7v1CV</a></p> <p>Essentially, each row represents a document represented as word_label_id and frequency. The words corresponding to each word_label_id are ...
0
2016-10-12T19:44:18Z
40,007,715
<p>The output of the DictVectorizer is a SciPy sparse matrix just as you would have from TfIdfVectorizer. You can proceed with the feature selection and k-means clustering steps.</p>
1
2016-10-12T20:25:15Z
[ "python", "scikit-learn", "k-means", "tf-idf", "dictvectorizer" ]
Dask/hdf5: Read by group?
40,007,106
<p>I must read in and operate independently over many chunks of a large dataframe/numpy array. However, these chunks are chosen in a specific, non-uniform manner and are broken naturally into groups within a hdf5 file. Each group is small enough to fit into memory (though even without restriction, I suppose the standar...
2
2016-10-12T19:47:55Z
40,007,327
<p>I would read many dask.arrays from many groups as single-chunk dask.arrays and then concatenate or stack those groups.</p> <h3>Read many dask.arrays</h3> <pre><code>f = h5py.File(...) dsets = [f[dset] for dset in datasets] arrays = [da.from_array(dset, chunks=dset.shape) for dset in dsets] </code></pre> <h3>Alter...
1
2016-10-12T20:00:43Z
[ "python", "hdf5", "h5py", "dask" ]
Python or Numpy Approach to MATLAB's "cellfun"
40,007,120
<p>Is there a python or numpy approach similar to MATLABs "cellfun"? I want to apply a function to an object which is a MATLAB cell array with ~300k cells of different lengths. </p> <p>A very simple example:</p> <pre><code>&gt;&gt;&gt; xx = [(4,2), (1,2,3)] &gt;&gt;&gt; yy = np.exp(xx) Traceback (most recent call l...
0
2016-10-12T19:48:59Z
40,007,257
<p>The most readable/maintainable approach will probably be to use a <a href="https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a>:</p> <pre><code>yy = [ np.exp(xxi) for xxi in xx ] </code></pre> <p>That relies on <code>numpy.exp</code> to implicitly conver...
3
2016-10-12T19:57:05Z
[ "python", "numpy", "elementwise-operations" ]
Python or Numpy Approach to MATLAB's "cellfun"
40,007,120
<p>Is there a python or numpy approach similar to MATLABs "cellfun"? I want to apply a function to an object which is a MATLAB cell array with ~300k cells of different lengths. </p> <p>A very simple example:</p> <pre><code>&gt;&gt;&gt; xx = [(4,2), (1,2,3)] &gt;&gt;&gt; yy = np.exp(xx) Traceback (most recent call l...
0
2016-10-12T19:48:59Z
40,007,984
<p>MATLAB cells were it's attempt to handle general lists like a real language. But being MATLAB they have to be 2d. But in general, in Python uses lists where MATLAB uses cells. <code>numpy</code> arrays with <code>dtype=object</code> behave similarly, adding multidimensions.</p> <p>Taking the object array route, ...
2
2016-10-12T20:41:17Z
[ "python", "numpy", "elementwise-operations" ]
Duplicate element from for loop in BeautifulSoup
40,007,131
<p>Given the code:</p> <pre><code>import urllib import urllib.request from bs4 import BeautifulSoup from urllib.request import urlopen def make_soup(url): thepage = urllib.request.urlopen(url) soupdata = BeautifulSoup(thepage, "html.parser") return soupdata soup = make_soup("https://www.wellstar.org/loca...
0
2016-10-12T19:49:42Z
40,007,496
<p>could it be the indentation? How should the for loops be nested? in python I would expect something like:</p> <pre><code>for tabele ...: for specialty ...: spe.. for name ...: name ... print ... </code></pre> <p>or</p> <pre><code>for tabele ...: for specialty ...: spe.....
0
2016-10-12T20:10:57Z
[ "python", "web-scraping", "beautifulsoup" ]
Format nested list python
40,007,245
<pre><code>list=[['name1', 'maths,english'], ['name2', 'maths,science']] </code></pre> <p>I have a nested list that likes something like this, I am trying to work out how to format it so that the out put would be something like the following:</p> <pre><code>name1, maths,english name2, maths,science </code></pre> <p>...
0
2016-10-12T19:56:18Z
40,007,268
<p>Iterate over your groups and join the items from each group using a comma.</p> <pre><code>groups = [['name1', 'maths,english'], ['name2', 'maths,science']] for group in groups: print ', '.join(group) </code></pre>
5
2016-10-12T19:57:34Z
[ "python" ]
How do I make window visiable/invisible at runtime?
40,007,305
<p>I am using kivy to create a small Gui for my python program. This Gui is not always visible. So I start it with these settings:</p> <pre><code>Config.set('graphics', 'borderless', True) Config.set('graphics', 'resizable', False) Config.set('graphics', 'window_state', 'hidden') </code></pre> <p>However: Somewhere i...
1
2016-10-12T19:59:40Z
40,007,463
<p>It seems that if you are using the SDL provider you have a <strong>hide &amp; show</strong> functions on the Window object</p> <p>from the kivy.core.window docs:</p> <pre><code>hide() Added in 1.9.0 Hides the window. This method should be used on desktop platforms only. Note This feature requires the SDL2 window ...
2
2016-10-12T20:09:06Z
[ "python", "kivy" ]
How do I make window visiable/invisible at runtime?
40,007,305
<p>I am using kivy to create a small Gui for my python program. This Gui is not always visible. So I start it with these settings:</p> <pre><code>Config.set('graphics', 'borderless', True) Config.set('graphics', 'resizable', False) Config.set('graphics', 'window_state', 'hidden') </code></pre> <p>However: Somewhere i...
1
2016-10-12T19:59:40Z
40,007,538
<p>I'm not familiar with Kivy, but it looks like you just need to set it to visible.</p> <p><code>window_state</code>: string , one of 'visible', 'hidden', 'maximized' \ or 'minimized'</p> <p>from: <a href="https://kivy.org/docs/_modules/kivy/config.html" rel="nofollow">https://kivy.org/docs/_modu...
1
2016-10-12T20:14:01Z
[ "python", "kivy" ]
Repeat the same analysis for TWO files in a lot of directories
40,007,468
<p>I have a lot of data stored in two files found in folders with the structure shown on this <a href="https://i.stack.imgur.com/zfFZW.png" rel="nofollow">pic</a>. I wrote a small python script to process the two files in Subdir1 and would like to repeat it over Dir, so each Subdir gets visited. I searched stackoverflo...
0
2016-10-12T20:09:15Z
40,007,562
<p>Something like this:</p> <pre><code>subdirs = glob.glob("Dir/*/.") for subdir in subdirs: file1 = os.path.join(subdir, "File_1") file2 = os.path.join(subdir, "File_2") result = os.path.join(subdir, "result.txt") with open(file1, "rt") as input_file1: with open(file2, "rt") as input_file2: ...
0
2016-10-12T20:15:25Z
[ "python", "bash" ]
running local server .py prompts a text editor instead of opening page
40,007,469
<p>I have a file which currently works on my production site as mysite.com/pages/lister.py.</p> <p>I am trying to build a local version of the site. The index.php works and other pages work, but when I go to a .py page like: localhost/pages/lister.py it doesnt change the site, it just asks if I want to use gedit to op...
1
2016-10-12T20:09:16Z
40,008,360
<p>My configuration for .pl and .py scripts that write HTML directly out to a page is the following:</p> <pre><code>&lt;Directory "[put production path here]"&gt; Options Indexes FollowSymLinks ExecCGI AllowOverride All Require all granted &lt;/Directory&gt; </code></pre> <p>As I'm new to full stack work,...
0
2016-10-12T21:07:04Z
[ "php", "python", "lamp" ]
Python tile based game (2d array) player movement
40,007,549
<p>I'm making a rougelike in pygame, and I'm having trouble with player movement in a grid. This sample program shows how I plan to do it:</p> <pre><code>class P: def __init__(self, standing_on): self.standing_on = standing_on self.row, self.column = 4, 4 def __str__(self): return "@"...
1
2016-10-12T20:14:35Z
40,007,890
<p>The problem is your starting position. You need to draw a map without your player and then place the player on the map. Here is the solution that works:</p> <pre><code>class P: def __init__(self, standing_on): self.standing_on = standing_on self.row, self.column = 4, 4 def __str__(self): ...
1
2016-10-12T20:35:22Z
[ "python", "pygame" ]
Using Qt Designer files in python script
40,007,626
<p>I need to open a dialog from <em>login.py</em>, then if successful, the dialog will close and open a main-window from <em>home.py</em>. I need to do this with a file created by Qt Designer with pyuic4. In summary, I need to call <em>login.py</em> and <em>home.py</em> though <em>main.py</em>.</p> <p>Code of <em>main...
0
2016-10-12T20:19:01Z
40,010,245
<p>Create a class that derives from <code>QWidget</code>, and in its <code>__init__</code> instantiate the ui class, then call <code>setupUi(self)</code> on it. </p> <pre><code>class RunApp(): pass class MyDialog(QWidget): def __init__(self, parent=None): super().__init__() self.ui = Ui_Dia...
0
2016-10-13T00:04:31Z
[ "python", "pyqt", "qt-designer", "pyuic" ]
Using Qt Designer files in python script
40,007,626
<p>I need to open a dialog from <em>login.py</em>, then if successful, the dialog will close and open a main-window from <em>home.py</em>. I need to do this with a file created by Qt Designer with pyuic4. In summary, I need to call <em>login.py</em> and <em>home.py</em> though <em>main.py</em>.</p> <p>Code of <em>main...
0
2016-10-12T20:19:01Z
40,010,686
<p>For login page of PyQt based application. i would suggest use <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qstackedwidget.html" rel="nofollow">QstackedWidget</a></p> <blockquote> <p>Page1 in stackedwidget for login page </p> <p>Page2 in stackwidget for home screen</p> </blockquote> <p>all you need is a s...
0
2016-10-13T01:02:48Z
[ "python", "pyqt", "qt-designer", "pyuic" ]
Python: how to create sublists through loop?
40,007,691
<p>I have a long list containing elements that value from 0 to 100. What I want to do is find all the positions where my elements take on values [0,2]. Then find out all the positions of the values between 2 and 4, etc up to 98 and 100.</p> <p>Let's call the list containing the values ''list''. And let's call the resu...
-2
2016-10-12T20:23:59Z
40,007,811
<pre><code>import itertools l = list(range(10)) ## If you just want the values: print([(x,y) for (x,y) in itertools.combinations(l, 2) if abs(x-y)==2]) ## If you want the positions: for i, x in enumerate(l): for j, y in enumerate(l): if j &lt;= i: continue if abs(x-y) == 2: ...
0
2016-10-12T20:30:54Z
[ "python", "list", "loops" ]
Digital Image Processing via Python
40,007,759
<p>I am starting a new project with a friend of mine, we want to design a system that would alert the driver if the car is diverting from its original path and its dangerous. so in a nutshell we have to design a real-time algorithm that would take pictures from the camera and process them. All of this will be done in P...
0
2016-10-12T20:27:34Z
40,007,828
<p>You can search for this libraries: dlib, PIL (pillow), opencv and scikit learn image. This libraries are image processing libraries for python.</p> <p>Hope it helps.</p>
0
2016-10-12T20:31:44Z
[ "python", "image-processing" ]
Why tensor flow could not load csv
40,007,785
<p>I just installed tensor flow using pip and I try to run the following tutorial:</p> <p><a href="https://www.tensorflow.org/versions/r0.11/tutorials/tflearn/index.html" rel="nofollow">https://www.tensorflow.org/versions/r0.11/tutorials/tflearn/index.html</a></p> <pre><code># Data sets IRIS_TRAINING = "iris_training...
0
2016-10-12T20:29:25Z
40,009,254
<p>since my version is 11... They removed load_csv in 11 without changing the tutorial... I have to run version 0.10.0rc0 just to run the tutorial.</p>
0
2016-10-12T22:15:40Z
[ "python", "tensorflow" ]
Why tensor flow could not load csv
40,007,785
<p>I just installed tensor flow using pip and I try to run the following tutorial:</p> <p><a href="https://www.tensorflow.org/versions/r0.11/tutorials/tflearn/index.html" rel="nofollow">https://www.tensorflow.org/versions/r0.11/tutorials/tflearn/index.html</a></p> <pre><code># Data sets IRIS_TRAINING = "iris_training...
0
2016-10-12T20:29:25Z
40,032,112
<p>The function <code>tf.contrib.learn.datasets.base.load_csv()</code> was removed in TensorFlow release 0.11. Depending on whether the file has a header or not (and the Iris dataset does have a header), the replacement functions are:</p> <ul> <li><a href="https://github.com/tensorflow/tensorflow/blob/fcab4308002412e3...
1
2016-10-13T22:33:04Z
[ "python", "tensorflow" ]
Speeding up nested loops in python
40,007,800
<p>How can I speed up this code in python?</p> <pre><code>while ( norm_corr &gt; corr_len ): correlation = 0.0 for i in xrange(6): for j in xrange(6): correlation += (p[i] * T_n[j][i]) * ((F[j] - Fbar) * (F[i] - Fbar)) Integral += correlation T_n =np.mat(T_n) * np.mat(TT) ...
0
2016-10-12T20:30:27Z
40,007,999
<p>The way to do these things quickly is to use Numpy's built-in functions and operators to perform the operations. Numpy is implemented internally with optimized C code and if you set up your computation properly, it will run much faster.</p> <p>But leveraging Numpy effectively can sometimes be tricky. It's called "v...
0
2016-10-12T20:41:54Z
[ "python", "performance", "loops" ]
getpass.getpass() function in Python not working?
40,007,802
<p>Running on Windows 7 and using PyCharm 2016.2.3 if that matters at all.</p> <p>Anyway, I'm trying to write a program that sends an email to recipients, but I want the console to prompt for a password to login.</p> <p>I heard that <code>getpass.getpass()</code> can be used to hide the input. </p> <p>Here is my cod...
0
2016-10-12T20:30:35Z
40,008,031
<p>The problem you have is that you are launching it via PyCharm, which has it's own console (and is not the console used by <code>getpass</code>)</p> <p>Running the code via a command prompt should work</p>
1
2016-10-12T20:44:27Z
[ "python" ]
Multiprocessing | Multithreading ffmpeg in python
40,007,815
<p>I am developing a <a href="https://github.com/lordcantide/Alien-FFMPEG-Transcoder-Framework-for-HDHomeRun-PRIME" rel="nofollow">python WSGI script</a> to interface with an HDHomeRun Prime. In a perfect world it will pass URI values as commands to FFMPEG and display the resulting stream in a browser. I have the "show...
0
2016-10-12T20:31:02Z
40,014,136
<p>I don't really understand your whole process, but IMO you should start with <code>multithreading</code>, as it is much easier to setup (variables are shared like usual in Python). IF that doesn't meet your requirement (e.g not fast enough), you can move to <code>multiprocessing</code> but it will increase the comple...
0
2016-10-13T06:50:22Z
[ "python", "ffmpeg", "wsgi", "python-multithreading", "python-multiprocessing" ]
How to save lists that have been changed during execution?
40,007,864
<p>So, Im making a text based Rpg (very similar to Progress Quest). The only lists worth saving are the weapons and items lists as well as your name and class. At the beginning of the game, you get those two lists emptied and your name reset to 0.</p> <p><code>weapons = []</code> That is how it starts.</p> <p><code>w...
0
2016-10-12T20:33:28Z
40,007,908
<p>The canonical way to do this in Python is with the <code>pickle</code> module. For Python 3 the <a href="https://docs.python.org/3.5/library/pickle.html" rel="nofollow">documentation is here</a>. An example from this documentation:</p> <pre><code>import pickle # An arbitrary collection of objects supported by pick...
3
2016-10-12T20:36:43Z
[ "python", "list", "save" ]
python pandas - identify row of rolling maximum value from panel?
40,007,866
<p>Does Panel have anything like pan.idxmax(axis='items') which could return the row # or index for the largest value as in the question linked below which piRSquared answered perfectly? </p> <p><a href="http://stackoverflow.com/questions/40000718/python-pandas-possible-to-compare-3-dfs-of-same-shape-using-wheremax-is...
1
2016-10-12T20:33:30Z
40,026,017
<p>consider the <code>pd.Panel</code> <code>p</code></p> <pre><code>dfs = dict( one=pd.DataFrame(np.random.randint(1, 10, (5, 5))), two=pd.DataFrame(np.random.randint(1, 10, (5, 5))), three=pd.DataFrame(np.random.randint(1, 10, (5, 5))), ) p = pd.Panel(dfs) p.to_frame().unstack() </code></pre> <p><a href...
1
2016-10-13T16:10:43Z
[ "python", "pandas", "max", "panel", "vectorization" ]
Why Python pickling library complain about class member that doesn't exist?
40,008,010
<p>I have the following simple class definition:</p> <pre><code>def apmSimUp(i): return APMSim(i) def simDown(sim): sim.close() class APMSimFixture(TestCase): def setUp(self): self.pool = multiprocessing.Pool() self.sims = self.pool.map( apmSimUp, range(numCores) ...
0
2016-10-12T20:42:42Z
40,008,066
<p>It would help to see how your class looks, but if it has methods from <code>multiprocessing</code> you may have issues just pickling it by default. Multiprocessing objects can use locks as well, and these are (obviously) unpickle-able.</p> <p>You can customize pickling with the <a href="https://docs.python.org/dev/...
0
2016-10-12T20:47:14Z
[ "python", "serialization", "pickle" ]
Problems importing imblearn python package on ipython notebook
40,008,015
<p>I installed <a href="https://github.com/glemaitre/imbalanced-learn" rel="nofollow">https://github.com/glemaitre/imbalanced-learn</a> on windows powershell using pip install,conda and github. But when im on ipython notebook and i try importing the package using :</p> <pre><code>from unbalanced_dataset import UnderSa...
0
2016-10-12T20:42:45Z
40,008,278
<p>Try this:</p> <pre><code>from imblearn import under_sampling, over_sampling </code></pre> <p>In order to import <code>SMOTE</code>:</p> <pre><code>from imblearn.over_sampling import SMOTE </code></pre> <p>Or datasets:</p> <pre><code>from imblearn.datasets import ... </code></pre>
0
2016-10-12T21:01:38Z
[ "python", "python-2.7", "powershell", "jupyter-notebook" ]
scipy curve_fit strange result
40,008,017
<p>I am trying to fit a distribution with scipy's curve_fit. I tried to fit a one component exponential function which resulted in an almost straight line (see figure). I also tried a two component exponential fit which seemed to work nicely. Two components just means that a part of the equation repeats with different ...
0
2016-10-12T20:42:49Z
40,008,187
<p>In my experience <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html" rel="nofollow"><code>curve_fit</code></a> can sometimes act up and stick with the initial values for the parameters. I would suspect that in your case adding a few fake parameters changed the heuristics of ho...
0
2016-10-12T20:54:36Z
[ "python", "scipy" ]
How to find methods which are only defined in a subclass, in Python 2.7?
40,008,155
<p>Is there a clean way to get methods only defined in a subclass that not defined in parent class?</p> <pre><code>class Parent(object): def method_of_parent(self): pass class SubClass(Parent): def method_of_subclass(self): pass # desired: &gt;&gt;&gt; print(get_subclass_methods(SubClass))...
3
2016-10-12T20:52:32Z
40,008,332
<p>I think there are many corner cases but here is one of solutions.</p> <pre><code>import inspect class Parent(object): def method_of_parent(self): pass class SubClass(Parent): def method_of_subclass(self): pass def get_subclass_methods(child_cls): parents = inspect.getmro(child_cls...
3
2016-10-12T21:05:22Z
[ "python", "python-2.7", "methods", "subclass" ]
python error parsing json
40,008,219
<p>I'm trying to parse the information found in this link here: <a href="http://stats.nba.com/stats/playergamelog?DateFrom=&amp;DateTo=&amp;LeagueID=00&amp;PlayerID=203518&amp;Season=2016-17&amp;SeasonType=Pre+Season" rel="nofollow">http://stats.nba.com/stats/playergamelog?DateFrom=&amp;DateTo=&amp;LeagueID=00&amp;...
0
2016-10-12T20:57:31Z
40,008,954
<p>The webpage might be expecting a web browser to request the data from the URL. Try adding a user-agent to your request.</p> <pre><code>import requests HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/31.0'} urlPlayerLog = "http://stats.nba.com/stats/playergamelog?DateFro...
1
2016-10-12T21:50:03Z
[ "python", "json", "django" ]
Latest versions of Python 3 and PyQt5 working on Windows XP 32bit
40,008,236
<p>I developed a program with Python 3 64bit and PyQt5 on Debian 64bit (of course it works on Linux and Windows 10 64bit). The problem is I cannot find the last version (if it exists at all) of PyQt5 working on Windows XP 32bit. As I have read, it seems that Python version 3.4.4 is the newest/latest to work with Window...
0
2016-10-12T20:59:12Z
40,008,706
<p>You can find an archive of earlier installers and source code on sourceforge:</p> <ul> <li><a href="https://sourceforge.net/projects/pyqt/files/PyQt5/" rel="nofollow">https://sourceforge.net/projects/pyqt/files/PyQt5/</a></li> </ul> <p>The latest 32bit Windows installer for Python-3.4 seems to be for PyQt-5.5.1.</...
0
2016-10-12T21:31:38Z
[ "python", "windows", "python-3.x", "windows-xp", "pyqt5" ]
How to process panel data for use in a recurrent neural network (RNN)
40,008,240
<p>I have been doing some research on recurrent neural networks, but I am having trouble understanding if and how they could be used to analyze panel data (meaning cross-sectional data that is captured at different periods in time for several subjects -- see sample data below for example).Most examples of RNNs I have s...
0
2016-10-12T20:59:32Z
40,009,286
<p>I find no reason in being able to train neural network with panel data. What neural network does is that it maps one set of values with other set of values who have non-linear relation. In a time series a value at a particular instance depends on previous occuring values. Example: your pronunciation of a letter may ...
0
2016-10-12T22:17:33Z
[ "python", "recurrent-neural-network", "panel-data" ]
Need Help in python3, Wnat to set variables like they are increasing
40,008,273
<p>any ideas how to take middle number and put in middle of min and max?</p> <pre><code>x=input('Pirveli: ') y=input('Meore: ') z=input('Mesame: ') list = (ord(x),ord(y),ord(z)) print(min(list),(MIDDLENUMBER HERE),max(list)) </code></pre> <p>any ideas?</p>
-3
2016-10-12T21:01:19Z
40,008,294
<p>Yes. You can sort the list, and you'll get what you need.</p> <pre><code>&gt; lst = [4, 5, 3] &gt; lst.sort() &gt; lst [3, 4, 5] </code></pre> <p>You can also use <code>sorted</code> in a more general way on iterable objects. For example, given a tuple with <code>x</code>, <code>y</code>, <code>z</code>:</p> <pre...
2
2016-10-12T21:02:49Z
[ "python" ]
Repeat a string n times and print n lines of it
40,008,279
<p>i've been stuck on a question for some time now:</p> <p>I'm looking to create a python function that consumes a string and a positive integer. The function will print the string n times, for n lines. I <strong>cannot</strong> use loops, i must only use recursion</p> <p>e.g.</p> <pre><code>repeat("hello", 3) hell...
1
2016-10-12T21:01:41Z
40,008,347
<p>Try this</p> <pre><code>def f(string, n, c=0): if c &lt; n: print(string * n) f(string, n, c=c + 1) f('abc', 3) </code></pre>
3
2016-10-12T21:06:10Z
[ "python", "recursion" ]
Repeat a string n times and print n lines of it
40,008,279
<p>i've been stuck on a question for some time now:</p> <p>I'm looking to create a python function that consumes a string and a positive integer. The function will print the string n times, for n lines. I <strong>cannot</strong> use loops, i must only use recursion</p> <p>e.g.</p> <pre><code>repeat("hello", 3) hell...
1
2016-10-12T21:01:41Z
40,008,351
<p>You were really close.</p> <pre><code>def repeat(a, n): def rep(a, c): if c &gt; 0: print(a) rep(a, c - 1) return rep(a * n, n) print(repeat('ala', 2)) alaala alaala </code></pre> <p>A function with closure would do the job.</p>
0
2016-10-12T21:06:15Z
[ "python", "recursion" ]
Repeat a string n times and print n lines of it
40,008,279
<p>i've been stuck on a question for some time now:</p> <p>I'm looking to create a python function that consumes a string and a positive integer. The function will print the string n times, for n lines. I <strong>cannot</strong> use loops, i must only use recursion</p> <p>e.g.</p> <pre><code>repeat("hello", 3) hell...
1
2016-10-12T21:01:41Z
40,008,383
<p>So you just need extra argument that will tell you how many times you already ran that function, and it should have default value, because in first place function must take two arguments(<code>str</code> and positive number).</p> <pre><code>def repeat(a, n, already_ran=0): if n == 0: print(a*(n+already_...
1
2016-10-12T21:08:33Z
[ "python", "recursion" ]
Repeat a string n times and print n lines of it
40,008,279
<p>i've been stuck on a question for some time now:</p> <p>I'm looking to create a python function that consumes a string and a positive integer. The function will print the string n times, for n lines. I <strong>cannot</strong> use loops, i must only use recursion</p> <p>e.g.</p> <pre><code>repeat("hello", 3) hell...
1
2016-10-12T21:01:41Z
40,008,384
<p>You should (optionally) pass a 3rd parameter that handles the decrementing of how many lines are left:</p> <pre><code>def repeat(string, times, lines_left=None): print(string * times) if(lines_left is None): lines_left = times lines_left = lines_left - 1 if(lines_left &gt; 0): repe...
1
2016-10-12T21:08:34Z
[ "python", "recursion" ]
Repeat a string n times and print n lines of it
40,008,279
<p>i've been stuck on a question for some time now:</p> <p>I'm looking to create a python function that consumes a string and a positive integer. The function will print the string n times, for n lines. I <strong>cannot</strong> use loops, i must only use recursion</p> <p>e.g.</p> <pre><code>repeat("hello", 3) hell...
1
2016-10-12T21:01:41Z
40,008,504
<p>One liner</p> <pre><code>def repeat(a,n): print((((a*n)+'\n')*n)[:-1]) </code></pre> <p>Let's split this up</p> <ol> <li><code>a*n</code> repeats string <code>n</code> times, which is what you want in one line</li> <li><code>+'\n'</code> adds a new line to the string so that you can go to the next line</li> ...
2
2016-10-12T21:17:17Z
[ "python", "recursion" ]
Looping through table to calculate separations - Python
40,008,450
<p>Okay so I have a table of xy coordinates for a bunch of different points like this:</p> <blockquote> <pre><code> ID X Y 1 403.294 111.401 2 1771.424 62.183 3 804.812 71.674 4 2066.54 43.456 5 2208.55 40.907 </code></pre> </blockquote> <p>Eac...
0
2016-10-12T21:13:25Z
40,008,592
<p>The error occurs because math.sqrt() can only take a float value, if you pass an np.array it will attempt to convert to a float. This only works if the array contains a single value.</p> <pre><code>&gt; math.sqrt(np.array([2])) 1.4142135623730951 &gt; math.sqrt(np.array([2,1])) Traceback (most recent call last): ...
1
2016-10-12T21:24:06Z
[ "python", "loops", "numpy" ]
Rename colum header from another dataframe
40,008,455
<p>I have two dataframes where 1, 2, 3 is the connection between the dataframes:</p> <pre><code> 1 2 3 2016-10-03 12 10 10 2016-10-04 4 4 5 ...... and name year 1 apple 2001 2 lemon 2002 3 kiwi 1990 </code></pre> <p>The end result should be:</p> <pre><cod...
0
2016-10-12T21:13:47Z
40,008,663
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.rename.html" rel="nofollow"><code>rename</code></a>, which does not require the two DataFrames to have the keys in the same order:</p> <pre><code>df1 = df1.rename(columns=df2['name']) </code></pre>
0
2016-10-12T21:28:44Z
[ "python", "pandas", "dataframe" ]
yes/no input loop, issues with with correct looping
40,008,477
<p>I'm programming a short guessing game. But, I have no idea how prevent incorrect input (yes/no), preventing user to go forward. Here's a WORKING code. Tried with while True but it only messes the input even more. The furthest is that else, that notifies the player, but the q count move forward. </p> <pre><code># -...
0
2016-10-12T21:15:32Z
40,008,780
<p>You need a 'while' in here somewhere, once you hit the end of the 'for' block it will go to the next value in the range.</p> <pre><code>for y in xrange(len(testQ)): bGoodInput = False while not bGoodInput: reply = str(raw_input('\n'+str(abs(y-5))+ ' - ' + testQ[y]+' (y/n) --&gt; ')).lower().strip() ...
0
2016-10-12T21:37:29Z
[ "python", "loops" ]
yes/no input loop, issues with with correct looping
40,008,477
<p>I'm programming a short guessing game. But, I have no idea how prevent incorrect input (yes/no), preventing user to go forward. Here's a WORKING code. Tried with while True but it only messes the input even more. The furthest is that else, that notifies the player, but the q count move forward. </p> <pre><code># -...
0
2016-10-12T21:15:32Z
40,008,786
<p><code>while True:</code> will work, you need to <code>break</code> out of the loop once the conditions have been met.</p> <pre><code>while True: reply = str(raw_input('\n' + str(abs(y - 5)) + ' - ' + testQ[y] + ' (y/n) --&gt; ')).lower().strip() if reply in yes or reply in no: break </code></pre...
1
2016-10-12T21:38:12Z
[ "python", "loops" ]
Printing from lists
40,008,526
<p>I've got 3 different lists, all the data inside is coming from an external CSV file which works although how do I print each name with each number next to them</p> <pre><code>name = [] number1 = [] number2 = [] </code></pre> <p>for example expected output is, although I'm unsure how I would do this</p> <pre><co...
-5
2016-10-12T21:18:42Z
40,008,630
<p>You are probably looking for something like this:</p> <pre><code>name = ["Test1", "Test2", "Test3"] number1 = [1,2,3] number2 = [4,5,6] k=0 for v in name: print(v + ", " + str(number1[k]) + ", " + str(number2[k])) k+=1 </code></pre> <p><strong>EDIT</strong></p> <p>As MSeifert mentioned in the comment bel...
1
2016-10-12T21:26:45Z
[ "python", "list" ]
Printing from lists
40,008,526
<p>I've got 3 different lists, all the data inside is coming from an external CSV file which works although how do I print each name with each number next to them</p> <pre><code>name = [] number1 = [] number2 = [] </code></pre> <p>for example expected output is, although I'm unsure how I would do this</p> <pre><co...
-5
2016-10-12T21:18:42Z
40,009,091
<p>Here's a way to do it using zip:</p> <pre><code>for triplet in zip(name, number1, number2): print(", ".join(map(str, triplet))) </code></pre> <p>triplet is a 3-tuple <code>(a, b, c)</code> with the corresponding element from the 3 lists (in other words, they are zipped)</p>
1
2016-10-12T22:00:47Z
[ "python", "list" ]
Trying to install pycrypto on mac OS El capitan 10.11.6
40,008,571
<p>Trying to install pycrypto, running into an error </p> <p>When i run </p> <pre><code>&gt; sudo pip install pycrypto </code></pre> <p>I get </p> <blockquote> <p>Command "/usr/bin/python -u -c "import setuptools, tokenize;<strong>file</strong>='/private/tmp/pip-build-tTSWlY/pycrypto/setup.py';exec(compile(geta...
-2
2016-10-12T21:22:27Z
40,009,161
<p>Using <a href="http://conda.pydata.org/miniconda.html" rel="nofollow">miniconda</a>, you can simply do:</p> <p><code>conda install pycrypto</code></p>
0
2016-10-12T22:06:17Z
[ "python", "osx", "terminal", "osx-elcapitan", "pycrypto" ]
How to convert some string fields in list to integer in Python?
40,008,661
<p>I have a string list and want to convert last value to integer, </p> <pre><code>[['wind turbine', 'feed induction generator', '16'], ['wind turbine', 'dynamic model', '6'], ['electrical model', 'dynamic model', '4']] </code></pre> <p>I want just convert last fields to integer. </p> <p>results something like this:...
-5
2016-10-12T21:28:25Z
40,008,971
<pre><code>L = [['wind turbine', 'feed induction generator', '16'],['wind turbine', 'dynamic model', '6'],['electrical model', 'dynamic model', '4']] for i in L: i[-1] = int(i[-1]) print(L) </code></pre> <p>hope this helps</p>
-2
2016-10-12T21:51:16Z
[ "python" ]
How to convert some string fields in list to integer in Python?
40,008,661
<p>I have a string list and want to convert last value to integer, </p> <pre><code>[['wind turbine', 'feed induction generator', '16'], ['wind turbine', 'dynamic model', '6'], ['electrical model', 'dynamic model', '4']] </code></pre> <p>I want just convert last fields to integer. </p> <p>results something like this:...
-5
2016-10-12T21:28:25Z
40,008,991
<p>Update : Added support for float numbers. </p> <p>We can use <code>isdigit()</code> for positive int and <code>str(x).startswith('-') and x[1:].isdigit()</code> for negative int as well as <code>isFloat(aNumber)</code> for float numbers. </p> <p>Below code works with both positive and negative int.</p> <pre><cod...
-2
2016-10-12T21:52:38Z
[ "python" ]
How can I define a Nix environment that defaults to Python 3.5
40,008,731
<p>I have defined a the following environment in <code>default.nix</code>:</p> <pre><code>with import &lt;nixpkgs&gt; {}; stdenv.mkDerivation rec { name = "env"; env = buildEnv { name = name; paths = buildInputs; }; buildInputs = [ python35 python35Packages.pyyaml ]; } </code></pre> <p>If I run <code>...
1
2016-10-12T21:33:56Z
40,016,749
<p>One simple solution could be to add a shell hook to your environment, to define an alias from <code>python</code> to <code>python3</code>. This alias will be active only when you run <code>nix-shell</code>:</p> <pre><code>with import &lt;nixpkgs&gt; {}; stdenv.mkDerivation rec { name = "env"; env = buildEnv { n...
1
2016-10-13T09:10:15Z
[ "python", "nix" ]
Export multiple scraped files in python from beautiful soup to a cvs file
40,008,742
<p>I have a csv list of urls that I need to scrape and organize into a csv file. I want the data from each url to be a row in the csv file. I have about 19000 urls to scrape, but am trying to figure this out using only handful. I am able to scrape the files and view them in the terminal, but when I export them to the c...
0
2016-10-12T21:34:47Z
40,112,614
<p>Your indenting is completely off, try the following:</p> <pre><code>from bs4 import BeautifulSoup import csv import re import pandas as pd import requests with open('/Users/test/Dropbox/one_minute_json/Extracting Data/a_2005_test.csv') as f: reader = csv.reader(f) index = 0 df = pd.DataFrame(colum...
0
2016-10-18T15:43:33Z
[ "python", "csv", "beautifulsoup" ]
Analogs for Placeholder from Django-CMS or Streamfield from Wagtail without cms itself
40,008,775
<p>I often need to implement rich content editing in my django projects. There are a lot of different wysiwyg-editors, but they are not good for creating complex content structure. Placeholder from Django-CMS or Streamfield from Wagtail can do it much better, but I don't want to add whole CMS to my project, because it ...
0
2016-10-12T21:37:09Z
40,009,135
<p>Django CMS is very modular - you do not need to bring in the whole URL and page management interface.</p> <p>You can enhance your existing models with Django CMS's placeholder fields and use the rich structure mode and plugins only, for example:</p> <pre><code>from django.db import models from cms.models.fields im...
0
2016-10-12T22:04:13Z
[ "python", "django", "wysiwyg", "django-cms", "wagtail-streamfield" ]
Script for replacing digits
40,008,777
<p>I have a file that has content as below</p> <pre><code>a b c 123.67989 aa bb cc 56789.38475 b c a 56789.3456 bb cc aa 0.12409124 c a b 0.0123123 </code></pre> <p>I am trying to remove digits after the <code>.</code> in the each line. Is there is a way to do this using regu...
-3
2016-10-12T21:37:20Z
40,008,906
<p>I didn't use regular expressions but maybe this helps:</p> <pre><code>text = "a b c 123.67989 \n" \ "aa bb cc 56789.38475 \n" \ "b c a 56789.3456 \n" \ "bb cc aa 0.12409124 \n" \ "c a b 0.0123123" lines = text.splitlines() for line in lines: line_without_digits = line.spli...
1
2016-10-12T21:46:55Z
[ "python", "python-3.x" ]
Script for replacing digits
40,008,777
<p>I have a file that has content as below</p> <pre><code>a b c 123.67989 aa bb cc 56789.38475 b c a 56789.3456 bb cc aa 0.12409124 c a b 0.0123123 </code></pre> <p>I am trying to remove digits after the <code>.</code> in the each line. Is there is a way to do this using regu...
-3
2016-10-12T21:37:20Z
40,008,978
<p>No regex here, either, but:</p> <pre><code>with open( "C:/TestFile.txt", 'r' ) as file: lines = file.readlines() out_lines = [] out_file = open( "C:/TestFile2.txt", "w" ) for i in range( len( lines ) ): out_lines.append( lines[ i ].split( "." )[0] ) for line in out_lines: out_file.write( "%s\n" % line ...
0
2016-10-12T21:51:51Z
[ "python", "python-3.x" ]
Script for replacing digits
40,008,777
<p>I have a file that has content as below</p> <pre><code>a b c 123.67989 aa bb cc 56789.38475 b c a 56789.3456 bb cc aa 0.12409124 c a b 0.0123123 </code></pre> <p>I am trying to remove digits after the <code>.</code> in the each line. Is there is a way to do this using regu...
-3
2016-10-12T21:37:20Z
40,013,738
<p>Get only digits with one decimal value:</p> <pre><code>import re text = """ a b c 123.67989 aa bb cc 56789.38475 b c a 56789.3456 bb cc aa 0.12409124 c a b 0.0123123 """ digits = re.findall(r'\d+\.\d{1}', text) print(digits) # prints: ['123.6', '56789.3', '56789.3', '0.1...
0
2016-10-13T06:26:31Z
[ "python", "python-3.x" ]
Odd behavior with python basemap and pcolormesh
40,008,778
<p>I'm trying to plot longitudinal strips of binned data by making a numpy.meshgrid, converting the coordinates to map x,y coordinates using Basemap(), and then making a pcolormesh which is applied over the map. Code is for Python 2.7:</p> <pre><code>import numpy as np from mpl_toolkits.basemap import Basemap, shiftgr...
0
2016-10-12T21:37:26Z
40,062,415
<p>After some additional looking around I stumbled across this post: <a href="https://stackoverflow.com/questions/18186047/map-projection-and-forced-interpolation">Map projection and forced interpolation</a></p> <p>This solved my problems for now, so I'm linking in case someone else runs into this issue.</p>
0
2016-10-15T17:59:09Z
[ "python", "numpy", "matplotlib", "matplotlib-basemap" ]
Schedule table updates in Django
40,008,788
<p>How do you schedule updating the contents of a database table in Django based on time of day. For example every 5 minutes Django will call a REST api to update contents of a table.</p>
1
2016-10-12T21:38:23Z
40,009,025
<p>I think this is likely best accomplished by writing a server-side python script and adding a cronjob </p>
0
2016-10-12T21:55:21Z
[ "python", "django", "django-models" ]
Schedule table updates in Django
40,008,788
<p>How do you schedule updating the contents of a database table in Django based on time of day. For example every 5 minutes Django will call a REST api to update contents of a table.</p>
1
2016-10-12T21:38:23Z
40,009,031
<p>Based upon your question, I am not 100% clear what you are looking for. But, assuming you are looking to run some sort of a task every 5 minutes (that will make calls to the DB), then I <strong>highly</strong> suggest you look at <a href="http://www.celeryproject.org/" rel="nofollow">Celery</a>. </p> <p>It is a rob...
1
2016-10-12T21:56:02Z
[ "python", "django", "django-models" ]
Sentinel not working properly
40,008,800
<pre><code>def load(): global name global count global shares global pp global sp global commission name=input("Enter stock name OR -999 to Quit: ") count =0 while name != '-999': count=count+1 shares=int(input("Enter number of shares: ")) pp=float(input("...
0
2016-10-12T21:38:57Z
40,008,909
<p>Remove <code>calc()</code> and <code>display()</code> from <code>main()</code>. You're already doing those things in <code>load()</code>.</p>
1
2016-10-12T21:47:02Z
[ "python", "python-3.x", "sentinel" ]
how to save/crop detected faces in dlib python
40,008,806
<p>i want to save the detected face in dlib by cropping the rectangle do anyone have any idea how can i crop it. i am using dlib first time and having so many problems. i also want to run the fisherface algorithm on the detected faces but it is giving me type error when i pass the detected rectangle to pridictor. i ser...
2
2016-10-12T21:39:12Z
40,019,580
<p>Please use minimal-working sample code to get answers faster. </p> <p>After you have detected face - you have a rect. So <strong>you can crop image and save with opencv functions</strong>:</p> <pre><code> img = cv2.imread("test.jpg") dets = detector.run(img, 1) for i, d in enumerate(dets): print...
-1
2016-10-13T11:21:04Z
[ "python", "opencv", "face-detection", "face-recognition", "dlib" ]
how to save/crop detected faces in dlib python
40,008,806
<p>i want to save the detected face in dlib by cropping the rectangle do anyone have any idea how can i crop it. i am using dlib first time and having so many problems. i also want to run the fisherface algorithm on the detected faces but it is giving me type error when i pass the detected rectangle to pridictor. i ser...
2
2016-10-12T21:39:12Z
40,025,317
<p>Should be like this:</p> <pre><code>crop_img = img_full[d.top():d.bottom(),d.left():d.right()] </code></pre>
0
2016-10-13T15:35:58Z
[ "python", "opencv", "face-detection", "face-recognition", "dlib" ]
Running Jupyter/IPython document on Zepplin
40,008,886
<p>I have a large set of existing documents running on Jupyter. I want to move to Zeppelin.</p> <p>I assume Jupyter pages run in Zeppelin, but I can't find any documentation. Has anyone tried this? Does it work? Anyone have a useful link?</p> <p>Thanks Peter</p>
1
2016-10-12T21:44:42Z
40,019,541
<p>Jupyter's ipynb is json file. You can find <a href="http://nbformat.readthedocs.io/en/latest/" rel="nofollow">The Jupyter Notebook Format</a></p> <p>Zeppelin's note.json is also json format. Each notebook has an folder(notebook id) and note.json. </p> <p>It should be possible to convert with a small application. I...
0
2016-10-13T11:19:10Z
[ "python", "apache-spark", "jupyter", "apache-zeppelin" ]