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 |
|---|---|---|---|---|---|---|---|---|---|
Calculating mean value in DataFrame using a mask | 38,834,031 | <p>I have the following DataFrame:</p>
<pre><code> DATA Price1 Price2 Price3
sys dis
27 0.8 43.89 83.06 33.75
0.9 2.56 12.19 2.48
1.0 42.28 1.87 1.93
1.2 22.70 ... | 1 | 2016-08-08T16:15:02Z | 38,835,126 | <p>IIUC:</p>
<pre><code>idx_s = df.index.to_series()
lvl1 = idx_s.str.get(0)
gt_1 = np.where(idx_s.str.get(1) > 1, 'GT_1', 'LE_1')
df.groupby([lvl1, gt_1]).mean()
</code></pre>
<p><a href="http://i.stack.imgur.com/tfQEQ.png" rel="nofollow"><img src="http://i.stack.imgur.com/tfQEQ.png" alt="enter image description ... | 0 | 2016-08-08T17:22:26Z | [
"python",
"pandas",
"dataframe"
] |
Python : How to check if a given site is accessible through a proxy network? | 38,834,104 | <p>If our network has a proxy , then some sites can not be opened.
I want to check iteratively , how many sites can be accessed through our network.</p>
| 0 | 2016-08-08T16:19:47Z | 38,834,146 | <p>Find out what the source code of the Proxy Block page is.</p>
<p>Use <code>urllib</code> and <code>BeautifulSoup</code> to try and scrape the page and parse the page's source code to see if you can find something unique that can tell you if the site is accessible or not.</p>
<p>For example, in my office, when a pa... | 0 | 2016-08-08T16:22:10Z | [
"python",
"python-3.x",
"url"
] |
Split and parse (to new file) string every nth character iterating over starting character - python | 38,834,118 | <p>I asked a more general approach to this problem in a <a href="http://stackoverflow.com/questions/38727914/split-python-string-every-nth-character-iterating-over-starting-character">previous post</a> but I am getting stuck with trying to parse out my results to individual files. I want to iterate over a long string, ... | 0 | 2016-08-08T16:20:34Z | 38,836,251 | <p>A few things:</p>
<ol>
<li>You define the variables <code>seq</code> and <code>read_num</code> in the global scope, and then also use the same parameters in your function. What you should be doing is have the names of the parameters in the function definition be different, and then passing those two variables to th... | 2 | 2016-08-08T18:37:27Z | [
"python",
"loops",
"parsing"
] |
Split and parse (to new file) string every nth character iterating over starting character - python | 38,834,118 | <p>I asked a more general approach to this problem in a <a href="http://stackoverflow.com/questions/38727914/split-python-string-every-nth-character-iterating-over-starting-character">previous post</a> but I am getting stuck with trying to parse out my results to individual files. I want to iterate over a long string, ... | 0 | 2016-08-08T16:20:34Z | 38,836,920 | <h2>Edit in response to clarifying comment:</h2>
<p>Essentially, you want a rolling window of your string. Say <code>long_string = "012345678901234567890123456789..."</code> for a total length of 100. </p>
<pre><code>In [18]: long_string
Out[18]: '0123456789012345678901234567890123456789012345678901234567890123456789... | 0 | 2016-08-08T19:17:08Z | [
"python",
"loops",
"parsing"
] |
Celery not carrying out a scheduled, repeating, task | 38,834,206 | <p>I'm using Django to set up a web-server that monitors prices on a stock. I therefore want a task (updating the price) to occur every 5 seconds, with a console log telling me about the update. Why won't Celery write to console as asked?</p>
<p>My file structure:</p>
<pre><code>âââ Project
â âââ cele... | 0 | 2016-08-08T16:25:54Z | 39,588,222 | <p>Make sure you run the <a href="http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#starting-the-scheduler" rel="nofollow">celery beat scheduler</a>, e.g. <code>celery -A Project beat</code></p>
| 0 | 2016-09-20T07:31:49Z | [
"python",
"django",
"celery"
] |
Run subprocess with several commands and detach to background keeping order | 38,834,243 | <p>I'm using the <code>subprocess</code> module to execute two commands:</p>
<pre><code>import shlex
from subprocess import check_call()
def comm_1(error_file):
comm = shlex("mkdir /tmp/kde")
try:
check_call(comm)
except subprocess.CalledProcessError:
error_file.write("Error comm_1")
... | 0 | 2016-08-08T16:28:14Z | 38,834,928 | <p>You can check to make sure the process inside of <code>comm_1</code> dies before starting the subprocess call within <code>comm_2</code> by using <a href="https://docs.python.org/3/library/subprocess.html#subprocess.Popen.wait" rel="nofollow"><code>wait()</code></a>. But to do so, you're going to have to use <a href... | 0 | 2016-08-08T17:09:15Z | [
"python",
"linux",
"subprocess"
] |
Make a new array | 38,834,271 | <p>I am writing a program that parses sequence alleles. I have written code that reads a file and creates a header array and a sequence array. Here is an example of a file:</p>
<pre><code>>DQB1*04:02:01
------------------------------------------------------------
--ATGTCTTGGAAGAAGGCTTTGCGGAT-------CCCTGGAGGCCTTCGGG... | 1 | 2016-08-08T16:29:37Z | 38,834,726 | <p>Why do you want to use <code>re.finditer</code>?</p>
<p>What about</p>
<pre><code>if header[m].find('OMIXON') > -1 or header[m].find('GENDX') > -1:
</code></pre>
| 2 | 2016-08-08T16:56:46Z | [
"python",
"arrays",
"python-2.7",
"header",
"sequence"
] |
Make a new array | 38,834,271 | <p>I am writing a program that parses sequence alleles. I have written code that reads a file and creates a header array and a sequence array. Here is an example of a file:</p>
<pre><code>>DQB1*04:02:01
------------------------------------------------------------
--ATGTCTTGGAAGAAGGCTTTGCGGAT-------CCCTGGAGGCCTTCGGG... | 1 | 2016-08-08T16:29:37Z | 38,834,901 | <p>You can do this very easily using <a href="http://biopython.org/wiki/Biopython" rel="nofollow">Biopython</a>, assuming your sequences are saved in a FASTA file.</p>
<pre><code>from Bio import SeqIO
headers = [record.id for record in SeqIO.parse("myfile.fasta", "fasta")][1:]
</code></pre>
<p>and you're done.</p>
... | 0 | 2016-08-08T17:07:26Z | [
"python",
"arrays",
"python-2.7",
"header",
"sequence"
] |
Make a new array | 38,834,271 | <p>I am writing a program that parses sequence alleles. I have written code that reads a file and creates a header array and a sequence array. Here is an example of a file:</p>
<pre><code>>DQB1*04:02:01
------------------------------------------------------------
--ATGTCTTGGAAGAAGGCTTTGCGGAT-------CCCTGGAGGCCTTCGGG... | 1 | 2016-08-08T16:29:37Z | 38,834,968 | <p>The re.finditer function does not do what you think it does. For an example, see <a href="http://www.saltycrane.com/blog/2007/10/python-finditer-regular-expression/" rel="nofollow">here</a>.</p>
<p>I would recommend using this instead:</p>
<pre><code>if header[m][1:7] == 'OMIXON' or header[m][1:6]=='GENDX':
</code... | 0 | 2016-08-08T17:12:00Z | [
"python",
"arrays",
"python-2.7",
"header",
"sequence"
] |
path to a directory as argparse argument | 38,834,378 | <p>Problem: I want a write a directory's path as user's input in an add.argument of ArgumentParser().</p>
<p>So far: I have written this </p>
<pre><code>import argparse
parser = argparse.ArgumentParser()
parser.add_argument('path', option = os.chdir(input("paste here path to biog.txt file:")), help= 'paste path to b... | 0 | 2016-08-08T16:36:09Z | 38,835,157 | <p>You can use something like:</p>
<pre><code>import argparse, os
parser = argparse.ArgumentParser()
parser.add_argument('--path', help= 'paste path to biog.txt file')
args = parser.parse_args()
os.chdir(args.path) # to change directory to argument passed for '--path'
print os.getcwd()
</code></pre>
<p>Pass the d... | 0 | 2016-08-08T17:24:22Z | [
"python",
"argparse"
] |
Getting python to run an application when the application needs an input file | 38,834,480 | <pre><code>import subprocess
subprocess.call(['C:\\Users\michael\\Desktop\\Test\\pdftotext'])
</code></pre>
<p>pdftotext is the application that will run if I use this ^ code. This works fine, however, I'm trying to find a way to run pdftotext that includes the pdf's file name which pdftotext uses to convert it into a... | 0 | 2016-08-08T16:41:27Z | 38,834,548 | <p><a href="https://docs.python.org/2/library/subprocess.html" rel="nofollow">subprocess.call</a> takes an iterable where the first item is the executable and the following are switches and parameters.</p>
<p>This means you need to change the above to this:</p>
<pre><code>import subprocess
subprocess.call(['C:\\Users... | 2 | 2016-08-08T16:46:25Z | [
"python",
"windows",
"python-3.x",
"cmd"
] |
Scikit-image and central moments: what is the meaning? | 38,834,495 | <p>Looking for examples of how to use image processing tools to "describe" images and shapes of any sort, I have stumbled upon the <a href="http://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.moments_central" rel="nofollow">Scikit-image</a> <code>skimage.measure.moments_central(image, cr, cc, orde... | 0 | 2016-08-08T16:42:09Z | 38,860,218 | <p>The array returned by <code>measure.moments_central</code> correspond to the formula of <a href="https://en.wikipedia.org/wiki/Image_moment" rel="nofollow">https://en.wikipedia.org/wiki/Image_moment</a> (section central moment). mu_00 corresponds indeed to the area of the object.</p>
<p><a href="http://i.stack.imgu... | 2 | 2016-08-09T20:52:23Z | [
"python",
"image-processing",
"canopy",
"scikit-image"
] |
Python - CherryPy testing - set session data? | 38,834,632 | <p>When running a pytest unit test against a CherryPy server, using a cherrypy.helper.CPWebCase sub-class, how can I set data for the session object? I tried just calling <code>cherrypy.session['foo']='bar'</code> like I would if I was really in a cherrypy call, but that just gave an <code>"AttributeError: '_Serving' o... | 0 | 2016-08-08T16:50:15Z | 39,044,461 | <p>What you are trying to achieve is usually referred as <a href="https://docs.python.org/3/library/unittest.mock.html" rel="nofollow"><em>mocking</em></a>.</p>
<p>While running tests you'd usually want to 'mock' some of resources you access with dummy objects having same interface (duck typing). This may be achieved ... | 1 | 2016-08-19T17:10:07Z | [
"python",
"session",
"py.test",
"cherrypy"
] |
'is' operator behaves unexpectedly with floats | 38,834,770 | <p>I came across a confusing problem when unit testing a module. The module is actually casting values and I want to compare this values.</p>
<p>There is a difference in comparison with <code>==</code> and <code>is</code> (partly, I'm beware of the difference)</p>
<pre><code>>>> 0.0 is 0.0
True # as expect... | 7 | 2016-08-08T16:59:39Z | 38,835,030 | <p>This has to do with how <code>is</code> works. It checks for references instead of value. It returns <code>True</code> if either argument is assigned to the same object.</p>
<p>In this case, they are different instances; <code>float(0)</code> and <code>float(0)</code> have the same value <code>==</code>, but are di... | 20 | 2016-08-08T17:15:36Z | [
"python",
"python-2.7",
"python-3.x",
"floating-point",
"python-internals"
] |
'is' operator behaves unexpectedly with floats | 38,834,770 | <p>I came across a confusing problem when unit testing a module. The module is actually casting values and I want to compare this values.</p>
<p>There is a difference in comparison with <code>==</code> and <code>is</code> (partly, I'm beware of the difference)</p>
<pre><code>>>> 0.0 is 0.0
True # as expect... | 7 | 2016-08-08T16:59:39Z | 38,835,101 | <p>If a <code>float</code> object is supplied to <code>float()</code>, <em>CPython</em>* just returns it without making a new object. </p>
<p>This can be seen in <a href="https://github.com/python/cpython/blob/954b23e8571dfe4ea94a03fde134f289f9845f2c/Objects/abstract.c#L1348" rel="nofollow"><code>PyNumber_Float</code>... | 9 | 2016-08-08T17:20:23Z | [
"python",
"python-2.7",
"python-3.x",
"floating-point",
"python-internals"
] |
How to Remove the Data in a Specific Column for the Duplicate IDs? | 38,834,788 | <p>I have this simple dataframe: </p>
<pre><code>ID Name State
1 John DC
1 John VA
2 Smith NE
3 Janet CA
3 Janet NC
3 Janet MD
</code></pre>
<p>I want to delete the <code>State</code> value for the duplicate <code>IDs</code> like so:</p>
<pre><code>ID Name State
1 John n... | 2 | 2016-08-08T17:00:31Z | 38,834,855 | <p><code>duplicated</code> returns a boolean mask where rows are duplicated over the columns defined in <code>subset</code>. <code>keep=False</code> indicates that we shouldn't consider the first or last of the duplicates as non-duplicate. Using <code>loc</code> then allows us to assign to the rows where duplicates h... | 3 | 2016-08-08T17:04:20Z | [
"python",
"pandas",
"dataframe",
"duplicates"
] |
How to Remove the Data in a Specific Column for the Duplicate IDs? | 38,834,788 | <p>I have this simple dataframe: </p>
<pre><code>ID Name State
1 John DC
1 John VA
2 Smith NE
3 Janet CA
3 Janet NC
3 Janet MD
</code></pre>
<p>I want to delete the <code>State</code> value for the duplicate <code>IDs</code> like so:</p>
<pre><code>ID Name State
1 John n... | 2 | 2016-08-08T17:00:31Z | 38,834,945 | <p>you can use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html" rel="nofollow">np.where</a>:</p>
<pre><code>In[25]:df['State']=np.where(df['Name'].duplicated(keep=False),np.nan,df['State'])
In[26]:df
Out[26]:
ID Name State
0 1 John NaN
1 1 John NaN
2 2 Smith NE
3 ... | 2 | 2016-08-08T17:10:48Z | [
"python",
"pandas",
"dataframe",
"duplicates"
] |
Multiple with statements in Python 2.7 using a list comprehension | 38,834,827 | <h1>Question:</h1>
<p>I am interested in doing a list comprehension <strong>inside</strong> a Python <code>with</code> statement, so that I can open multiple context managers at the same time with minimal syntax. I am looking for answers that work with <strong>Python 2.7</strong>.</p>
<p>Consider the following code e... | 2 | 2016-08-08T17:02:45Z | 38,835,226 | <p>The major tasks of <code>with</code> statement is invoking the <code>__exit__</code> attribute of its context manager. Specially for dealing with files. So In this case due to this point and the fact that <code>open()</code> returns an <code>file_object</code> you can dimple use a list comprehension in order to crea... | 2 | 2016-08-08T17:29:02Z | [
"python",
"python-2.7",
"list-comprehension",
"with-statement"
] |
Multiple with statements in Python 2.7 using a list comprehension | 38,834,827 | <h1>Question:</h1>
<p>I am interested in doing a list comprehension <strong>inside</strong> a Python <code>with</code> statement, so that I can open multiple context managers at the same time with minimal syntax. I am looking for answers that work with <strong>Python 2.7</strong>.</p>
<p>Consider the following code e... | 2 | 2016-08-08T17:02:45Z | 38,835,403 | <p>Doing this yourself is really tricky, especially handling exceptions that occur while opening or closing the files. I'd recommend just getting a library like <a href="https://contextlib2.readthedocs.io/en/stable/" rel="nofollow"><code>contextlib2</code></a> that implements the <code>contextlib.ExitStack</code> funct... | 2 | 2016-08-08T17:40:24Z | [
"python",
"python-2.7",
"list-comprehension",
"with-statement"
] |
Filter Azure Table Storage by RowKey and StartsWith using the Python SDK | 38,834,919 | <p>I have seen that Azure Table Storage supports querying records by a partial <code>RowKey</code> (in addition to the <code>PartitionKey</code>) (C# example <a href="https://alexandrebrisebois.wordpress.com/2014/10/30/azure-table-storage-using-startswith-to-filter-on-rowkeys/" rel="nofollow">here</a>).</p>
<p>However... | 0 | 2016-08-08T17:08:27Z | 38,835,539 | <p>Assuming your RowKey values contains words and you only want to filter the words starting with <code>a</code> and <code>b</code>, this is what you would add to your query:</p>
<pre><code>(RowKey ge 'a' and RowKey lt 'c') ==> (RowKey >= 'a' && RowKey < 'c')
</code></pre>
<p>So your code would be so... | 1 | 2016-08-08T17:48:24Z | [
"c#",
"python",
"rest",
"azure",
"azure-storage-tables"
] |
Django Query lookup using Q Not Returning the Right Result | 38,834,996 | <p>I want to do a basic query search. I want to use the fields <code>city</code> and <code>area</code> to perform datatbase lookup.</p>
<p>I want a case whereby if the user input the city and area in the search field, it should return the results. Also if the user input either city or area it should return the result.... | 0 | 2016-08-08T17:13:39Z | 38,835,411 | <p>In general all the kwargs in filter() are AND'ed together you can know more about complex look ups using Q in the <a href="https://docs.djangoproject.com/en/1.10/topics/db/queries/#complex-lookups-with-q-objects" rel="nofollow">Django Documentation</a></p>
<pre><code># For performing OR operation
hots= Place.object... | 1 | 2016-08-08T17:40:54Z | [
"python",
"django"
] |
Django Query lookup using Q Not Returning the Right Result | 38,834,996 | <p>I want to do a basic query search. I want to use the fields <code>city</code> and <code>area</code> to perform datatbase lookup.</p>
<p>I want a case whereby if the user input the city and area in the search field, it should return the results. Also if the user input either city or area it should return the result.... | 0 | 2016-08-08T17:13:39Z | 38,836,143 | <p>You should go with the or operator "|" if you want to accept a query of city only or area only. I suggest you to print variable q after being taken from request to see what in it and do your database query again. Another thought is maybe you should split the value of q into city and area.</p>
| 1 | 2016-08-08T18:30:52Z | [
"python",
"django"
] |
Python: regex elements match with List | 38,835,193 | <p>I have a list, I want to compare each element of list against a list of regex and then print only what is not found with regex.Regex are coming from a config file:</p>
<p><code>exclude_reg_list= qa*,bar.*,qu*x</code></p>
<p>Code:</p>
<pre><code>import re
read_config1 = open("config.ini", "r")
for line1 in read_co... | 1 | 2016-08-08T17:26:32Z | 38,837,241 | <p>Instead of using <strong>re</strong> module, I am going to use <strong>fnmatch</strong> module since it looks like wildcard pattern matching.</p>
<p>Please check this link for more information on <a href="https://docs.python.org/2/library/fnmatch.html" rel="nofollow">fnmatch</a>.</p>
<p>Extending your code for des... | 1 | 2016-08-08T19:39:06Z | [
"python",
"regex"
] |
delete python list in the correct order | 38,835,206 | <p>I tried to delete by this order: 11,12,13,21,22,23,31,32,33
and to stay with an empty list.
at the begining I tried the regular deletion, but then I understood that you must use int for deletion and you can't you the object so, I started to use enumerate function but the I saw another problem.
It was delete but not ... | 0 | 2016-08-08T17:27:45Z | 38,835,886 | <p>The issue is that you are iterating over your list while modifying it. This will often cause the exact problem you are encountering. Rather, you have have to iterate over indices (more like a classic-for-loop) and modify the list. Notice, though, you have to take into account that the index you are going to be delet... | 0 | 2016-08-08T18:14:19Z | [
"python",
"list",
"del"
] |
Adding lines of a text file to a dictionary | 38,835,309 | <p>I've been trying to think how I would exactly do this, but I cant seem to get anywhere. </p>
<p>If I have a text file that contains a host name with their made up corresponding ip address:</p>
<pre><code>The result of www.espn.com is 199.181.133.15
The result of www.espn.com is 199.454.152.10
The result of www.esp... | 1 | 2016-08-08T17:34:01Z | 38,835,374 | <p>Use dictionary of lists. For simple implementation use <a class='doc-link' href="http://stackoverflow.com/documentation/python/498/collections/1636/collections-defaultdict#t=201608030921439071977"><code>defaultdict</code></a> as follows:</p>
<pre><code>from collections import defaultdict
dictA = defaultdict(list)
f... | 2 | 2016-08-08T17:38:51Z | [
"python",
"list",
"dictionary"
] |
Adding lines of a text file to a dictionary | 38,835,309 | <p>I've been trying to think how I would exactly do this, but I cant seem to get anywhere. </p>
<p>If I have a text file that contains a host name with their made up corresponding ip address:</p>
<pre><code>The result of www.espn.com is 199.181.133.15
The result of www.espn.com is 199.454.152.10
The result of www.esp... | 1 | 2016-08-08T17:34:01Z | 38,835,406 | <p>You can make use of <code>defaultdict</code> from <code>collections</code> and set your default as a list:</p>
<pre><code>>>> from collections import defaultdict
>>> s = '''The result of www.espn.com is 199.181.133.15
... The result of www.espn.com is 199.454.152.10
... The result of www.espn.com ... | 3 | 2016-08-08T17:40:33Z | [
"python",
"list",
"dictionary"
] |
Adding lines of a text file to a dictionary | 38,835,309 | <p>I've been trying to think how I would exactly do this, but I cant seem to get anywhere. </p>
<p>If I have a text file that contains a host name with their made up corresponding ip address:</p>
<pre><code>The result of www.espn.com is 199.181.133.15
The result of www.espn.com is 199.454.152.10
The result of www.esp... | 1 | 2016-08-08T17:34:01Z | 38,835,563 | <p>Using a dictionary, you can do this:</p>
<pre><code>domain_name_to_ip_mappping = {}
with open('filename') as f:
for line in f:
data = line.split()
domain_name = data[3]
ip = data[-1]
if domain_name in domain_name_to_ip_mappping:
#domain name already exists, so simply... | 0 | 2016-08-08T17:50:25Z | [
"python",
"list",
"dictionary"
] |
Adding lines of a text file to a dictionary | 38,835,309 | <p>I've been trying to think how I would exactly do this, but I cant seem to get anywhere. </p>
<p>If I have a text file that contains a host name with their made up corresponding ip address:</p>
<pre><code>The result of www.espn.com is 199.181.133.15
The result of www.espn.com is 199.454.152.10
The result of www.esp... | 1 | 2016-08-08T17:34:01Z | 38,835,749 | <p>Like others have stated, it's easy to use <a href="https://docs.python.org/2/library/collections.html#collections.defaultdict" rel="nofollow"><code>defaultdict</code></a> to prime the values of your <strong>domain</strong> keys as a list, and just append the IP addresses to that list.</p>
<pre><code>from collection... | 1 | 2016-08-08T18:04:53Z | [
"python",
"list",
"dictionary"
] |
Joining Array In Python | 38,835,352 | <p>Hi I want to join multiple arrays in python, using numpy to form multidimensional arrays, it's inside of a for loop, this is a pseudocode</p>
<pre><code>import numpy as np
h = np.zeros(4)
for x in range(3):
x1 = some array of length of 4 returned from a previous function (3,5,6,7)
h = np.concatenate((h,x1), a... | 0 | 2016-08-08T17:37:05Z | 38,835,491 | <p>You need to use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.vstack.html" rel="nofollow">vstack</a>. It allows you to stack arrays. You take a sequence of arrays and stack them vertically to make a single array</p>
<pre><code> import numpy as np
h = np.zeros(4)
for x in range(3):
x1 =... | 1 | 2016-08-08T17:45:28Z | [
"python",
"arrays",
"numpy"
] |
Joining Array In Python | 38,835,352 | <p>Hi I want to join multiple arrays in python, using numpy to form multidimensional arrays, it's inside of a for loop, this is a pseudocode</p>
<pre><code>import numpy as np
h = np.zeros(4)
for x in range(3):
x1 = some array of length of 4 returned from a previous function (3,5,6,7)
h = np.concatenate((h,x1), a... | 0 | 2016-08-08T17:37:05Z | 38,835,601 | <p>It is best to collect values in a list, and perform the concatenate or array creation once, at the end.</p>
<pre><code>h = [np.zeros(4)]
for x in range(3):
x1 = some array of length of 4 returned from a previous function (3,5,6,7)
h = h.append(x1)
h = np.array(h)
# or h = np.vstack(h)
</code></pre>
<p>All th... | 1 | 2016-08-08T17:53:55Z | [
"python",
"arrays",
"numpy"
] |
Joining Array In Python | 38,835,352 | <p>Hi I want to join multiple arrays in python, using numpy to form multidimensional arrays, it's inside of a for loop, this is a pseudocode</p>
<pre><code>import numpy as np
h = np.zeros(4)
for x in range(3):
x1 = some array of length of 4 returned from a previous function (3,5,6,7)
h = np.concatenate((h,x1), a... | 0 | 2016-08-08T17:37:05Z | 38,835,861 | <p>There are multiple ways of doing this. I'll list a few examples: </p>
<p>First, we import <code>numpy</code> and define a function that generates those arrays of length 4. </p>
<pre class="lang-python prettyprint-override"><code>import numpy as np
def previous_function_returning_array_of_length_4(x):
return... | 1 | 2016-08-08T18:12:16Z | [
"python",
"arrays",
"numpy"
] |
python open windows explorer | 38,835,359 | <p>Please image such a situation: A local file's icon is displayed in a GUI, right click the icon, a context menu pops, with the option: show file in explorer. Click the option, then a explorer window opened, with the particular file selected. Many editors have such a feature: show in folder or show in explorer</p>
<p... | 0 | 2016-08-08T17:37:39Z | 38,875,519 | <p>Finally, some nice guy guided me to the answer.<br>
It's from <a href="https://github.com/exaile/exaile/blob/master/xl/common.py#L350" rel="nofollow">https://github.com/exaile/exaile/blob/master/xl/common.py#L350</a></p>
<p><strong>in py3+</strong></p>
<pre><code>import ctypes
ctypes.windll.ole32.CoInitialize(Non... | 0 | 2016-08-10T13:56:56Z | [
"python",
"windows",
"explorer"
] |
delete stop words in a file in python | 38,835,479 | <p>I have a file which consists of stop words (each in a new line) and another file (a corpus actually) which consists of a lot of sentences each in a new line. I have to delete the stop words in the corpus and return each line of that without stop words. I wrote a code but it just returns one sentence. (The language i... | -2 | 2016-08-08T17:44:52Z | 38,836,114 | <p>The problem is that your last two lines of code are not in the for loop. You are iterating through the entire f2, line-by-line, and doing nothing with it. Then, after the last line, you write just that last line to f3. Instead, try:</p>
<pre><code>with open("stopwords.txt", encoding = "utf-8") as stopfile:
stop... | 0 | 2016-08-08T18:28:47Z | [
"python",
"nlp"
] |
delete stop words in a file in python | 38,835,479 | <p>I have a file which consists of stop words (each in a new line) and another file (a corpus actually) which consists of a lot of sentences each in a new line. I have to delete the stop words in the corpus and return each line of that without stop words. I wrote a code but it just returns one sentence. (The language i... | -2 | 2016-08-08T17:44:52Z | 38,836,281 | <p>You can just iterate through both files, and write to the third one. <a href="http://stackoverflow.com/a/38836114/1708751">@Noam</a> was right in that you had issues with the indentation of your last file open.</p>
<pre><code>with open("stopwords.txt", encoding="utf-8") as sw, open("train.txt", encoding="utf-8") as... | 0 | 2016-08-08T18:39:21Z | [
"python",
"nlp"
] |
Confusion re: pandas copy of slice of dataframe warning | 38,835,483 | <p>I've looked through a bunch of questions and answers related to this issue, but I'm still finding that I'm getting this copy of slice warning in places where I don't expect it. Also, it's cropping up in code that was running fine for me previously, leading me to wonder if some sort of update may be the culprit. </p... | 5 | 2016-08-08T17:45:03Z | 38,835,530 | <pre><code> izmir = pd.read_excel(filepath)
izmir_lim = izmir[['Gender','Age','MC_OLD_M>=60','MC_OLD_F>=60',
'MC_OLD_M>18','MC_OLD_F>18','MC_OLD_18>M>5',
'MC_OLD_18>F>5','MC_OLD_M_Child<5','MC_OLD_F_Child<5',
'MC_OLD_M>0<=1... | 1 | 2016-08-08T17:48:02Z | [
"python",
"pandas"
] |
Trying to Gather all tweets from the past 24hours and put them into a CSV file | 38,835,497 | <p>Im trying to gather all the tweets from the last 24 hours and put them into a CSV file </p>
<p>When i do this i get </p>
<pre><code>_csv.Error: iterable expected, not datetime.datetime
</code></pre>
<p>As an error</p>
<p>Can anyone help tell me how to get rid of this error and any other improvements that could p... | -1 | 2016-08-08T17:45:52Z | 38,835,903 | <p><code>outtweets</code> only ever contains a <em>single row</em> of data. <code>writer.writerows()</code> expects a list of rows, that is, a list of lists:</p>
<pre><code>[
[columns, in, row, 1],
[columns, in, row, 2],
]
</code></pre>
<p>You are setting <code>outtweets</code> like this:</p>
<pre><code>outtweet... | 2 | 2016-08-08T18:15:08Z | [
"python",
"csv",
"twitter",
"tweepy"
] |
exception handling in decorator function | 38,835,528 | <p>New to Python and I have a bunch of functions to perform various tasks on some hardware. Each function has different numbers of parameters and returns.</p>
<p>I want to make a kind of generic "retry" wrapper function that will catch an exception from any of my functions and do some error handling (such as retrying ... | 0 | 2016-08-08T17:48:01Z | 38,835,700 | <p>Converting my comment to answer:</p>
<p>You should be using like:</p>
<pre><code>def retry(function):
@wraps(function)
def _retry(*args, **kwargs):
try:
reply = function(*args, **kwargs)
print "reply: ", reply
return reply
except PDError as msg:
... | 0 | 2016-08-08T18:01:35Z | [
"python",
"python-2.7",
"exception",
"decorator"
] |
Listing all directories and files in a sub-directory not working - Python | 38,835,555 | <p>I need to print a list of all files in sub-directories of the directory "H:\Reference_Archive\1EastRefsJan2014". I am currently using the code:</p>
<pre><code>for root, dirs, files in os.walk("H:\Reference_Archive\1EastRefsJan2014"):
for name in files:
print os.path.join(root, name)
</code></pre>
<p>T... | 1 | 2016-08-08T17:49:54Z | 38,835,626 | <p>try this, you omitted dirs</p>
<pre><code>for root, dirs, files in os.walk("H:\Reference_Archive\1EastRefsJan2014"):
for name in files:
print os.path.join(root, name)
</code></pre>
| 0 | 2016-08-08T17:55:28Z | [
"python"
] |
Listing all directories and files in a sub-directory not working - Python | 38,835,555 | <p>I need to print a list of all files in sub-directories of the directory "H:\Reference_Archive\1EastRefsJan2014". I am currently using the code:</p>
<pre><code>for root, dirs, files in os.walk("H:\Reference_Archive\1EastRefsJan2014"):
for name in files:
print os.path.join(root, name)
</code></pre>
<p>T... | 1 | 2016-08-08T17:49:54Z | 38,836,359 | <p>Finally figured out that the os.walk function was not working with my folder because the folder name started with a number. Once I changed the name of the folder, it worked properly. </p>
| 0 | 2016-08-08T18:44:04Z | [
"python"
] |
âUnicodeEncodeError: 'ascii' codec can't encode characterâ in Python3 | 38,835,584 | <p>I'm fetching JSON with Requests from an API (using Python 3.5) and when I'm trying to print (or use) the JSON, either by response.text, json.loads(...) or response.json(), I get an UnicodeEncodeError.</p>
<pre><code>print(response.text)
UnicodeEncodeError: 'ascii' codec can't encode character '\xc5' in position 676... | 0 | 2016-08-08T17:52:11Z | 38,851,554 | <p>If your code is running within VS, then it sounds that Python can't work out the encoding of the inbuilt console, so defaults to ASCII. If you try to print any non-ASCII then Python throws an error rather printing text that won't display.</p>
<p>You can force Python's encoding by using the <code>PYTHONIOENCODING</c... | 0 | 2016-08-09T13:02:46Z | [
"python",
"json",
"encoding",
"utf-8"
] |
How to switch between loops? | 38,835,612 | <p>I have a program that generates two lists. I want to print an item from list1 then switch to printing an item from list 2 and then go back to printing from list1 ..etc. However whenever I try it it just prints list1 then list2. </p>
<p>Please help.</p>
<p><strong>Code:</strong></p>
<pre><code>List1 = ['a', 'b' , ... | 0 | 2016-08-08T17:54:40Z | 38,835,641 | <p>The <code>continue = False</code> does not prevent the <code>for</code> loop from running to completion. The <code>while</code> condition is only evaluated <em>after</em> the <code>for</code> loop completes. This causes all element of <code>List1</code> to be printed and then all elements of <code>List2</code>.</p>
... | 1 | 2016-08-08T17:56:27Z | [
"python",
"list",
"for-loop",
"while-loop"
] |
How to switch between loops? | 38,835,612 | <p>I have a program that generates two lists. I want to print an item from list1 then switch to printing an item from list 2 and then go back to printing from list1 ..etc. However whenever I try it it just prints list1 then list2. </p>
<p>Please help.</p>
<p><strong>Code:</strong></p>
<pre><code>List1 = ['a', 'b' , ... | 0 | 2016-08-08T17:54:40Z | 38,835,651 | <p>Python's built-in <a href="https://docs.python.org/3/library/functions.html#zip" rel="nofollow">zip function</a> provides a very concise way of achieving that goal.</p>
<pre><code>for x,y in zip(List1,List2):
print(x)
print(y)
# Out:
a
1
b
2
c
3
d
4
e
5
f
6
</code></pre>
<p>This is a much more Pythonic so... | 6 | 2016-08-08T17:56:53Z | [
"python",
"list",
"for-loop",
"while-loop"
] |
How to switch between loops? | 38,835,612 | <p>I have a program that generates two lists. I want to print an item from list1 then switch to printing an item from list 2 and then go back to printing from list1 ..etc. However whenever I try it it just prints list1 then list2. </p>
<p>Please help.</p>
<p><strong>Code:</strong></p>
<pre><code>List1 = ['a', 'b' , ... | 0 | 2016-08-08T17:54:40Z | 38,835,994 | <p>My answer is based around the code for your question. If this is the format you are wanting then use my answer. Otherwise, the other answers are more Pythonic as stated.</p>
<p>Please note that I've renamed "continue" to "switch" as continue is a reserved Python word, producing a syntax error.</p>
<pre><code>List1... | 2 | 2016-08-08T18:22:08Z | [
"python",
"list",
"for-loop",
"while-loop"
] |
(key, value) pair using Python Lambdas | 38,835,636 | <p>I am trying to work on a simple word count problem and trying to figure if that can be done by use of map, filter and reduce exclusively.</p>
<p>Following is an example of an wordRDD(the list used for spark):</p>
<pre><code>myLst = ['cats', 'elephants', 'rats', 'rats', 'cats', 'cats']
</code></pre>
<p>All i need ... | 1 | 2016-08-08T17:56:15Z | 38,835,799 | <p>Not using a lambda but gets the job done.</p>
<pre><code>from collections import Counter
c = Counter(myLst)
result = list(c.items())
</code></pre>
<p>And the output:</p>
<pre><code>In [21]: result
Out[21]: [('cats', 3), ('rats', 2), ('elephants', 1)]
</code></pre>
| 1 | 2016-08-08T18:08:11Z | [
"python",
"python-3.x",
"apache-spark"
] |
(key, value) pair using Python Lambdas | 38,835,636 | <p>I am trying to work on a simple word count problem and trying to figure if that can be done by use of map, filter and reduce exclusively.</p>
<p>Following is an example of an wordRDD(the list used for spark):</p>
<pre><code>myLst = ['cats', 'elephants', 'rats', 'rats', 'cats', 'cats']
</code></pre>
<p>All i need ... | 1 | 2016-08-08T17:56:15Z | 38,835,802 | <p>You don't need <code>map(..)</code> at all. You can do it with just <code>reduce(..)</code></p>
<pre><code>>>> def function(obj, x):
... obj[x] += 1
... return obj
...
>>> from functools import reduce
>>> reduce(function, myLst, defaultdict(int)).items()
dict_items([('elephants', ... | 1 | 2016-08-08T18:08:22Z | [
"python",
"python-3.x",
"apache-spark"
] |
(key, value) pair using Python Lambdas | 38,835,636 | <p>I am trying to work on a simple word count problem and trying to figure if that can be done by use of map, filter and reduce exclusively.</p>
<p>Following is an example of an wordRDD(the list used for spark):</p>
<pre><code>myLst = ['cats', 'elephants', 'rats', 'rats', 'cats', 'cats']
</code></pre>
<p>All i need ... | 1 | 2016-08-08T17:56:15Z | 38,836,029 | <p>If you don't want the full reduce step done for you (which aggregated the counts in SuperSaiyan's answer), you can use map this way:</p>
<pre><code> >>> myLst = ['cats', 'elephants', 'rats', 'rats', 'cats', 'cats']
>>> counts = list(map(lambda s: (s,1), myLst))
>>> print(counts... | 0 | 2016-08-08T18:23:50Z | [
"python",
"python-3.x",
"apache-spark"
] |
Only use part of a Pandas dataframe | 38,835,672 | <p>I feel like I am asking a very silly question that has been asked a thousand times but I cannot seem to find it anywhere. I might be using the wrong terminology.</p>
<p>Anyway, I have a pandas frame <code>df</code>. And I would like to use a part of this dataframe. More specifically I'd like to use it in a loop:</p... | 0 | 2016-08-08T17:58:55Z | 38,835,705 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/groupby.html" rel="nofollow"><code>df.groupby</code></a> instead:</p>
<pre><code>for value, tempDf in df.groupby('my_column'):
# Do stuff with tempDf
</code></pre>
<hr>
<p>You code does work, after fixing a missing single quote around <code>'my_column</... | 3 | 2016-08-08T18:01:52Z | [
"python",
"pandas",
"filter"
] |
Only use part of a Pandas dataframe | 38,835,672 | <p>I feel like I am asking a very silly question that has been asked a thousand times but I cannot seem to find it anywhere. I might be using the wrong terminology.</p>
<p>Anyway, I have a pandas frame <code>df</code>. And I would like to use a part of this dataframe. More specifically I'd like to use it in a loop:</p... | 0 | 2016-08-08T17:58:55Z | 38,836,650 | <pre><code>for value in unique_values:
tempDf = df.where(df['column_name'] == value)
# Do stuff with tempDf
</code></pre>
<p>Additionally you could use a query statement</p>
<pre><code>for value in unique_values:
tempDf = df.query('(column_name == value)')
# Do stuff with tempDf
</code></pre>
<p>Or... | 0 | 2016-08-08T19:01:06Z | [
"python",
"pandas",
"filter"
] |
Calculating Weighted Mean in PySpark | 38,835,687 | <p>I am trying to calculate weighted mean in pyspark but not making a lot of progress</p>
<pre><code># Example data
df = sc.parallelize([
("a", 7, 1), ("a", 5, 2), ("a", 4, 3),
("b", 2, 2), ("b", 5, 4), ("c", 1, -1)
]).toDF(["k", "v1", "v2"])
df.show()
import numpy as np
def weighted_mean(workclass, final_wei... | 1 | 2016-08-08T18:00:17Z | 38,875,882 | <p>User Defined Aggregation Function (UDAF, which works on <code>pyspark.sql.GroupedData</code> but not supported in pyspark) is not User Defined Function (UDF, which works on <code>pyspark.sql.DataFrame</code>).</p>
<p>Because in pyspark you cannot create your own UDAF, and the supplied UDAFs cannot resolve your issu... | 0 | 2016-08-10T14:12:42Z | [
"python",
"apache-spark",
"pyspark"
] |
how can i find "smallest eigenvalue" o a plate with python scripting in abaqus? | 38,835,788 | <p>i write a python script to modeling and analysis a plate for buckling.
i need the minimum eigenvalue for run the other script for RIKS analysis.
how can i find "smallest eigenvalue" with python scripting in abaqus?</p>
| -1 | 2016-08-08T18:07:18Z | 38,836,445 | <pre><code>foo = [3,1,4,5]
print min(foo)
outputs => 1
</code></pre>
| 0 | 2016-08-08T18:48:32Z | [
"python",
"eigenvalue",
"abaqus"
] |
how can i find "smallest eigenvalue" o a plate with python scripting in abaqus? | 38,835,788 | <p>i write a python script to modeling and analysis a plate for buckling.
i need the minimum eigenvalue for run the other script for RIKS analysis.
how can i find "smallest eigenvalue" with python scripting in abaqus?</p>
| -1 | 2016-08-08T18:07:18Z | 38,935,593 | <pre><code>datFullPath = PathDir+FileName+'.dat'
myOutdf = open(datFullPath,'r')
stline=' MODE NO EIGENVALUE\n'
lines = myOutdf.readlines()
ss=0
for i in range(len(lines)-1):
if lines[i] == stline :
print lines[i]
ss=i
f1=lines[ss+3]
MinEigen=float(f1[15:24])
myOutdf.close()
MinEigen
</co... | 0 | 2016-08-13T18:09:41Z | [
"python",
"eigenvalue",
"abaqus"
] |
OSError: [Errno 2] No such file or directory: '/usr/local/lib/python2.7/dist-packages/pyduino-0.0.0-py2.7.egg' | 38,835,843 | <p>I am trying to install and uninstall a package.I have written a setup.py script.While installing the script works fine and the package installs.But while uninstalling package uninstalls but throw some errors.I am using pip uninstall package_name for uninstalling.Here is the traceback </p>
<pre><code>Uninstalling py... | 0 | 2016-08-08T18:11:16Z | 38,888,867 | <p>I found the solution.I didn't upgrade pip after installing.Later,I upgraded and works perfectly..</p>
| 0 | 2016-08-11T06:33:05Z | [
"python",
"install",
"setup.py",
"pypi"
] |
Python's equivalent of get (,'color') function in Matlab | 38,835,919 | <p>I am a newbie in Python. Please excuse my dummy question. I want to implement something very similar to the following Matlab code, but am stuck with its Python equivalents:</p>
<pre><code>...
Subplot (2,1,1);
H = plot (rand(100,5));
C = get (H, 'Color')
H = area (myX, myY);
H(1).FaceColor = C1;
H(2).FaceColor = C... | 0 | 2016-08-08T18:15:54Z | 38,838,737 | <p>Have a look at matplotlib for plotting. Then, you can use <code>get_color()</code> for line objects.</p>
<p>this is a minimal example:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
a=np.random.random((100,5))
fig, ax = plt.subplots()
lines=ax.plot(a)
#line_colors is a list of colors used for ... | 1 | 2016-08-08T21:23:56Z | [
"python",
"plot"
] |
Identify and sort multiple circles on 2d plane using python | 38,835,946 | <p>I have multiple points forming many circles on a 2d plane and need to identify and sort them for further calculation. I have the [x, y] co-ordinates of each point and a number representing each point.</p>
<p>All point numbers in one circle should be sorted in a list. and then point numbers of next circle should fol... | 3 | 2016-08-08T18:18:05Z | 38,881,692 | <p>Knowing the specifics from your edit allows for taking some shortcuts. Allow me to restate / infer a couple things:</p>
<ol>
<li>Holes are in rows/columns <em>that are vertical/horizontal</em> and <em>do not overlap</em></li>
<li>Holes are all a standard width/height (identical diameters)</li>
<li>The x or y value ... | 0 | 2016-08-10T19:09:28Z | [
"python",
"algorithm",
"cluster-analysis",
"convex-hull"
] |
Django Search Bar Implementation | 38,836,111 | <p>I'm trying to implement a search bar to query my database and show only the matches. When I hit submit it just gives me back 'SEARCH', which is what I set as the default instead of printing an error.</p>
<p><strong>ajax.py</strong></p>
<pre><code>...
def chunkSearcher(request):
test = request.GET.get('search_box',... | 0 | 2016-08-08T18:28:27Z | 38,837,485 | <p>Getting this working without Ajax would be a bit quicker to start. When the <code>action</code> attribute of your form is pointed towards the URL of the current page (rather than towards the URL of your ajax view), the GET request is sent to the view that corresponds to that page's URL - your <code>searcher</code> v... | 0 | 2016-08-08T19:54:59Z | [
"python",
"ajax",
"django"
] |
Coverage failing on Travis but not on local machine - error depends on order of flags | 38,836,138 | <p>I'm have the following <code>script</code> section in my .travis.yml file:</p>
<pre><code>script:
# run all tests in mymodule/tests and check coverage of the mymodule dir
# don't report on coverage of files in the mymodule/tests dir itself
- coverage run -m --source mymodule --omit mymodule/tests/* py.test my... | 0 | 2016-08-08T18:30:24Z | 38,839,581 | <p>Solved by changing from using <code>coverage</code> directly to using <code>pytest-cov</code>.</p>
<pre><code>script:
# run all tests in mymodule/tests and check coverage of the mymodule dir
- py.test -v --cov-config .coveragerc --cov=mymodule mymodule/tests
</code></pre>
<p>And the <code>.coveragerc</code> fi... | 0 | 2016-08-08T22:44:34Z | [
"python",
"travis-ci",
"py.test",
"coverage.py"
] |
Discrete legend in seaborn heatmap plot | 38,836,154 | <p>I am using the data present here to construct this heat map using seaborn and pandas.</p>
<p>The input csv file is here: <a href="https://www.dropbox.com/s/5jc1vr6u8j7058v/LUH2_trans_matrix.csv?dl=0" rel="nofollow">https://www.dropbox.com/s/5jc1vr6u8j7058v/LUH2_trans_matrix.csv?dl=0</a></p>
<p>Code:</p>
<pre><cod... | 4 | 2016-08-08T18:31:41Z | 38,884,912 | <p>The link provided by @Fabio Lamanna is a great start. </p>
<p>From there, you still want to set colorbar labels in the correct location and use tick labels that correspond to your data. </p>
<p>assuming that you have equally spaced levels in your data, this produces a nice discrete colorbar:</p>
<p>Basically, thi... | 2 | 2016-08-10T23:03:27Z | [
"python",
"pandas",
"matplotlib",
"seaborn"
] |
Discrete legend in seaborn heatmap plot | 38,836,154 | <p>I am using the data present here to construct this heat map using seaborn and pandas.</p>
<p>The input csv file is here: <a href="https://www.dropbox.com/s/5jc1vr6u8j7058v/LUH2_trans_matrix.csv?dl=0" rel="nofollow">https://www.dropbox.com/s/5jc1vr6u8j7058v/LUH2_trans_matrix.csv?dl=0</a></p>
<p>Code:</p>
<pre><cod... | 4 | 2016-08-08T18:31:41Z | 38,886,003 | <p>I find that a discretized colorbar in seaborn is much easier to create if you use a <code>ListedColormap</code>. There's no need to define your own functions, just add a few lines to basically customize your axes.</p>
<pre><code>import pandas
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.col... | 2 | 2016-08-11T01:39:09Z | [
"python",
"pandas",
"matplotlib",
"seaborn"
] |
Discrete legend in seaborn heatmap plot | 38,836,154 | <p>I am using the data present here to construct this heat map using seaborn and pandas.</p>
<p>The input csv file is here: <a href="https://www.dropbox.com/s/5jc1vr6u8j7058v/LUH2_trans_matrix.csv?dl=0" rel="nofollow">https://www.dropbox.com/s/5jc1vr6u8j7058v/LUH2_trans_matrix.csv?dl=0</a></p>
<p>Code:</p>
<pre><cod... | 4 | 2016-08-08T18:31:41Z | 38,887,138 | <p>Well, there's definitely more than one way to accomplish this. In this case, with only three colors needed, I would pick the colors myself by creating a <code>LinearSegmentedColormap</code> instead of generating them with <code>cubehelix_palette</code>. If there were enough colors to warrant using <code>cubehelix... | 1 | 2016-08-11T04:12:15Z | [
"python",
"pandas",
"matplotlib",
"seaborn"
] |
Error when "import requests" - "No module named requests" | 38,836,249 | <p>N00b Altert.</p>
<p>So I tried to call "import requests" through Python and got the error: </p>
<pre><code>>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
</code></pre>
<p>I do not think I have pip installed corr... | 0 | 2016-08-08T18:37:01Z | 38,836,365 | <p>According to the <a href="http://docs.python-requests.org/en/master/user/install/#install" rel="nofollow">requests website installation page</a>:</p>
<ol>
<li>Checkout the <a href="https://github.com/kennethreitz/requests" rel="nofollow">git repository</a></li>
<li>execute <code>/path/to/virtualenv/bin/python reque... | 1 | 2016-08-08T18:44:34Z | [
"python",
"python-requests"
] |
Does TensorFlow view all CPUs of one machine as ONE device? | 38,836,269 | <p>From the experiments I run, it seems like TensorFlow uses automatically all CPUs on one machine. Furthermore, it seems like TensorFlow refers to all CPUs as /cpu:0. </p>
<p>Am I right, that only the different GPUs of one machine get indexed and viewed as separate devices, but all the CPUs on one machine get viewed ... | 0 | 2016-08-08T18:38:25Z | 38,836,390 | <p>By default all CPUs available to the process are aggregated under <code>cpu:0</code> device.</p>
<p>There's answer by mrry <a href="http://stackoverflow.com/a/37864489/419116">here</a> showing how to create logical devices like <code>/cpu:1</code>, <code>/cpu:2</code></p>
<p>There doesn't seem to be working functi... | 0 | 2016-08-08T18:45:55Z | [
"python",
"tensorflow"
] |
How to affect outer loop variable from inner loop in Python? | 38,836,312 | <p>This is in Java:</p>
<pre><code>for(int i=0; i<10; i++){
while(i%3!=0)
i++;
System.out.print(i + " ");
}
</code></pre>
<p>This will output: </p>
<blockquote>
<p>0 3 6 9</p>
</blockquote>
<p>I am trying to achieve similar code block in Python 3. I am not able to.</p>
<p>In the outer loop, I ... | 0 | 2016-08-08T18:41:35Z | 38,836,405 | <pre><code>i = 0
while i < 10:
while i % 3 is not 0:
i += 1
print(str(i) + " ")
i += 1
</code></pre>
| 2 | 2016-08-08T18:46:35Z | [
"java",
"python",
"for-loop",
"condition"
] |
How to affect outer loop variable from inner loop in Python? | 38,836,312 | <p>This is in Java:</p>
<pre><code>for(int i=0; i<10; i++){
while(i%3!=0)
i++;
System.out.print(i + " ");
}
</code></pre>
<p>This will output: </p>
<blockquote>
<p>0 3 6 9</p>
</blockquote>
<p>I am trying to achieve similar code block in Python 3. I am not able to.</p>
<p>In the outer loop, I ... | 0 | 2016-08-08T18:41:35Z | 38,836,425 | <p>From my comment on the OP's question:</p>
<p><code>for i in range(0, 11, 3): print(i, end=' ')</code></p>
| 0 | 2016-08-08T18:47:40Z | [
"java",
"python",
"for-loop",
"condition"
] |
How to affect outer loop variable from inner loop in Python? | 38,836,312 | <p>This is in Java:</p>
<pre><code>for(int i=0; i<10; i++){
while(i%3!=0)
i++;
System.out.print(i + " ");
}
</code></pre>
<p>This will output: </p>
<blockquote>
<p>0 3 6 9</p>
</blockquote>
<p>I am trying to achieve similar code block in Python 3. I am not able to.</p>
<p>In the outer loop, I ... | 0 | 2016-08-08T18:41:35Z | 38,836,464 | <p>There is no need for two loops in your example.</p>
<pre><code>while i<=10:
if i%3 == 0:
print(i+ " ")
i++
</code></pre>
<p>Your code runs infinitely because you never increment i when it equals 3</p>
| 3 | 2016-08-08T18:49:27Z | [
"java",
"python",
"for-loop",
"condition"
] |
How to affect outer loop variable from inner loop in Python? | 38,836,312 | <p>This is in Java:</p>
<pre><code>for(int i=0; i<10; i++){
while(i%3!=0)
i++;
System.out.print(i + " ");
}
</code></pre>
<p>This will output: </p>
<blockquote>
<p>0 3 6 9</p>
</blockquote>
<p>I am trying to achieve similar code block in Python 3. I am not able to.</p>
<p>In the outer loop, I ... | 0 | 2016-08-08T18:41:35Z | 38,836,596 | <p>Another option is to just use a list comprehension:</p>
<pre><code>print(' '.join([i for i in range(10) if i % 3 == 0])
</code></pre>
| 1 | 2016-08-08T18:57:55Z | [
"java",
"python",
"for-loop",
"condition"
] |
How to affect outer loop variable from inner loop in Python? | 38,836,312 | <p>This is in Java:</p>
<pre><code>for(int i=0; i<10; i++){
while(i%3!=0)
i++;
System.out.print(i + " ");
}
</code></pre>
<p>This will output: </p>
<blockquote>
<p>0 3 6 9</p>
</blockquote>
<p>I am trying to achieve similar code block in Python 3. I am not able to.</p>
<p>In the outer loop, I ... | 0 | 2016-08-08T18:41:35Z | 38,837,242 | <p>OK. Another suggestion for the party. Might be helpful with your actual task:</p>
<pre><code>g = iter(range(10))
for i in g:
while i%3 is not 0:
i = next(g)
print(i)
</code></pre>
<p>The main difference is that this will raise <code>StopIteration</code> exception when the inner loop exceeds the ran... | 1 | 2016-08-08T19:39:11Z | [
"java",
"python",
"for-loop",
"condition"
] |
mypy "invalid type" error | 38,836,357 | <p>I'm trying to implement type annotations in a current project, and am receiving errors from mypy that I don't understand. </p>
<p>I'm using Python 2.7.11, and newly installed mypy in my base virtualenv. The following program runs fine:</p>
<pre><code>from __future__ import print_function
from types import String... | 2 | 2016-08-08T18:44:04Z | 38,839,696 | <p>The problem is that <code>types.StringTypes</code> is defined to be a <em>sequence</em> of types -- the formal type signature <a href="https://github.com/python/typeshed/blob/master/stdlib/2.7/types.pyi#L22" rel="nofollow">on Typeshed</a> is:</p>
<pre><code>StringTypes = (StringType, UnicodeType)
</code></pre>
<p>... | 1 | 2016-08-08T22:56:13Z | [
"python",
"mypy"
] |
Multiple field filtering using pyDAL | 38,836,394 | <p><strong>EDIT: I think I solved it, I added the answer.</strong></p>
<p>I am writing a REST API using python,
Falcon as the web framework and pyDAL as the DAL for MySQL.</p>
<p>I want to filter(where statement) using the fields that I get in the query string of the get request.</p>
<p>For example I receive the the... | 2 | 2016-08-08T18:46:09Z | 38,837,775 | <p>I created a function that receives a Table object and the query string and does:</p>
<pre><code>def generate_filter(table, query_string):
statement = True
for field in query_string.split('&'):
field = field.split('=')
statement &= getattr(table, field[0]) == field[1]
return state... | 1 | 2016-08-08T20:15:46Z | [
"python",
"pydal"
] |
RobotFramework adding tests through argument file | 38,836,411 | <p>I am learning robot and creating a testframework. I want to give people an easy way to add more tests.</p>
<p>Is it possible to dynamically create tests based on arguments passed in argument file? </p>
<p>I have all my tests in a .rst file and right now users have to populate the test table , but I want to make it... | 0 | 2016-08-08T18:46:55Z | 38,837,243 | <p>No, it is not possible to dynamically create tests via an argument file.</p>
<p>It is, however, possible to write a script that reads a data file and generates a suite of tests before running pybot.</p>
| 1 | 2016-08-08T19:39:24Z | [
"python",
"robotframework"
] |
How to get the regression intercept using Statsmodels.api | 38,836,465 | <p>I am trying calculate a regression output using python library but I am unabl;e to get the intercept value when I use the library:</p>
<pre><code>import statsmodels.api as sm
</code></pre>
<p>It prints all the regression analysis except the intercept. </p>
<p>but when I use:</p>
<pre><code>from pandas.stats.api ... | 2 | 2016-08-08T18:49:29Z | 38,838,570 | <p>So, <code>statsmodels</code> has a <code>add_constant</code> method that you need to use to explicitly add intercept values. IMHO, this is better than the R alternative where the intercept is added by default.</p>
<p>In your case, you need to do this:</p>
<pre><code>import statsmodels.api as sm
endog = Sorted_Data... | 2 | 2016-08-08T21:09:57Z | [
"python",
"pandas",
"statsmodels"
] |
How to get around this memoryview error in numpy? | 38,836,469 | <p>In this code snippet <code>train_dataset</code>, <code>test_dataset</code> and <code>valid_dataset</code> are of the type <code>numpy.ndarray</code>.</p>
<pre><code>def check_overlaps(images1, images2):
images1.flags.writeable=False
images2.flags.writeable=False
print(type(images1))
print(type(image... | 0 | 2016-08-08T18:49:40Z | 38,837,737 | <p>The problem is that your method to hash arrays only works for <code>python2</code>. Therefore, your code fails as soon as you try to compute <code>hash(image1.data)</code>. The error message tells you that only <code>memoryview</code>s of formats unsigned bytes (<code>'B'</code>), bytes (<code>'b'</code>) of single ... | 2 | 2016-08-08T20:12:51Z | [
"python",
"python-3.x",
"numpy"
] |
can a return value of a function be passed in the where clause | 38,836,480 | <p>I have a python code that displays a list of station ID and air temperature for certain number of days. In the code below I have passed the dates as a list. But that is cumbersome coding since I have to write all the dates in the list. Is there any way wherein I can pass the return value of a function to the where c... | 0 | 2016-08-08T18:50:30Z | 38,836,616 | <p>Yes you can substitute the return value of a function in your query. Because <code>message</code> is just a string you can concatenate it like you would any other string.</p>
<p><code>message = """select stationId,Date,airTemperature from cimishourly where stationId in (2,7) and Date in (""" + functionToGetDates() ... | 0 | 2016-08-08T18:58:47Z | [
"python",
"mysql",
"python-2.7",
"mysql-python"
] |
Create a rolling custom EWMA on a pandas dataframe | 38,836,482 | <p>I am trying to create a rolling EWMA with the following decay= 1-ln(2)/3 on the last 13 values of a df such has :</p>
<pre><code>factor
Out[36]:
EWMA
0 0.043
1 0.056
2 0.072
3 0.094
4 0.122
5 0.159
6 0.207
7 0.269
8 0.350
9 0.455
10 0.591
11 0.769
12 1.000
</code></pre>
<p>I have a df of monthly ret... | 1 | 2016-08-08T18:50:47Z | 38,836,640 | <p>use <code>ewm</code> with <code>mean()</code></p>
<pre><code>df.ewm(halflife=1 - np.log(2) / 3).mean()
</code></pre>
<p><a href="http://i.stack.imgur.com/K9u4C.png" rel="nofollow"><img src="http://i.stack.imgur.com/K9u4C.png" alt="enter image description here"></a></p>
| 2 | 2016-08-08T19:00:36Z | [
"python",
"pandas"
] |
Writing a dict list as rows in CSV | 38,836,492 | <p>I have a simple csv file:</p>
<pre><code>101,8
102,10
102,6
103,5
104,0
</code></pre>
<p>with duplicated entries for row[0] on the second and third line and I want to keep the last (or lower row[1] value) duplicate. The only way I have figured out how to make it work correctly was using a dict() to sort, but now ... | 1 | 2016-08-08T18:51:12Z | 38,836,656 | <p>If I understand correctly. </p>
<p>Instead of:</p>
<pre><code>writer.writerows(unique_rows)
</code></pre>
<p>you want to do something like:</p>
<pre><code>for row in unqiue_rows.values():
writer.writerow(row)
</code></pre>
| 0 | 2016-08-08T19:01:12Z | [
"python",
"csv"
] |
Can I derive from a class that can only be created by a "factory"? | 38,836,510 | <p>Suppose that a library I'm using implements a class</p>
<pre><code>class Base(object):
def __init__(self, private_API_args):
...
</code></pre>
<p>It's meant to be instantiated only via</p>
<pre><code>def factory(public_API_args):
"""
Returns a Base object
"""
...
</code></pre>
<p>I'd ... | 0 | 2016-08-08T18:52:27Z | 38,838,647 | <p>If you do not have any access to the private API, you can do the following thing:</p>
<pre><code>class Base(object):
def __init__(self, private_API_args):
...
def factory(public_API_args):
""" Returns a Base object """
# Create base object with all private API methods
return base_object
... | 0 | 2016-08-08T21:15:07Z | [
"python",
"python-2.7",
"inheritance",
"factory",
"api-design"
] |
Where is a list of all of python's `__builtin__` datatypes? | 38,836,524 | <p>I'm using comparisons like:</p>
<pre><code>if type( self.__dict__[ key ] ) is str \
or type( self.__dict__[ key ] ) is set \
or type( self.__dict__[ key ] ) is dict \
or type( self.__dict__[ key ] ) is list \
or type( self.__dict__[ key ] ) is tuple \
or type( self.__dict__[ key ] ) is int \
... | 3 | 2016-08-08T13:52:41Z | 38,836,604 | <p>You can iterate over <code>__builtin__</code>'s <a href="https://docs.python.org/3/library/stdtypes.html#object.__dict__" rel="nofollow"><code>__dict__</code></a>, and use <a href="https://docs.python.org/2/library/functions.html#isinstance" rel="nofollow"><code>isinstance</code></a> to see if something is a class:<... | 2 | 2016-08-08T18:58:25Z | [
"python",
"variables"
] |
Django Pagination, User selected entry amount error | 38,836,591 | <p>I have a page with a form that a user enters information to help filter a queryset when they press submit. Upon submission, they are brought to a results page that displays this filtered queryset. I have pagination set up with Django as well as an interactive drop down where the user can select how many entries of t... | -2 | 2016-08-08T18:57:40Z | 38,838,315 | <p>You're going about it wrong - rather than trying to remember the state of the queryset for each user and paging based on that, instead set your user page up to request the page it wants and request it from the server. </p>
<p>You could do this in a lot of ways, but something like Tastypie or django rest framework c... | 0 | 2016-08-08T20:52:30Z | [
"python",
"django",
"pagination",
"django-queryset"
] |
Minor issue in using dictionary and isspace function | 38,836,605 | <p>Here is my code for a simple Caesar's cipher-style program.</p>
<p>It works fine otherwise, but it does not recognize potential spaces between words written by the user. </p>
<p>While the program translates the letters themselves correctly, it prints all characters clustered together in a single word, omitting spa... | 0 | 2016-08-08T18:58:25Z | 38,836,683 | <p>Change the line <code>if ch in key.isspace():</code> to <code>if ch.isspace():</code></p>
| 1 | 2016-08-08T19:02:41Z | [
"python",
"whitespace",
"ordereddictionary"
] |
One to many + one relationship in SQLAlchemy? | 38,836,747 | <p>I'm trying to model the following situation: A program has many versions, and one of the versions is the current one (not necessarily the latest).</p>
<p>This is how I'm doing it now:</p>
<pre><code>class Program(Base):
__tablename__ = 'programs'
id = Column(Integer, primary_key=True)
name = Column(Str... | 1 | 2016-08-08T19:06:41Z | 38,838,477 | <p>This design is not ideal; by having two tables refer to one another, you cannot effectively insert into either table, because the foreign key required in the other will not exist. One possible solution in outlined in the selected answer of
<a href="https://social.msdn.microsoft.com/Forums/sqlserver/en-US/431c8ca9-... | 0 | 2016-08-08T21:02:32Z | [
"python",
"database",
"sqlalchemy"
] |
One to many + one relationship in SQLAlchemy? | 38,836,747 | <p>I'm trying to model the following situation: A program has many versions, and one of the versions is the current one (not necessarily the latest).</p>
<p>This is how I'm doing it now:</p>
<pre><code>class Program(Base):
__tablename__ = 'programs'
id = Column(Integer, primary_key=True)
name = Column(Str... | 1 | 2016-08-08T19:06:41Z | 38,838,738 | <p>Circular dependency like that is a perfectly valid solution to this problem.</p>
<p>To fix your foreign keys problem, you need to explicitly provide the <code>foreign_keys</code> argument.</p>
<pre><code>class Program(Base):
...
current_version = relationship('ProgramVersion', foreign_keys=current_version_... | 0 | 2016-08-08T21:24:01Z | [
"python",
"database",
"sqlalchemy"
] |
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list' | 38,836,795 | <p>I having trouble passing a function as a parameter to another function. This is my code:</p>
<p><strong>ga.py:</strong></p>
<pre><code>def display_pageviews(hostname):
pageviews_results = get_pageviews_query(service, hostname).execute()
if pageviews_results.get('rows', []):
pv = pageviews_results.g... | 0 | 2016-08-08T19:09:01Z | 38,838,589 | <p>What the error is telling, is that you can't convert an entire list into a integer. You could get an index from the list and convert that into a integer:</p>
<pre><code>x = ["0", "1", "2"]
y = int(x[0]) #accessing zeroth element
</code></pre>
<p>If your trying to convert a whole list into a integer, your going to... | 0 | 2016-08-08T21:11:11Z | [
"python",
"django",
"python-3.x"
] |
Occurence of a string in a text python | 38,836,809 | <p>There are numerous posts about the occurence of a substring in python, but I can't find anything about the occurrence of a string in a text. </p>
<pre><code>testSTR = "Suppose you have a large text and you are trying to find the specific occurences of some words"
#Suppose my search term is a, then I would expect t... | 0 | 2016-08-08T19:09:41Z | 38,836,889 | <p>You can use collections to do it after splitting the string.</p>
<pre><code>from collections import Counter
print Counter(testSTR.split())
</code></pre>
<p>The output would look like </p>
<pre><code>Counter({'you': 2, 'a': 1, 'and': 1, 'words': 1, 'text': 1, 'some': 1, 'the': 1, 'large': 1, 'to': 1, 'Suppose': 1,... | 5 | 2016-08-08T19:14:37Z | [
"python",
"string"
] |
Occurence of a string in a text python | 38,836,809 | <p>There are numerous posts about the occurence of a substring in python, but I can't find anything about the occurrence of a string in a text. </p>
<pre><code>testSTR = "Suppose you have a large text and you are trying to find the specific occurences of some words"
#Suppose my search term is a, then I would expect t... | 0 | 2016-08-08T19:09:41Z | 38,836,901 | <p>If you are concerned about punctuation, you should try this: </p>
<pre><code>words = testSTR.split().map(lambda s: s.strip(".!?:;,\"'"))
print "a" in words
</code></pre>
| 1 | 2016-08-08T19:15:30Z | [
"python",
"string"
] |
Occurence of a string in a text python | 38,836,809 | <p>There are numerous posts about the occurence of a substring in python, but I can't find anything about the occurrence of a string in a text. </p>
<pre><code>testSTR = "Suppose you have a large text and you are trying to find the specific occurences of some words"
#Suppose my search term is a, then I would expect t... | 0 | 2016-08-08T19:09:41Z | 38,836,974 | <p>I think the most straightforward way is to use regular expressions:</p>
<pre><code>import re
testSTR = "Suppose you have a large text and you are trying to find the specific occurences of some words"
print len(re.findall(r"\ba\b", testSTR))
# 1
</code></pre>
<p><code>\ba\b</code> checks for a "word boundary" both... | 2 | 2016-08-08T19:20:56Z | [
"python",
"string"
] |
python adjust x-axis label frequency | 38,836,832 | <p>I have some time series data from 2000 to 2050. The default plot x-labels are 10 yr intervals, but i want to change them to 5 yr intervals. The time series data is in a Pandas dataframe. I cannot find a good solution to my problem.</p>
<p>Here is my data:</p>
<p>Here is my code:</p>
<pre><code>years = dates.YearL... | 0 | 2016-08-08T19:11:02Z | 38,838,111 | <p>ax.set_xticks([2000, 2005, 2010, 2015, 2020, 2025, 2030, 2035, 2040, 2045, 2050])</p>
| 0 | 2016-08-08T20:37:52Z | [
"python",
"pandas",
"plot",
"axis-labels"
] |
When using Django save() to update db, exception is thrown but why is db still updated? | 38,836,841 | <p>Here is my models and views file. My objective was to add a new attribute to my db ("Entries") which I added to my models and make the migrations using the python manage.py commands. That worked and everything had the new attribute with the correct default "NA" in it. I then wanted to read a file and use that column... | 0 | 2016-08-08T19:11:35Z | 38,837,223 | <p>Try using <a href="https://docs.djangoproject.com/ja/1.9/topics/db/transactions/#controlling-transactions-explicitly" rel="nofollow">transaction.atomic()</a> if any error occurs all the code present within the block will be rolled back. Nothing will be saved unless the whole block executes. </p>
<p>It is well docum... | 0 | 2016-08-08T19:37:47Z | [
"python",
"django",
"database"
] |
When using Django save() to update db, exception is thrown but why is db still updated? | 38,836,841 | <p>Here is my models and views file. My objective was to add a new attribute to my db ("Entries") which I added to my models and make the migrations using the python manage.py commands. That worked and everything had the new attribute with the correct default "NA" in it. I then wanted to read a file and use that column... | 0 | 2016-08-08T19:11:35Z | 38,840,617 | <p>The header record was causing the issue. Once discarding the first record of the file everything worked great.</p>
<p>Here is the updated Views.py file</p>
<p>views.py</p>
<pre><code>def testUpdateDB(passFileName):
f = open(passFileName, 'r')
discardHeader = f.readline() # New line which removes header ... | 0 | 2016-08-09T01:16:51Z | [
"python",
"django",
"database"
] |
Read Serial Python | 38,836,848 | <p>I am reading serial data on my Raspberry Pi with the console:</p>
<pre><code>stty -F /dev/ttyUSB0 1:0:9a7:0:3:1c:7f:15:4:5:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
cat < /dev/ttyUSB0 &
echo -n -e '\x2F\x3F\x21\x0D\x0A' > /dev/ttyUSB0
</code></pre>
<p>And I am getting data line for line:<... | 1 | 2016-08-08T19:12:00Z | 38,837,794 | <p>I'm guessing your device is the same as discussed here:
<a href="https://www.loxforum.com/forum/faqs-tutorials-howto-s/3121-mini-howto-z%C3%A4hlerauslesung-iskra-mt174-mit-ir-schreib-lesekopf-und-raspberry" rel="nofollow">https://www.loxforum.com/forum/faqs-tutorials-howto-s/3121-mini-howto-z%C3%A4hlerauslesung-iskr... | 1 | 2016-08-08T20:16:35Z | [
"python",
"serial-port"
] |
Limiting TCP sending rate | 38,836,898 | <p>TCP flows by their own nature will grow until they fill the maximum capacity of the links used from <code>src</code> to <code>dst</code> (if all those links are empty).</p>
<p>Is there an easy way to limit that ? I want to be able to send TCP flows with a maximum X mbps rate. </p>
<p>I thought about just sending X... | 0 | 2016-08-08T19:15:21Z | 38,838,673 | <p>At the TCP level, the only control you have is how many bytes you pass off to send(), and how often you call it. Once send() has handed over some bytes to the networking stack, it's entirely up to the networking stack how fast (or slow) it wants to send them.</p>
<p>Given the above, you can roughly limit your tran... | 1 | 2016-08-08T21:17:22Z | [
"python",
"linux",
"sockets",
"unix"
] |
Pyserial can't read device | 38,837,007 | <p>I'm trying to read data off of a sensor that I bought, using a conversion module (SSI to RS232). I have the module plugged into my Windows laptop via USB/serial converter.</p>
<p>When I use Putty in Serial mode, I can send the command $2RD and receive the appropriate response from the sensor unit. When I run a sc... | 1 | 2016-08-08T19:23:05Z | 38,837,239 | <p><code>s = ser.read(26)</code> should probably be <code>ser.read(size=26)</code> since it takes keyword argument and not positional argument.</p>
<p>Also, you can try to set a timeout to see what was sent after a specific time because otherwise the function can block if 26 bytes aren't sent as specified in the read ... | 0 | 2016-08-08T19:38:55Z | [
"python",
"serial-port",
"hardware",
"pyserial"
] |
Python and library (wxPython) | 38,837,023 | <p>I'm complety new to Python (coming from Java) and trying to use wxPython library (GUI). I'm using PyCharm as IDE.
Does anyone know how to use library with Python ? </p>
<p>Thanks a lot</p>
| -1 | 2016-08-08T19:23:52Z | 38,837,111 | <p>Here is a link from jetbrain's help section which will teach you how to install packages in Pycharm.</p>
<p><a href="https://www.jetbrains.com/help/pycharm/2016.1/installing-uninstalling-and-upgrading-packages.html" rel="nofollow">https://www.jetbrains.com/help/pycharm/2016.1/installing-uninstalling-and-upgrading-p... | 0 | 2016-08-08T19:30:06Z | [
"python",
"wxpython",
"libs"
] |
Python and library (wxPython) | 38,837,023 | <p>I'm complety new to Python (coming from Java) and trying to use wxPython library (GUI). I'm using PyCharm as IDE.
Does anyone know how to use library with Python ? </p>
<p>Thanks a lot</p>
| -1 | 2016-08-08T19:23:52Z | 38,838,167 | <p>There are semi-official installation instructions on the <a href="https://wiki.wxpython.org/How%20to%20install%20wxPython" rel="nofollow">wxPython wiki</a>.</p>
<p>If you are installing wxPython Phoenix, you can actually use pip:</p>
<pre><code>python -m pip install --no-index --find-links=http://wxpython.org/Phoe... | 0 | 2016-08-08T20:42:25Z | [
"python",
"wxpython",
"libs"
] |
python smallest range from multiple lists | 38,837,054 | <p>I need to find the smallest range from a group of integer lists using at least one element from each list.</p>
<pre><code>list1=[228, 240, 254, 301, 391]
list2=[212, 345, 395]
list3=[15, 84, 93, 103, 216, 398, 407, 488]
</code></pre>
<p>In this example the smallest range would be [391:398], because this covers the... | 5 | 2016-08-08T19:26:28Z | 38,837,374 | <p>Since your input lists are sorted, you can use a merge sort and you only need to test a range whenever the next value that is being merged in came from a different list than the last. Track the last value you've seen on each of the lists, and calculate ranges between the lowest value and the current. This is an <cod... | 5 | 2016-08-08T19:48:02Z | [
"python",
"algorithm",
"list",
"range"
] |
python smallest range from multiple lists | 38,837,054 | <p>I need to find the smallest range from a group of integer lists using at least one element from each list.</p>
<pre><code>list1=[228, 240, 254, 301, 391]
list2=[212, 345, 395]
list3=[15, 84, 93, 103, 216, 398, 407, 488]
</code></pre>
<p>In this example the smallest range would be [391:398], because this covers the... | 5 | 2016-08-08T19:26:28Z | 38,840,091 | <p>This solution slows down significantly as the lists get large/many but it doesn't assume the input lists are presorted:</p>
<pre><code>from itertools import product
def smallest_range(*arrays):
result = min((sorted(numbers) for numbers in product(*arrays)), key=lambda n: abs(n[0] - n[-1]))
return (result... | 0 | 2016-08-08T23:51:39Z | [
"python",
"algorithm",
"list",
"range"
] |
How to get dimensions right using fmin_cg in scipy.optimize | 38,837,155 | <p>I have been trying to use fmin_cg to minimize cost function for Logistic Regression.</p>
<pre><code>xopt = fmin_cg(costFn, fprime=grad, x0= initial_theta,
args = (X, y, m), maxiter = 400, disp = True, full_output = True )
</code></pre>
<p>This is how I call my fmin_cg</p>
<p>Here... | 1 | 2016-08-08T19:33:15Z | 38,841,390 | <p>Well, since I don't know exactly how your initializing <code>m</code>, <code>X</code>, <code>y</code>, and <code>theta</code> I had to make some assumptions. Hopefully my answer is relevant:</p>
<pre><code>import numpy as np
from scipy.optimize import fmin_cg
from scipy.special import expit
def costFn(theta, X, y,... | 0 | 2016-08-09T03:05:41Z | [
"python",
"optimization",
"machine-learning",
"scipy",
"gradient"
] |
How to get dimensions right using fmin_cg in scipy.optimize | 38,837,155 | <p>I have been trying to use fmin_cg to minimize cost function for Logistic Regression.</p>
<pre><code>xopt = fmin_cg(costFn, fprime=grad, x0= initial_theta,
args = (X, y, m), maxiter = 400, disp = True, full_output = True )
</code></pre>
<p>This is how I call my fmin_cg</p>
<p>Here... | 1 | 2016-08-08T19:33:15Z | 38,855,749 | <p>Finally, I figured out what the problem in my initial program was. </p>
<p>My 'y' was (100, 1) and the fmin_cg expects (100, ). Once I flattened my 'y' it no longer threw the initial error. But, the optimization wasn't working still. </p>
<pre><code> Warning: Desired error not necessarily achieved due to precision... | 0 | 2016-08-09T16:12:35Z | [
"python",
"optimization",
"machine-learning",
"scipy",
"gradient"
] |
Read Textfile Write new CSV file | 38,837,222 | <p>Currently I have the following code which prints my desired lines from a .KAP file.</p>
<pre><code>f = open('120301.KAP')
for line in f:
if line.startswith('PLY'):
print line
</code></pre>
<p>This results in the following output</p>
<pre><code>PLY/1,48.107478621032,-69.733975000000
PLY/2,48.1635163998... | 0 | 2016-08-08T19:37:35Z | 38,837,335 | <p>Step by step, since it looks like you're struggling with some basics:</p>
<pre><code>f_in = open("120301.KAP")
f_out = open("outfile.csv", "w")
for line in f_in:
if line.startswith("PLY"): # copy this line to the new file
# split it into columns, ignoring the first one ("PLY/x")
_, col1, col2 ... | 2 | 2016-08-08T19:45:55Z | [
"python",
"csv"
] |
Inserting/adjusting png into plot [matplotlib] | 38,837,233 | <p>I'm doing illustrations for my paper in python using <code>matplotlib</code> library. In this illustration I have a lot of lines, polygons, circles etc. But then I also want to insert a <code>.png</code> image from outside. </p>
<p>Here's what I'm trying to do so far:</p>
<pre><code>import matplotlib.pyplot as plt... | 1 | 2016-08-08T19:38:23Z | 38,838,312 | <p>can you plot your lines and the picture on the same axis?
for that, use the <code>extent</code> key in <code>plt.imshow()</code></p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
im='d:/frame.png'
img=plt.imread(im)
fig, ax = plt.subplots()
frame_height=25
x... | 1 | 2016-08-08T20:52:20Z | [
"python",
"image",
"matplotlib",
"plot",
"imread"
] |
export to csv in python | 38,837,257 | <p>I have the following case:
I need to get the time of a feature in a csv file and compare it with the time of the pictures taken by someone.
Then i need to find 2 (or less) matches. I will assign the first two pictures i find in a 2 mins interval from the time of the feature to that feature.
I managed to create two d... | 0 | 2016-08-08T19:40:23Z | 38,842,774 | <p>There is a CSV module for python to help load these files. You could sort the results to try to be more efficient/short-circuit your checks as well. I cannot really tell what the i and j variables are meant to represent, but I am pretty sure you can do something like the following: </p>
<pre><code>import csv
def h... | 0 | 2016-08-09T05:33:04Z | [
"python",
"csv",
"export",
"increment"
] |
TensorFlow: Saver has 5 models limit | 38,837,309 | <p>I wanted to save multiple models for my experiment but I noticed that <code>tf.train.Saver()</code> constructor could not save more than 5 models. Here is a simple code: </p>
<pre class="lang-py prettyprint-override"><code>import tensorflow as tf
x = tf.Variable(tf.zeros([1]))
saver = tf.train.Saver()
sess = tf.S... | 0 | 2016-08-08T19:44:04Z | 38,837,404 | <p>The <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/state_ops.html#Saver.__init__" rel="nofollow"><code>tf.train.Saver()</code> constructor</a> takes an optional argument called <code>max_to_keep</code>, which defaults to keeping the 5 most recent checkpoints of your model. To save more models, si... | 2 | 2016-08-08T19:49:54Z | [
"python",
"machine-learning",
"tensorflow"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.