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 |
|---|---|---|---|---|---|---|---|---|---|
SQLite-Python "executemany()" not executing to the database | 39,790,006 | <p>I need to get this program to store the values for a persons firstname and surname in a database. The database is called Class and the table inside it that I am trying to insert data into is called Names.
I have tried to rearrange this several times and removed it from its try loop to try diagnose the issue. Thanks... | -2 | 2016-09-30T11:02:47Z | 39,790,071 | <p><code>executemany()</code> expects <em>many</em> items, as the name suggests.</p>
<p>That means a list of lists, or any similar data structure. You give it only one item.</p>
<pre><code>new_first, new_surname = str(input("Firstname:\t")), str(input("Surname:\t"))
new_name = [[new_surname, new_first]]
c.executeman... | 1 | 2016-09-30T11:06:07Z | [
"python",
"sqlite"
] |
SQLite-Python "executemany()" not executing to the database | 39,790,006 | <p>I need to get this program to store the values for a persons firstname and surname in a database. The database is called Class and the table inside it that I am trying to insert data into is called Names.
I have tried to rearrange this several times and removed it from its try loop to try diagnose the issue. Thanks... | -2 | 2016-09-30T11:02:47Z | 39,790,073 | <p>Don't use <code>cursor.executemany()</code>, use <code>cursor.execute()</code>:</p>
<pre><code>c.execute("INSERT INTO Names VALUES (?,?)", new_name)
</code></pre>
<p><code>executemany()</code> should be used for <em>multiple rows of data</em>, but you have just one. </p>
<p>The error is caused by the <code>execut... | 1 | 2016-09-30T11:06:14Z | [
"python",
"sqlite"
] |
Python Pandas plot multiindex specify x and y | 39,790,041 | <p>Below is an example <code>DataFrame</code>.</p>
<pre><code> joaquin manolo
xx 0 0.000000e+00 44.000000
1 1.570796e+00 52.250000
2 3.141593e+00 60.500000
3 4.712389e+00 68.750000
4 6.283185e+00 77.000000
yy 0 0.000000e+00 37.841896
1 2.078796e+00 39.560399
2 5.292179e-1... | 2 | 2016-09-30T11:04:26Z | 39,791,006 | <p>Just use a for loop:</p>
<pre><code>fig, axes = pl.subplots(1, 2)
for ax, col in zip(axes, data.columns):
data[col].unstack(0).plot(x="xx", y="yy", ax=ax, title=col)
</code></pre>
<p>output:</p>
<p><a href="http://i.stack.imgur.com/SrYbq.png" rel="nofollow"><img src="http://i.stack.imgur.com/SrYbq.png" alt="e... | 3 | 2016-09-30T11:57:43Z | [
"python",
"pandas",
"plot"
] |
Flask app doesn't builds on MS Azure cloud | 39,790,145 | <p>I want to deploy my flask web application on Azure cloud. In Deployment options, I have selected GitHub as source destination for my flask code. after doing the configuration test successfully, the init.py file now starts building;<a href="http://i.stack.imgur.com/9vwfW.png" rel="nofollow"><img src="http://i.stack.i... | 0 | 2016-09-30T11:09:50Z | 39,791,229 | <p>You cannot listen on port 8000 in Web Apps. Only port 80 or 443. You'll need to read the port number from the environment, to know what to listen on.</p>
| 0 | 2016-09-30T12:10:31Z | [
"python",
"azure",
"flask",
"azure-web-sites"
] |
Flask app doesn't builds on MS Azure cloud | 39,790,145 | <p>I want to deploy my flask web application on Azure cloud. In Deployment options, I have selected GitHub as source destination for my flask code. after doing the configuration test successfully, the init.py file now starts building;<a href="http://i.stack.imgur.com/9vwfW.png" rel="nofollow"><img src="http://i.stack.i... | 0 | 2016-09-30T11:09:50Z | 39,825,145 | <p>Based on your <code>500</code> error, I think some python packages are not installed correctly.</p>
<p>To check your code is working correctly in naive manner, do as follows.</p>
<ol>
<li>If you are developing on Windows machine, copy all of your <code>site-packages</code> files in development machine to WebApp <c... | 0 | 2016-10-03T05:37:11Z | [
"python",
"azure",
"flask",
"azure-web-sites"
] |
Flask app doesn't builds on MS Azure cloud | 39,790,145 | <p>I want to deploy my flask web application on Azure cloud. In Deployment options, I have selected GitHub as source destination for my flask code. after doing the configuration test successfully, the init.py file now starts building;<a href="http://i.stack.imgur.com/9vwfW.png" rel="nofollow"><img src="http://i.stack.i... | 0 | 2016-09-30T11:09:50Z | 39,864,475 | <p>If you created the Azure Webapp using the Flask tool, the default app is called <code>FlaskWebProject1</code>. If your app has a different name, you need to modify <code>web.config</code> in your <code>wwwroot</code> folder to reflect the correct app name. </p>
<p>Then redeploy using the Azure portal or change it ... | 0 | 2016-10-05T02:20:57Z | [
"python",
"azure",
"flask",
"azure-web-sites"
] |
calculating factorial of large numbers in 0.5 second with python | 39,790,221 | <p>I've been trying to find a super fast code that can calculate the factorial of a big number like 70000 in 0.5 second,My own code could do it in 10 seconds.I've searched everywhere, every code I find has memory error problem or is not as fast as I want. Can anyone help me with this?</p>
<pre><code>enter code here
im... | 0 | 2016-09-30T11:14:15Z | 39,790,388 | <p>Try to use the commutativity property of integer multiplication.</p>
<p>When multiplied numbers are long (they do not fit in a single word), the time necessary to perform the operation grows superlinearly with their length.</p>
<p>If you multiply the smallest (shortest in terms of memory representation) factors (a... | 0 | 2016-09-30T11:22:52Z | [
"python",
"factorial"
] |
calculating factorial of large numbers in 0.5 second with python | 39,790,221 | <p>I've been trying to find a super fast code that can calculate the factorial of a big number like 70000 in 0.5 second,My own code could do it in 10 seconds.I've searched everywhere, every code I find has memory error problem or is not as fast as I want. Can anyone help me with this?</p>
<pre><code>enter code here
im... | 0 | 2016-09-30T11:14:15Z | 39,790,889 | <p>For most practical use, the <a href="https://en.wikipedia.org/wiki/Stirling%27s_approximation" rel="nofollow">Stirling's approximation</a> is very fast and quite accurate</p>
<pre><code>import math
from decimal import Decimal
def fact(n):
d = Decimal(n)
return (Decimal(2 * math.pi) * d).sqrt() * (d / Decim... | 0 | 2016-09-30T11:51:28Z | [
"python",
"factorial"
] |
calculating factorial of large numbers in 0.5 second with python | 39,790,221 | <p>I've been trying to find a super fast code that can calculate the factorial of a big number like 70000 in 0.5 second,My own code could do it in 10 seconds.I've searched everywhere, every code I find has memory error problem or is not as fast as I want. Can anyone help me with this?</p>
<pre><code>enter code here
im... | 0 | 2016-09-30T11:14:15Z | 39,791,477 | <p>If you don't want a perfect precision, you can use the Stirling's approximation
<a href="https://en.wikipedia.org/wiki/Stirling's_approximation" rel="nofollow">https://en.wikipedia.org/wiki/Stirling's_approximation</a></p>
<pre><code>import np
n! ~ np.sqrt(2*np.pi*n)*(n/np.e)**n
</code></pre>
<p>for large n va... | 0 | 2016-09-30T12:24:03Z | [
"python",
"factorial"
] |
calculating factorial of large numbers in 0.5 second with python | 39,790,221 | <p>I've been trying to find a super fast code that can calculate the factorial of a big number like 70000 in 0.5 second,My own code could do it in 10 seconds.I've searched everywhere, every code I find has memory error problem or is not as fast as I want. Can anyone help me with this?</p>
<pre><code>enter code here
im... | 0 | 2016-09-30T11:14:15Z | 39,791,501 | <p>You may use <code>math.factorial()</code>. For example:</p>
<pre><code>from math import factorial
factorial(7000)
</code></pre>
<p>with <strong>execution time of 20.5 msec</strong> for calculating the factorial of <em>7000</em>:</p>
<pre><code>python -m timeit -c "from math import factorial; factorial(7000)"
10 ... | 0 | 2016-09-30T12:25:08Z | [
"python",
"factorial"
] |
Bubble Sort in PHP and Python | 39,790,316 | <p>As far as I can tell, these two programs should do exactly the same thing. However, the Python version works and the PHP one doesn't. What am I missing please?</p>
<pre><code>def bubbleSort(alist):
for passnum in range(len(alist)-1,0,-1):
for i in range(passnum):
if alist[i]>alist[i+1]:
... | 1 | 2016-09-30T11:19:32Z | 39,790,581 | <p>The sort is in fact working, but as you dont pass a reference to the <code>bubble_sort($arr)</code> function you never get to see the actual result. Telling <code>bubble_sort()</code> that the array is being passed by reference means you are changing <code>$my_list</code> and not a copy of <code>$my_list</code></p>
... | 1 | 2016-09-30T11:33:07Z | [
"php",
"python",
"bubble-sort"
] |
How to generate unique name for each JSON value | 39,790,342 | <p>I have following JSON, returned from a REST service, where I want to generate a unique names for each value by combining parent keys. For example. <code>name+phone+address+city+name</code> , <code>name+phone+address+city+population+skilled+male</code> and so on. </p>
<pre><code>{
"name": "name",
"phone": "34344... | -3 | 2016-09-30T11:20:44Z | 39,791,176 | <p>If you want to print all keys of your python dict you can do the following:</p>
<pre><code>def print_keys(d):
for key, value in d.iteritems():
print key,
if isinstance(value, dict):
print_keys(value)
</code></pre>
| 0 | 2016-09-30T12:07:22Z | [
"python",
"json",
"python-3.x"
] |
How to generate unique name for each JSON value | 39,790,342 | <p>I have following JSON, returned from a REST service, where I want to generate a unique names for each value by combining parent keys. For example. <code>name+phone+address+city+name</code> , <code>name+phone+address+city+population+skilled+male</code> and so on. </p>
<pre><code>{
"name": "name",
"phone": "34344... | -3 | 2016-09-30T11:20:44Z | 39,792,230 | <p>If you ignore the <code>name</code> and <code>phone</code> keys, since they are not ancestors of <code>city name</code> or <code>skilled male</code> and the order of keys is not guaranteed, you can recursively build a flattened dict. </p>
<pre><code>def walk_through(json_object):
d = {}
for k, v in json_obj... | 1 | 2016-09-30T13:03:31Z | [
"python",
"json",
"python-3.x"
] |
Docker for windows10 run django fail: Can't open file 'manage.py': [Errno 2] No such file or directory | 39,790,384 | <p>I just start a sample django app. And use docker to run it. My docker image like:</p>
<pre><code>FROM python:3.5
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
</code></pre>
<p>My docker-compose.yml file:</p>
<pre><code>version: '2... | 2 | 2016-09-30T11:22:39Z | 39,795,499 | <p>I think you either missed this step: <code>docker-compose run web django-admin.py startproject composeexample .</code> or you're using a directory that isn't available to the Virtual Machine that is running docker.</p>
<p>If it works when you remove <code>volumes: .:/code</code> from the Compose file, then you know... | 1 | 2016-09-30T15:54:39Z | [
"python",
"django",
"docker",
"docker-compose",
"cookiecutter-django"
] |
openpyxl if condition formula with reference fails | 39,790,457 | <p>Using python 2.7 and openpyxl, I am inserting an IF formula into excel worksheet that references fields in other sheet.</p>
<p>While other formulas work (CONTIF, COUTN, SUM, etc) I kind of do not find the reason for this "simple" IF formula does not to work. Only IF is the problem</p>
<p>This is my code </p>
<pre... | 0 | 2016-09-30T11:26:48Z | 39,790,987 | <p>Formulas are sometimes serialised in the XML differently than they appear in the GUI. They may have prefixes, or use different words, or, and I think this may be the case here, they use different separators between parameters. In countries which use a comma as the decimal separator, semi-colons are used to separate ... | 1 | 2016-09-30T11:57:01Z | [
"python",
"excel",
"openpyxl"
] |
openpyxl if condition formula with reference fails | 39,790,457 | <p>Using python 2.7 and openpyxl, I am inserting an IF formula into excel worksheet that references fields in other sheet.</p>
<p>While other formulas work (CONTIF, COUTN, SUM, etc) I kind of do not find the reason for this "simple" IF formula does not to work. Only IF is the problem</p>
<p>This is my code </p>
<pre... | 0 | 2016-09-30T11:26:48Z | 39,874,517 | <p>So at the end the whole problem was that with using IF formula commas have to be used "," not semi-colons ";"</p>
<p>NB you must use the English name for a function and function arguments must be separated by commas and not other punctuation such as semi-colons.</p>
| 0 | 2016-10-05T12:52:40Z | [
"python",
"excel",
"openpyxl"
] |
How the generate this specific chart in Python / Matplotlib | 39,790,566 | <p>I need to plot this specific chart in Python, or at least come very close to it, see the picture. I prefer to use the Matplotlib package and I already tried to a great extend but didn't came close enough. If I need another package for this then I am ok with that. </p>
<p><a href="http://i.stack.imgur.com/dGJ64.png"... | -3 | 2016-09-30T11:32:32Z | 39,828,327 | <p>Well, this is an attempt for an answer, unfortunately it is not categorical. </p>
<pre><code>import matplotlib.pyplot as plt
# example data
x = (1, 2, 3, 4)
y = (1, 2, 3, 4)
# example variable error bar values
yerr = [[0.2, 0.1, 0.5, 0.35], [0.7, 0.7, 0.3, 0.2]]
plt.figure()
plt.errorbar(x, y, yerr=yerr, fmt="r^... | 0 | 2016-10-03T09:24:43Z | [
"python",
"matplotlib",
"charts"
] |
How the generate this specific chart in Python / Matplotlib | 39,790,566 | <p>I need to plot this specific chart in Python, or at least come very close to it, see the picture. I prefer to use the Matplotlib package and I already tried to a great extend but didn't came close enough. If I need another package for this then I am ok with that. </p>
<p><a href="http://i.stack.imgur.com/dGJ64.png"... | -3 | 2016-09-30T11:32:32Z | 39,960,312 | <p>By searching the web (found most of the answers on this site) and a lot of trail and error I was able to generate the following chart:</p>
<p><a href="http://i.stack.imgur.com/HbfU8.png" rel="nofollow">enter image description here</a></p>
<p>These were the 3 key elements in the global construction of the chart:</p... | 0 | 2016-10-10T14:12:00Z | [
"python",
"matplotlib",
"charts"
] |
LMDB database for training of caffe convolutional network | 39,790,578 | <p>I am new to python and caffe and want to set up a convolutional network that takes images as input and gives processed images as output.
What I understood from some internet research was that caffe can take lmdb databases as input for training.
My question now is how to make a database entry with two images (raw a... | 0 | 2016-09-30T11:33:01Z | 39,876,076 | <p>you can, but don't have to make <code>lmdb</code> file as input. try this <a href="http://mi.eng.cam.ac.uk/projects/segnet/tutorial.html" rel="nofollow">tutorial</a>. good luck.</p>
| 0 | 2016-10-05T14:01:22Z | [
"python",
"deep-learning",
"caffe",
"lmdb"
] |
Tensorflow equivalent of Theano's dimshuffle | 39,790,829 | <p>How can I find the Tensorflow equivalent of Theano's dimshuffle function.</p>
<pre><code>mask = mask.dimshuffle(0, 1, "x")
</code></pre>
<p>I'm doing this I have tried many ways but couldn't find. Thank you :)</p>
| 1 | 2016-09-30T11:47:55Z | 39,792,376 | <p>You can use <a href="https://www.tensorflow.org/versions/master/api_docs/python/math_ops.html#transpose" rel="nofollow"><code>tf.transpose</code></a>:</p>
<pre><code> mask = tf.transpose(mask, perm=[0, 1])
</code></pre>
| 1 | 2016-09-30T13:11:19Z | [
"python",
"tensorflow",
"deep-learning",
"theano"
] |
Getting a tuple in a Dafaframe into multiple rows | 39,790,830 | <p>I have a Dataframe, which has two columns (Customer, Transactions).
The Transactions column is a tuple of all the transaction id's of that customer.</p>
<pre><code>Customer Transactions
1 (a,b,c)
2 (d,e)
</code></pre>
<p>I want to convert this into a dataframe, which has customer and transaction id'... | 1 | 2016-09-30T11:47:57Z | 39,790,938 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html" rel="nofollow"><code>DataFrame</code></a> constructor:</p>
<pre><code>df = pd.DataFrame({'Customer':[1,2],
'Transactions':[('a','b','c'),('d','e')]})
print (df)
Customer Transactions
0 1 ... | 1 | 2016-09-30T11:54:05Z | [
"python",
"pandas",
"dataframe",
"tuples",
"reshape"
] |
Getting a tuple in a Dafaframe into multiple rows | 39,790,830 | <p>I have a Dataframe, which has two columns (Customer, Transactions).
The Transactions column is a tuple of all the transaction id's of that customer.</p>
<pre><code>Customer Transactions
1 (a,b,c)
2 (d,e)
</code></pre>
<p>I want to convert this into a dataframe, which has customer and transaction id'... | 1 | 2016-09-30T11:47:57Z | 39,791,660 | <p>I think following is faster:</p>
<pre><code>import numpy as np
import random
import string
import pandas as pd
from itertools import chain
customer = np.unique(np.random.randint(0, 1000000, 100000))
transactions = [tuple(string.ascii_letters[:random.randint(3, 10)]) for _ in range(len(customer))]
df = pd.DataFrame... | 0 | 2016-09-30T12:34:29Z | [
"python",
"pandas",
"dataframe",
"tuples",
"reshape"
] |
python: can't open file get-pip.py error 2] no such file or directory | 39,790,923 | <p>when I am trying to execute this in CMD</p>
<pre><code>python get-pip.py
</code></pre>
<p>I am getting this
python: can't open file get-pip.py error 2] no such file or directory</p>
<p>while the file store in (get-pip.py)</p>
<blockquote>
<p>C:\Python27\Tools\Scripts</p>
</blockquote>
| 0 | 2016-09-30T11:53:22Z | 39,790,976 | <p>Try to either <code>cd</code> into folder with script (<code>cd "C:\Python27\Tools\Scripts"</code>) or add this folder to your PATH variable.</p>
| 1 | 2016-09-30T11:56:29Z | [
"python"
] |
Setting an index limit in SQLAlchemy | 39,791,026 | <p>I would like to set up a maximum limit for an index within a <code>Column</code> definition or just through the <code>Index</code> constructor but I don't seem to find a way to achieve it.</p>
<p>Basically, I would like to simulate this MySQL behaviour:</p>
<pre><code>CREATE TABLE some_table (
id int(11) NOT NUL... | 2 | 2016-09-30T11:59:14Z | 39,791,161 | <p>I think you can do something like: </p>
<pre><code>class SomeTable(BaseModel):
__tablename__ = 'some_table'
__seqname__ = 'some_table_id_seq'
__table_args__ = (
sa.Index("idx_some_text", "some_text", mysql_length=1024),
)
id = sa.Column(sa.Integer(11), sa.Sequence(__seqname__), primary_key=True)
s... | 3 | 2016-09-30T12:06:48Z | [
"python",
"mysql",
"indexing",
"sqlalchemy"
] |
How to append a list of csr matrices | 39,791,088 | <p>I have a list of <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.html" rel="nofollow">csr matrices</a> in a list called <code>L</code>. All the matrices have the same dimension which is <code>1</code> by <code>100000</code>. How can I append them so I end up with one csr matrix o... | 0 | 2016-09-30T12:03:12Z | 39,791,169 | <p>I think a <em>vertical stack</em> i.e. <a href="http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.sparse.vstack.html" rel="nofollow"><code>vstack</code></a> will do:</p>
<pre><code>from scipy.sparse import vstack
new_array = vstack(L).toarray()
</code></pre>
| 3 | 2016-09-30T12:07:09Z | [
"python",
"scipy"
] |
Changing the proxy server during Selenium | 39,791,242 | <p>So everything works</p>
<pre><code>fp = webdriver.FirefoxProfile()
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http", PROXY_HOST)
fp.set_preference("network.proxy.http_port", int(PROXY_PORT))
fp.update_preferences()
driver = webdriver.Firefox(firefox_profile=fp)
</code></pre>
<p>But... | 0 | 2016-09-30T12:11:16Z | 39,810,577 | <p>When using WebDriver with Firefox, the use of the profile is a one-time thing. When the driver launches the browser, it writes the profile object to disk, then starts the browser executable. After that point, there is no mechanism for the browser to read any further changes to the WebDriver profile object. To change... | 0 | 2016-10-01T19:17:19Z | [
"python",
"selenium",
"selenium-webdriver",
"proxy",
"updates"
] |
How do I install a .whl file in a PyCharm virtualenv? | 39,791,243 | <p>The package manager in Project Interpreter doesn't appear to have any way for me to run a pure pip command so I'm unable to install the wheel as I normally would through command line.</p>
<p>Running through command line installs the wheel on my base python install and not the virtualenv. Help?</p>
| 2 | 2016-09-30T12:11:18Z | 39,791,424 | <p>To install via your command line, and avoid installing on your <em>base</em> Python, you'll have to first <em>activate</em> the <code>virtualenv</code>:</p>
<pre><code>$ source path_to_your_venv/bin/activate
</code></pre>
<p>for POSIX systems, and:</p>
<pre><code>> path_to_venv\Scripts\activate
</code></pre>
... | 1 | 2016-09-30T12:21:04Z | [
"python",
"python-2.7",
"python-3.x",
"pycharm"
] |
calculate number ticks from outside of the .net framework | 39,791,257 | <p>Does anyone know how to calculate the number of .net time ticks from outside of the .net framework? my situation involves a python script on Linux (my side) needing to send a timestamp as the number of ticks in a message destined for a C# process (the other side, who can't change its code). I can't find any librarie... | 0 | 2016-09-30T12:12:12Z | 39,792,175 | <p>You can easily determine what the Unix/Linux epoch (1970-01-01 00:00:00) is in DateTime ticks:</p>
<pre><code>DateTime netTime = new DateTime(1970, 1, 1, 0, 0, 0);
Console.WriteLine(netTime.Ticks);
// Prints 621355968000000000
</code></pre>
<p>Since the Unix/Linux timestamp is the number of seconds since 1970-01-0... | 1 | 2016-09-30T13:01:10Z | [
"c#",
"python",
".net",
"timestamp"
] |
Create Excel Hyperlinks in Python | 39,791,441 | <p>I am using win32com to modify an Excel spreadsheet (Both read and edit at the same time) I know there are other modules out there that can do one or the other but for the application I am doing I need it read and processed at the same time.</p>
<p>The final step is to create some hyperlinks off of a path name. Here... | 0 | 2016-09-30T12:21:56Z | 39,791,989 | <p>Borrowing heavily from <a href="https://www.experts-exchange.com/questions/21349668/Using-win32com-with-Python.html" rel="nofollow">this</a> question, as I couldn't find anything on SO to link to as a duplicate...</p>
<p>This code will create a Hyperlink in cells <code>A1:A9</code></p>
<pre><code>import win32com.c... | 1 | 2016-09-30T12:52:09Z | [
"python",
"excel",
"python-2.7",
"win32com"
] |
Create list of given length with given values - convert histogram to list of values | 39,791,535 | <p>I have a histogram which I need to convert into a list of individual instances for another piece of software I am using: If I have four hits for a value of "1" and three hits for a value of "2" then my list would need to read <code>[1,1,1,1,2,2,2]</code>.</p>
<p>My histogram is structured as two numpy arrays packed... | 2 | 2016-09-30T12:26:54Z | 39,791,670 | <p>Those <code>i</code> indices are basically range of elements ranging for the length of number of <code>hist[0]</code> elements repeated by the numbers present in that first array <code>hist[0]</code> itself. Using those we simply index into the second array <code>hist[1]</code> to give us the desired output. For the... | 2 | 2016-09-30T12:34:57Z | [
"python",
"arrays",
"list",
"numpy"
] |
Integer matrix to stochastic matrix normalization | 39,791,643 | <p>Suppose I have matrix with integer values. I want to make it stochastic matrix (i.e. sum of each row in matrix equal to 1)</p>
<p>I create random matrix, count sum of each row and divide each element in row for row sum.</p>
<pre><code>dt = pd.DataFrame(np.random.randint(0,10000,size=10000).reshape(100,100))
dt['su... | 0 | 2016-09-30T12:33:35Z | 39,792,848 | <p>You can't guarantee the floats will be exactly one, but you can check the closely to an arbitrary precision with <code>np.around</code>.</p>
<p>This is probably easier/faster without looping through pandas columns.</p>
<pre><code>X = np.random.randint(0,10000,size=10000).reshape(100,100)
X_float = X.astype(float)
... | 1 | 2016-09-30T13:35:16Z | [
"python",
"pandas",
"numpy",
"normalization",
"stochastic"
] |
How to number unique words on each individual line, not miss paragraph? | 39,791,891 | <p>Before anything I am reading English language and programming, but I am beginner now. So I did a lot of methods to learn EN ( self-study ) but finally I make a personal method to learn.<br>
So I collected a lot of <strong>short story</strong> then, read those, day after day. Now I am doing this method as usual.<br>
... | -2 | 2016-09-30T12:47:43Z | 39,792,050 | <p>A quick and very dirty solution in Python...</p>
<pre><code>story = 'He wakes up. He sees the sun rise. He brushes his teeth are white He puts on his clothes. His shirt is blue. His shoes are yellow. His pants are brown. He goes downstairs. He gets a bowl. He pours some milk and cereal. He eats. He gets the newspap... | 0 | 2016-09-30T12:55:11Z | [
"python",
"bash",
"perl"
] |
How to number unique words on each individual line, not miss paragraph? | 39,791,891 | <p>Before anything I am reading English language and programming, but I am beginner now. So I did a lot of methods to learn EN ( self-study ) but finally I make a personal method to learn.<br>
So I collected a lot of <strong>short story</strong> then, read those, day after day. Now I am doing this method as usual.<br>
... | -2 | 2016-09-30T12:47:43Z | 39,792,081 | <pre><code>#!/usr/bin/perl
use strict;
use warnings;
my @words = <DATA> =~ /(\w+)/g;
my %seen;
my $count = 1;
foreach my $value (@words) {
if ( !$seen{$value} ) {
print "$count.$value ";
$seen{$value} = 1;
}
else{
print "$value";
}
$count++;
}
__DATA__
He wakes up. He sees the sun rise. He b... | 1 | 2016-09-30T12:57:10Z | [
"python",
"bash",
"perl"
] |
How to number unique words on each individual line, not miss paragraph? | 39,791,891 | <p>Before anything I am reading English language and programming, but I am beginner now. So I did a lot of methods to learn EN ( self-study ) but finally I make a personal method to learn.<br>
So I collected a lot of <strong>short story</strong> then, read those, day after day. Now I am doing this method as usual.<br>
... | -2 | 2016-09-30T12:47:43Z | 39,792,614 | <p><code>awk</code> to the rescue!</p>
<pre><code>$ awk -v RS=" +" -v ORS=" " '{key=$0;gsub(/[^A-Za-z]/,"",key);
if(key in a)print $0;
else{a[key];print ++c"."$0}}' file
</code></pre>
<blockquote>
<p>1.He 2.wakes 3.up. He 4.sees 5.the 6.sun 7.rise. He 8.b... | 1 | 2016-09-30T13:23:07Z | [
"python",
"bash",
"perl"
] |
How to number unique words on each individual line, not miss paragraph? | 39,791,891 | <p>Before anything I am reading English language and programming, but I am beginner now. So I did a lot of methods to learn EN ( self-study ) but finally I make a personal method to learn.<br>
So I collected a lot of <strong>short story</strong> then, read those, day after day. Now I am doing this method as usual.<br>
... | -2 | 2016-09-30T12:47:43Z | 39,793,083 | <pre><code>$ cat script.txt
BEGIN {RS=" "; ORS=" "} # the record is a word
{
key=$0 # separate key to clean it up
gsub(/[^a-zA-Z]/,"",key) # remove ".," etc.
key=tolower(key) # and capitals
if(!(key in a)) { # if not seen before
print ++i; a[key] #... | 1 | 2016-09-30T13:48:02Z | [
"python",
"bash",
"perl"
] |
Text from LineEdit1 (Form1) to LineEdit2 (Form2)_ Python, PyQt | 39,791,935 | <p>I have created MainWindow with LineEdit11 and button1 in main window. Also I created V1 Form 2 with LineEdit and a button 2.</p>
<p>When I cliked a Button1 Form 2 will show. I write a text in lineEdit and i want to transfer text to LineEdit11 in form1 by cliked Button2. How to connect them? </p>
<p>Python 3.5, Py... | -2 | 2016-09-30T12:49:34Z | 39,792,710 | <p>Without any code the simplest way (but not the best) would be something like that :</p>
<pre><code>def on_button2_click(self):
self.form2.lineEdit2.setText(self.lineEdit1.text())
</code></pre>
| 0 | 2016-09-30T13:27:58Z | [
"python",
"pyqt4"
] |
python Tkinter tkFileDialog | 39,791,942 | <p>in short, what's the difference between</p>
<pre><code>tkFileDialog.asksaveasfile
</code></pre>
<p>and</p>
<pre><code>tkFileDialog.asksaveasfilename
</code></pre>
<p>I could not understand from the build in docs</p>
| 0 | 2016-09-30T12:49:53Z | 39,792,020 | <p><code>asksaveasfile</code> asks the user for a file, then opens that file in write mode and returns it to you so you can write in it.</p>
<p><code>asksaveasfilename</code> asks the user for a file, then returns that file's name. No file is opened; if you want to write to the file, you'll have to open it yourself.</... | 4 | 2016-09-30T12:53:51Z | [
"python",
"tkinter"
] |
python Tkinter tkFileDialog | 39,791,942 | <p>in short, what's the difference between</p>
<pre><code>tkFileDialog.asksaveasfile
</code></pre>
<p>and</p>
<pre><code>tkFileDialog.asksaveasfilename
</code></pre>
<p>I could not understand from the build in docs</p>
| 0 | 2016-09-30T12:49:53Z | 39,792,041 | <p>According to the <a href="http://tkinter.unpythonic.net/wiki/tkFileDialog" rel="nofollow">http://tkinter.unpythonic.net/</a> wiki:</p>
<p>Similar to:</p>
<blockquote>
<p>First you have to decide if you want to open a file or just want to get a filename in order to open the file on your own. In the first case you... | 2 | 2016-09-30T12:54:46Z | [
"python",
"tkinter"
] |
Using adaptive time step for scipy.integrate.ode when solving ODE systems | 39,792,111 | <p>I have to just read <a href="http://stackoverflow.com/questions/12926393/using-adaptive-step-sizes-with-scipy-integrate-ode">Using adaptive step sizes with scipy.integrate.ode</a> and the accepted solution to that problem, and have even reproduced the results by copy-and-paste in my Python interpreter. </p>
<p>My p... | 0 | 2016-09-30T12:58:30Z | 39,815,225 | <p>In the line </p>
<pre><code> y_solutions.append(y)
</code></pre>
<p>you think that you are appending the current vector. What actally happens is that you are appending the object reference to <code>y</code>. Since apparently the integrator reuses the vector <code>y</code> during the integration loop, you are al... | 1 | 2016-10-02T08:30:48Z | [
"python",
"python-3.x",
"scipy",
"ode"
] |
Selenium with Python keeps to load a page | 39,792,146 | <p>I am trying to read a page using a simple Python/Selenium script</p>
<pre><code># encoding=utf8
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import datetime as dt
import codecs
import os
myDriver=webdriver.Chrome()
myDriver.get("http://spb.beeline.ru/customers/products/mobile/tari... | 0 | 2016-09-30T12:59:41Z | 39,792,558 | <p>I'm not sure what that page is doing, but it is certainly atypical. My best suggestion is to set the page load timeout and then handle the associated TimeoutException:</p>
<pre><code># encoding=utf8
from __future__ import print_function
from selenium import webdriver
from selenium.common.exceptions import TimeoutE... | 0 | 2016-09-30T13:20:14Z | [
"python",
"selenium",
"selenium-chromedriver"
] |
Vectorizing sRGB to linear conversion properly in Numpy | 39,792,163 | <p>In my image editing app I have a function for converting a 32 bit float image from sRGB to linear color space. The formula is:</p>
<pre><code>if value <= 0.04045: (value / 12.92)
if value > 0.04045: ((value + 0.055) / 1.055)^2.4)
</code></pre>
<p>My image is a three-dimensional <strong>numpy.ndarray</strong>... | 2 | 2016-09-30T13:00:30Z | 39,792,372 | <p>A clean way would be with <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html" rel="nofollow"><code>np.where</code></a> that lets us choose between two values based on a mask. In our case, the mask could be <code>img32 >= 0.04045</code> and we will choose <code>((img32 + 0.055) / 1.055)... | 1 | 2016-09-30T13:11:12Z | [
"python",
"numpy",
"vectorization",
"color-space",
"srgb"
] |
Vectorizing sRGB to linear conversion properly in Numpy | 39,792,163 | <p>In my image editing app I have a function for converting a 32 bit float image from sRGB to linear color space. The formula is:</p>
<pre><code>if value <= 0.04045: (value / 12.92)
if value > 0.04045: ((value + 0.055) / 1.055)^2.4)
</code></pre>
<p>My image is a three-dimensional <strong>numpy.ndarray</strong>... | 2 | 2016-09-30T13:00:30Z | 39,792,474 |
<pre><code>b = (img32 < 0.04045)
img32[b] /= 12.92
not_b = numpy.logical_not(b)
img32[not_b] += 0.05
img32[not_b] /= 1.055
img32[not_b] **= 2.4
</code></pre>
| 0 | 2016-09-30T13:16:29Z | [
"python",
"numpy",
"vectorization",
"color-space",
"srgb"
] |
Vectorizing sRGB to linear conversion properly in Numpy | 39,792,163 | <p>In my image editing app I have a function for converting a 32 bit float image from sRGB to linear color space. The formula is:</p>
<pre><code>if value <= 0.04045: (value / 12.92)
if value > 0.04045: ((value + 0.055) / 1.055)^2.4)
</code></pre>
<p>My image is a three-dimensional <strong>numpy.ndarray</strong>... | 2 | 2016-09-30T13:00:30Z | 39,792,885 | <p>You could also use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.piecewise.html" rel="nofollow">numpy.piecewise</a>:</p>
<pre><code>In [11]: img32 = np.random.rand(800, 600).astype(np.float32)
In [12]: img_linear = np.piecewise(img32,
[img32 <= 0.04045, img32 > 0.04045],
... | 1 | 2016-09-30T13:37:02Z | [
"python",
"numpy",
"vectorization",
"color-space",
"srgb"
] |
(timezone aware) datetime in netcdf using python | 39,792,228 | <p>I'm trying to save a timeserie in a netcdf file. According to documentation I found, this can be done using the date2num method from the netCDF4 module. I can't get it working however (see example below):</p>
<pre><code>from datetime import datetime as dt
from netCDF4 import Dataset
from netCDF4 import num2date, da... | 1 | 2016-09-30T13:03:29Z | 39,797,924 | <p>The <a href="http://unidata.github.io/netcdf4-python/#netCDF4.date2num" rel="nofollow">date2num() doc</a> says that the datetime object must be UTC. A number cannot be timezone aware,unless it is UTC. Would cause great problems with standard/daylight time transitions.</p>
<p>Try</p>
<pre><code>listDT = [dt.now(), ... | 0 | 2016-09-30T18:31:31Z | [
"python",
"datetime",
"netcdf"
] |
catching a form with Flask (very basic case) | 39,792,231 | <p>I want to use a very simple form to post comments to a Flask server.</p>
<p>My index.html is:</p>
<pre><code><form method="post" enctype="text/plain">
Name:<br>
<input type="text" name="id"> <br>
Comment:<br>
<input type="text" name="comment"> <br>
<... | -1 | 2016-09-30T13:03:33Z | 39,793,029 | <p>You're getting a KeyError there because <code>request.form</code> is a <a href="http://werkzeug.pocoo.org/docs/0.11/datastructures/#werkzeug.datastructures.MultiDict" rel="nofollow"><code>ImmutableMultiDict</code></a> and a descendant of a python <code>dict</code>. You get <code>KeyError</code> raised when you try t... | 1 | 2016-09-30T13:44:55Z | [
"python",
"html",
"forms",
"flask"
] |
How is this a coroutine? | 39,792,323 | <p>I'm trying to understand the coroutines in Python (and in general). Been reading about the theory, the concept and a few examples, but I'm still struggling. I understand the asynchronous model (did a bit of Twisted) but not coroutines yet.</p>
<p>One <a href="http://www.blog.pythonlibrary.org/2016/07/26/python-3-an... | 2 | 2016-09-30T13:08:18Z | 39,792,393 | <p>The <em>co</em> in <em>coroutine</em> stands for <em>cooperative</em>. Yielding (to other routines) makes a routine a co-routine, really, because only by yielding when waiting can other co-routines be interleaved. In the new <code>async</code> world of Python 3.5 and up, that usually is achieved by <code>await</code... | 6 | 2016-09-30T13:12:16Z | [
"python",
"python-3.x",
"async-await",
"coroutine"
] |
how to i use check button to show the snap | 39,792,541 | <p><strong>My program is designed to:</strong></p>
<ul>
<li><p>Initially, the Label shows nothing (i.e., it is empty).</p></li>
<li><p>Any number of the Checkbuttons may be selected by the user.</p></li>
<li><p>Any selected Checkbuttons may be unselected by the user.</p></li>
<li><p>When any two Checkbuttons are selec... | -1 | 2016-09-30T13:19:09Z | 39,793,323 | <p>It looks like you're using Tkinter. As the <a href="http://effbot.org/tkinterbook/checkbutton.htm" rel="nofollow">Tkinter docs</a> say "each Checkbutton widget should be associated with a variable". You can detect whether the widget is selected or not by using the <code>.get()</code> method of the variable: a value ... | 3 | 2016-09-30T14:00:52Z | [
"python",
"tkinter"
] |
Scrapy (python) TypeError: unhashable type: 'list' | 39,792,600 | <p>I have this simple scrappy code. However get this error when i use <code>response.urljoin(port_homepage_url)</code> this portion of the code.</p>
<pre><code>import re
import scrapy
from vesseltracker.items import VesseltrackerItem
class GetVessel(scrapy.Spider):
name = "getvessel"
allowed_domains = ["mar... | 2 | 2016-09-30T13:22:17Z | 39,792,931 | <p>The <code>ports.xpath('td[7]/a/@href').extract()</code> returns a <em>list</em> and when you try to do the "urljoin" on it, it fails. Use <code>extract_first()</code> instead:</p>
<pre><code>port_homepage_url = ports.xpath('td[7]/a/@href').extract_first()
</code></pre>
| 2 | 2016-09-30T13:39:43Z | [
"python",
"scrapy"
] |
Using Selenium to extract data provided by an autocomplete search | 39,792,641 | <p>I want to extract part of the result provided by a site's search bar's auto complete. I'm having trouble extracting the result. I'm able to enter the query I want, but I'm unable to store the autosuggestion. It seems whenever I click the drop down suggestions to "inspect element" in order to find what to select the ... | 0 | 2016-09-30T13:24:37Z | 39,792,898 | <p>This should work.
Basically you will have find the xpath locators of those web elements'</p>
<p>In your case it was like </p>
<pre><code><ul class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content ui-corner-all" id="ui-id-3" tabindex="0" style="display: none; top: 375px; left: 63px; width: 306px;"&g... | 2 | 2016-09-30T13:37:37Z | [
"python",
"selenium",
"selenium-chromedriver"
] |
How to get the reactor from ApplicationRunner in autobahnPython | 39,792,761 | <p>I have an autobahn client using the ApplicationRunner class from autobahn to connect to a WAMP router (crossbar). In the main section it attaches my ApplicationSession class "REScheduler" like this:</p>
<pre><code>if __name__ == '__main__':
from autobahn.twisted.wamp import ApplicationRunner
runner = Appl... | 0 | 2016-09-30T13:31:07Z | 39,792,913 | <p>Twisted (sadly) uses a (process) global reactor object. That means, once a reactor is chosen (which <code>ApplicationRunner</code> does if you set <code>start_reactor=True</code>), simply do a <code>from twisted.internet import reactor</code> at <strong>the place within your code</strong> where you need it.</p>
<p>... | 2 | 2016-09-30T13:38:17Z | [
"python",
"twisted",
"autobahn",
"crossbar"
] |
Equating the lengths of the arrays in an array of arrays | 39,792,815 | <p>Given an array of arrays with different lengths. Is there a cleaner (shorter) way to equate the lengths of the arrays by filling the shorter ones with zeros other than the following code:</p>
<pre><code>a = [[1.0, 2.0, 3.0, 4.0],[2.0, 3.0, 1.0],[5.0, 5.0, 5.0, 5.0],[1.0, 1.0]]
max =0
for x in a:
if len(x) >... | 2 | 2016-09-30T13:33:31Z | 39,792,869 | <pre><code>In: b = [i+[0.]*(max(map(len,a))-len(i)) for i in a]
In: b
Out:
[[1.0, 2.0, 3.0, 4.0],
[2.0, 3.0, 1.0, 0.0],
[5.0, 5.0, 5.0, 5.0],
[1.0, 1.0, 0.0, 0.0]]
</code></pre>
| 1 | 2016-09-30T13:36:19Z | [
"python"
] |
Equating the lengths of the arrays in an array of arrays | 39,792,815 | <p>Given an array of arrays with different lengths. Is there a cleaner (shorter) way to equate the lengths of the arrays by filling the shorter ones with zeros other than the following code:</p>
<pre><code>a = [[1.0, 2.0, 3.0, 4.0],[2.0, 3.0, 1.0],[5.0, 5.0, 5.0, 5.0],[1.0, 1.0]]
max =0
for x in a:
if len(x) >... | 2 | 2016-09-30T13:33:31Z | 39,792,878 | <p>You can find the length of the largest list within <code>a</code> using either:</p>
<p><code>len(max(a, key=len))</code> </p>
<p>or </p>
<p><code>max(map(len, a))</code></p>
<p>and also use a list comprehension to construct a new list:</p>
<pre><code>>>> a = [[1.0, 2.0, 3.0, 4.0], [2.0, 3.0, 1.0], [5.0... | 5 | 2016-09-30T13:36:53Z | [
"python"
] |
Django - Using multiple models for authentication | 39,792,837 | <p>I am kind of new to django and I am concerned about can we use multiple models for authentication for different types of users for our application e.g for Customers use Customer model, for Suppliers use Supplier model and also keep default User registration model for administration use only? If so can you point me i... | 0 | 2016-09-30T13:34:40Z | 39,794,111 | <p>There are a few different options to handle that.
Maybe check first <a href="https://docs.djangoproject.com/en/1.8/topics/auth/customizing/" rel="nofollow">the Django-docu</a>.
I've you'ld like to customize it to authenticate your users with a mail-address, there's a nice Tutorial <a class='doc-link' href="http://s... | 0 | 2016-09-30T14:40:27Z | [
"python",
"django",
"authentication",
"django-registration",
"custom-authentication"
] |
Getting flask-restful routes from within a blueprint | 39,792,872 | <p>Is there a way to get the routes defined in a blueprint? I know this (<a href="http://flask.pocoo.org/snippets/117/" rel="nofollow">http://flask.pocoo.org/snippets/117/</a>) snippit exists, but requires to have the app initalized to use url_map. Is there a way to view the routes without an application? I'm developin... | 0 | 2016-09-30T13:36:35Z | 39,808,625 | <p>Using the information provided by polyfunc, I was able to come up with this solution:</p>
<pre><code>from flask import Blueprint, current_app, url_for
from flask_restful import Resource, Api
api_blueprint = Blueprint('api', __name__)
api = Api(api_blueprint)
@api.resource('/foo')
class Foo(Resource):
def get(... | 0 | 2016-10-01T15:55:58Z | [
"python",
"flask",
"flask-restful"
] |
Subquery with count in SQLAlchemy | 39,792,884 | <p>Given these SQLAlchemy model definitions:</p>
<pre><code>class Store(db.Model):
__tablename__ = 'store'
id = Column(Integer, primary_key=True)
name = Column(String, nullable=False)
class CustomerAccount(db.Model, AccountMixin):
__tablename__ = 'customer_account'
id = Column(Integer, primary_... | 0 | 2016-09-30T13:37:00Z | 39,795,716 | <p>Thanks to Alex Grönholm on #sqlalchemy I ended up with this working solution:</p>
<pre><code>from sqlalchemy.sql.expression import label
from sqlalchemy.sql.functions import coalesce
from instalment.models import db
from sqlalchemy import func, desc
def projected_total_money_volume_breakdown(store):
subscri... | 0 | 2016-09-30T16:06:21Z | [
"python",
"sql",
"sqlalchemy"
] |
What are some ways to post python pandas dataframes to slack? | 39,792,891 | <p>How can I export a pandas dataframe to slack? </p>
<p>df.to_json() seems like a potential candidate, coupled with the slack incoming webhook, but then parsing the message to display as a nice markdown/html-ized table isn't obvious to me.</p>
<p>Long time listener, first time caller, please go easy on me...</p>
| 1 | 2016-09-30T13:37:19Z | 39,793,055 | <p>There is a <code>.to_html()</code> method on DataFrames, so that might work. But if you are just looking to cut and paste, <a href="https://pypi.python.org/pypi/tabulate" rel="nofollow">Tabulate</a> is a good choice. From the docs:</p>
<pre><code>from tabulate import tabulate
df = pd.DataFrame([["Name","Age"],["A... | 0 | 2016-09-30T13:46:47Z | [
"python",
"pandas",
"slack"
] |
level curves with pyqtgraph: isocurve | 39,792,905 | <p>Does anybody know a way to obtain this (<a href="http://i.stack.imgur.com/SZLIl.png" rel="nofollow">level curves from matplotlib</a>) using isocurve from pyqtgraph?
Here's my code...</p>
<p>Thank you!</p>
<pre><code>from pyqtgraph.Qt import QtGui,QtCore
import numpy as np
import pyqtgraph as pg
import sys
#data c... | 0 | 2016-09-30T13:37:57Z | 39,835,334 | <p>[SOLVED] I had to edit the "functions.py" at row ~1500 in order to get rid of the error</p>
<pre><code>"TypeError: Cannot cast ufunc add output from dtype('int32') to dtype('uint8') with casting rule 'same_kind'".
</code></pre>
<p>The file "functions.py" is located in
C:\Users\my_name\AppData\Local\Programs\Python... | 0 | 2016-10-03T15:37:27Z | [
"python",
"surface",
"level",
"pyqtgraph"
] |
Lazily create dask dataframe from generator | 39,792,928 | <p>I want to lazily create a Dask dataframe from a generator, which looks something like:</p>
<pre><code>[parser.read(local_file_name) for local_file_name in repo.download_files())]
</code></pre>
<p>Where both parser.read and repo.download_files return generators (using yield). parser.read yields a dictionary of key-... | 1 | 2016-09-30T13:39:33Z | 39,807,277 | <p>If you want to use the single-machine Dask scheduler then you'll need to know how many files you have to begin with. This might be something like the following:</p>
<pre><code>filenames = repo.download_files()
dataframes = [delayed(load)(filename) for filename in filenames]
df = dd.from_delayed(dataframes)
</code>... | 1 | 2016-10-01T13:34:52Z | [
"python",
"pandas",
"dask"
] |
Resampling Error : cannot reindex a non-unique index with a method or limit | 39,792,933 | <p>I am using Pandas to structure and process Data.</p>
<p>I have here a DataFrame with dates as index, Id and bitrate.
I want to group my Data by Id and resample, at the same time, timedates which are relative to every Id, and finally keep the bitrate score.</p>
<p>For example, given :</p>
<pre><code>df = pd.DataFr... | 2 | 2016-09-30T13:39:44Z | 39,793,110 | <p>It seems there is problem with duplicates in columns <code>beginning_time</code> and <code>end_time</code>, I try simulate it:</p>
<pre><code>df = pd.DataFrame(
{'Id' : ['CODI126640013.ts', 'CODI126622312.ts', 'a'],
'beginning_time':['2016-07-08 02:17:42', '2016-07-08 02:17:42', '2016-07-08 02:17:45'],
'end_time' ... | 2 | 2016-09-30T13:49:21Z | [
"python",
"python-2.7",
"pandas",
"group-by",
"resampling"
] |
write unicode objects from loop to list in Python | 39,793,030 | <p>I have a loop that returns me unicode objects:</p>
<pre><code>for i in X:
print i
Output:
A
B
C
...
Z
</code></pre>
<p>How can I make a list of these objects to get the folloving?</p>
<pre><code>['A', 'B', ..., 'Z']
</code></pre>
<p>If they were numbers, i'd do</p>
<pre><code>for i in X:
y=[]
i.ap... | -1 | 2016-09-30T13:45:00Z | 39,793,062 | <p>try this:</p>
<p><code>output_list = [y for y in x]</code></p>
<p>in your loop:</p>
<pre><code>for i in X:
i.append(X)
</code></pre>
<p>it takes each item in <code>X</code>, which are unicode chars, and tries to append the whole <code>X</code> object to it.</p>
<p>I think what you're wanting to do is like t... | 0 | 2016-09-30T13:46:59Z | [
"python",
"list",
"unicode",
"append"
] |
write unicode objects from loop to list in Python | 39,793,030 | <p>I have a loop that returns me unicode objects:</p>
<pre><code>for i in X:
print i
Output:
A
B
C
...
Z
</code></pre>
<p>How can I make a list of these objects to get the folloving?</p>
<pre><code>['A', 'B', ..., 'Z']
</code></pre>
<p>If they were numbers, i'd do</p>
<pre><code>for i in X:
y=[]
i.ap... | -1 | 2016-09-30T13:45:00Z | 39,793,159 | <p>If you are looping through a variable, you already know it is an iterable, such as a generator or list. First, you need to tell us the type of the <code>x</code> variable in your statement.</p>
<p>If your expected output is a list and <code>x</code> is not one, simply call the <code>list</code> function:</p>
<pre>... | 0 | 2016-09-30T13:51:20Z | [
"python",
"list",
"unicode",
"append"
] |
sqlite3 INSERT IF NOT EXIST (with Python) | 39,793,327 | <p>First of all, I am really super-new so I hope that I will be able to post the question correctly. Please tell me if there is any problem.</p>
<p>Now, here is my question: I would like to fill a database with a data, only if it doesn't already exist in it. I searched for this topic and I think I found correct the an... | 0 | 2016-09-30T14:01:09Z | 39,794,247 | <p>First, you need to combine everything into a single <code>self.cur.execute()</code> call. Each call to this must be a complete query, they're not concatenated to each other.</p>
<p>Second, you can't have both <code>VALUES</code> and <code>SELECT</code> as the source of data in an
<code>INSERT</code> query, it has ... | 0 | 2016-09-30T14:47:25Z | [
"python",
"database",
"sqlite",
"sqlite3",
"insert"
] |
sqlite3 INSERT IF NOT EXIST (with Python) | 39,793,327 | <p>First of all, I am really super-new so I hope that I will be able to post the question correctly. Please tell me if there is any problem.</p>
<p>Now, here is my question: I would like to fill a database with a data, only if it doesn't already exist in it. I searched for this topic and I think I found correct the an... | 0 | 2016-09-30T14:01:09Z | 39,794,295 | <p>Assuming <code>a</code> is in a column called "Col1", <code>b</code> is in "Col2" and <code>c</code> is in "Col3", the following should check for the existence of such a row:</p>
<pre><code>self.cur.execute('SELECT * FROM ProSolut WHERE (Col1=? AND Col2=? AND Col3=?)', ('a', 'b', 'c'))
entry = self.cur.fetchone()
... | 0 | 2016-09-30T14:49:42Z | [
"python",
"database",
"sqlite",
"sqlite3",
"insert"
] |
Mykrobe predictor AMR prediction not working | 39,793,340 | <p>I am getting the following error message when trying to execute AMR prediction on the command line.</p>
<pre><code>mykrobe predict tb_sample_id tb -1 /home/TB/demo_input_file_for_M.tuberculosis_app.fastq
</code></pre>
<p>The species chosen was Tuberculosis (TB), whereas the sample data file was pulled down from My... | 1 | 2016-09-30T14:01:54Z | 39,795,539 | <p>The error indicates that <code>mccortex31</code> is missing. </p>
<p>Did you install it according to the <a href="https://github.com/iqbal-lab/Mykrobe-predictor" rel="nofollow">documentation</a>?</p>
<pre><code>cd Mykrobe-predictor
cd mccortex
make
export PATH=$PATH:$(pwd)/bin
cd ..
</code></pre>
| 1 | 2016-09-30T15:56:35Z | [
"python",
"linux",
"sequence",
"bioinformatics"
] |
dropbox object does not have Dropbox attribute in Python | 39,793,429 | <p>I am now using Python to download files from Dropbox, and I following <a href="https://www.dropbox.com/developers/documentation/python#tutorial" rel="nofollow">this tutorial</a>. However, it did not succeed on the first two lines of codes:</p>
<pre><code>import dropbox
dbx = dropbox.Dropbox('YOUR_ACCESS_TOKEN')
</c... | 0 | 2016-09-30T14:06:14Z | 39,795,219 | <p>After careful examination, I found the reason is because I am using functions from dropbox-v2 while in my machine dropbox-v1 was installed. </p>
| 0 | 2016-09-30T15:39:49Z | [
"python",
"dropbox-api"
] |
Python -Two figures in one plot | 39,793,508 | <p>I have two python plot functions: </p>
<pre><code>def plotData(data):
fig, ax = plt.subplots()
results_accepted = data[data['accepted'] == 1]
results_rejected = data[data['accepted'] == 0]
ax.scatter(results_accepted['exam1'], results_accepted['exam2'], marker='+', c='b', s=40)
ax.scatter(resul... | 3 | 2016-09-30T14:09:50Z | 39,793,589 | <p>It depends what you want exactly:</p>
<ol>
<li><p>If you want the two figures overlayed, then you can call <a href="http://stackoverflow.com/questions/21465988/python-equivalent-to-hold-on-in-matlab"><code>hold</code></a><code>(True)</code> after the first, then plot the second, then call <code>hold(False)</code>.<... | 2 | 2016-09-30T14:14:11Z | [
"python",
"matplotlib"
] |
how to halt python program after pdb.set_trace() | 39,793,521 | <p>When debugging scripts in Python (2.7, running on Linux) I occasionally inject pdb.set_trace() (note that I'm actually using ipdb), e.g.:</p>
<pre><code>import ipdb as pdb
try:
do_something()
# I'd like to look at some local variables before running do_something_dangerous()
pdb.set_trace()
except:
p... | 2 | 2016-09-30T14:10:25Z | 39,793,564 | <p>From the <a href="https://docs.python.org/3/library/pdb.html#pdbcommand-quit" rel="nofollow">module docs</a>:</p>
<blockquote>
<p>q(uit)
Quit from the debugger. The program being executed is aborted.</p>
</blockquote>
<p>Specifically, this will cause the next debugger function that gets called to raise a <a hr... | 0 | 2016-09-30T14:12:59Z | [
"python",
"pdb",
"ipdb"
] |
how to halt python program after pdb.set_trace() | 39,793,521 | <p>When debugging scripts in Python (2.7, running on Linux) I occasionally inject pdb.set_trace() (note that I'm actually using ipdb), e.g.:</p>
<pre><code>import ipdb as pdb
try:
do_something()
# I'd like to look at some local variables before running do_something_dangerous()
pdb.set_trace()
except:
p... | 2 | 2016-09-30T14:10:25Z | 39,802,284 | <p>I found that ctrl-z to suspend the python/ipdb process, followed by 'kill %1' to terminate the process works well and is reasonably quick for me to type (with a bash alias k='kill %1'). I'm not sure if there's anything cleaner/simpler though.</p>
| 1 | 2016-10-01T01:56:45Z | [
"python",
"pdb",
"ipdb"
] |
Reverse redirect does not work but inserts data into db | 39,793,640 | <pre><code>from django.db import models
from django.core.urlresolvers import reverse
class Gallery(models.Model):
Title = models.CharField(max_length=250)
Category = models.CharField(max_length=250)
Gallery_logo = models.CharField(max_length=1000)
def get_absolute_url(self):
return reverse('p... | 0 | 2016-09-30T14:16:40Z | 39,793,730 | <p>You're passing <code>kwargs</code> to <code>reverse</code> as a <em>set</em>, when it should be a dictionary:</p>
<pre><code>kwargs={'pk': self.pk}
# ^
</code></pre>
| 2 | 2016-09-30T14:20:45Z | [
"python",
"django",
"python-2.7"
] |
Installing pyfm in virtual envornment | 39,793,646 | <p>I am not able to install the <a href="https://github.com/coreylynch/pyFM" rel="nofollow"><code>pyFM</code> module</a> in my virtualenv, only globally.</p>
<p>When I try to install it I get <code>ImportError: No module named Cython.Distutils</code>. However, when I try to <code>pip install cython</code>, I get <code... | 0 | 2016-09-30T14:17:02Z | 39,807,075 | <p>When linking gcc, you are linking it to the current folder, not <code>/usr/bin</code>. Try</p>
<p><code>ln -s /usr/bin/gcc-4.2 /usr/bin/gcc</code></p>
<p>to link into /usr/bin so your OS finds it. You can also do <code>brew install gcc</code> if you use homebrew to get the latest version.</p>
| 0 | 2016-10-01T13:16:16Z | [
"python",
"virtualenv"
] |
split a list according to size of float entries | 39,793,681 | <p>I have a list of floats where the size at each sequential index can vary.
i.e.</p>
<pre><code>float_list = [167.233, 95.6242, 181.367, 20.6354, 147.505, 41.9396, 20.3126]
</code></pre>
<p>What I am trying to do is to split the list according to the size of the floats in the indices. In particular, if the float at ... | 0 | 2016-09-30T14:18:40Z | 39,793,873 | <p>Use <code>numpy.diff</code> and <code>numpy.where</code> in order to find the indices that the items are not ordered, then use <code>numpy.split()</code> to split the array in that indices, and finally use <code>map()</code> to find the length of splitted arrays:</p>
<pre><code>In [19]: import numpy as np
In [20]: ... | 2 | 2016-09-30T14:28:00Z | [
"python"
] |
split a list according to size of float entries | 39,793,681 | <p>I have a list of floats where the size at each sequential index can vary.
i.e.</p>
<pre><code>float_list = [167.233, 95.6242, 181.367, 20.6354, 147.505, 41.9396, 20.3126]
</code></pre>
<p>What I am trying to do is to split the list according to the size of the floats in the indices. In particular, if the float at ... | 0 | 2016-09-30T14:18:40Z | 39,793,944 | <p>You can also do it like following:</p>
<pre><code>def group_list(l):
if not l:
return []
result = [0]
prev = l[0] + .1
for el in l:
if el < prev:
result[-1] += 1
else:
result.append(1)
prev = el
return result
>>> group_list([... | 0 | 2016-09-30T14:31:20Z | [
"python"
] |
split a list according to size of float entries | 39,793,681 | <p>I have a list of floats where the size at each sequential index can vary.
i.e.</p>
<pre><code>float_list = [167.233, 95.6242, 181.367, 20.6354, 147.505, 41.9396, 20.3126]
</code></pre>
<p>What I am trying to do is to split the list according to the size of the floats in the indices. In particular, if the float at ... | 0 | 2016-09-30T14:18:40Z | 39,794,031 | <p>It seems like you want to obtain a list containing the sizes of decreasing/non-increasing ranges in the list of floats.</p>
<pre><code>def size_of_decreasing_ranges(float_list):
if len(float_list) == 0:
return []
result = []
count = 1
for index, ele in enumerate(float_list):
if index... | 0 | 2016-09-30T14:35:53Z | [
"python"
] |
Looping with while function with Selenium throws error NameError: name 'neadaclick' is not defined | 39,793,700 | <p>I am trying to automate a task in my work. I already have the task and every time I click on the program I can accomplish it, however I would want to be able to do the tasks several times with one click so I want to enter a loop using while. So I started testing, this is my current code:</p>
<pre><code>from seleniu... | 0 | 2016-09-30T14:19:30Z | 39,831,172 | <p>@ElmoVanKielmo pointed out a mistake that i failed to notice, my first declaration is needaclick but on the next line i wrote neadaclick, this has been solved and its working.</p>
| 0 | 2016-10-03T12:04:38Z | [
"python",
"python-3.x",
"selenium-chromedriver"
] |
Custom rendering of foreign field in form in django template | 39,793,748 | <p>In my modelform I have a foreign key, I cannot figure out how to change the appearance of this field in template. I can change the text by changing</p>
<pre><code>__unicode__
</code></pre>
<p>of the model, but how would I make it bold, for example?</p>
<p>in <strong>models.py</strong> I tried the following but f... | 0 | 2016-09-30T14:21:28Z | 39,793,881 | <p>Django 1.9 has a <code>format_html</code> function that might be what you are looking for. From <a href="https://docs.djangoproject.com/en/1.9/ref/utils/#django.utils.html.format_html" rel="nofollow">the Docs</a>:</p>
<blockquote>
<p><code>format_html(format_string, *args, **kwargs)</code></p>
<p>This is sim... | 0 | 2016-09-30T14:28:34Z | [
"python",
"django",
"django-forms"
] |
Issues accessing Tkinter Radio Button CTRL var | 39,793,857 | <p>I am having trouble getting the value of the selected radio button. Currently when I use the <code>.get()</code> function on my varible that the radio buttons use it returns "" nothing. If I use the message box without the <code>.get()</code> function then it returns <code>PY_VAR</code>x where x is the specific inst... | 0 | 2016-09-30T14:27:07Z | 39,794,491 | <p>The problem is related to the fact that you are creating more than one root window. You need to change your code so that you create exactly one instance of <code>Tk</code> for the life of your program. Widgets and variables in one root cannot be shared with widgets and variables from another root window. </p>
<p>I... | 1 | 2016-09-30T14:58:59Z | [
"python",
"python-3.x",
"variables",
"tkinter",
"radio-button"
] |
Understanding net_surgery in caffe | 39,793,953 | <p>I'm following the <a href="http://nbviewer.jupyter.org/github/BVLC/caffe/blob/master/examples/net_surgery.ipynb" rel="nofollow">net_surgery.ipynb</a> example of caffe which explains how to modify the weights of a saved <code>.caffemodel</code>. However since I'm quite new to python I can't understand some of the syn... | 1 | 2016-09-30T14:32:07Z | 39,870,756 | <p>The line you are struggling with:</p>
<pre><code>conv_params = {pr: (net_full_conv.params[pr][0].data, net_full_conv.params[pr][1].data) for pr in params_full_conv}
</code></pre>
<p>defines a dictionary <code>conv_params</code> with keys <code>'fc6-conv'</code>, <code>'fc7-conv'</code> and <code>'fc8-conv'</code>... | 1 | 2016-10-05T09:50:55Z | [
"python",
"neural-network",
"deep-learning",
"caffe",
"pycaffe"
] |
How to check the shape of multiple arrays contained in a list? | 39,793,994 | <p>I got a list containing multiple arrays, and I wrote the following codes try to see shape[0] of these arrays,</p>
<pre><code>for i in xrange(len(list)):
k = list[i].shape[0]
print k
</code></pre>
<p>the outputs were correct, but I want to <strong>check</strong> these shape[0], that is, if they are the same... | 0 | 2016-09-30T14:34:12Z | 39,794,043 | <pre><code>all(x.shape[0]==list[0].shape[0] for x in list)
</code></pre>
| 5 | 2016-09-30T14:36:42Z | [
"python",
"arrays",
"numpy"
] |
How to check the shape of multiple arrays contained in a list? | 39,793,994 | <p>I got a list containing multiple arrays, and I wrote the following codes try to see shape[0] of these arrays,</p>
<pre><code>for i in xrange(len(list)):
k = list[i].shape[0]
print k
</code></pre>
<p>the outputs were correct, but I want to <strong>check</strong> these shape[0], that is, if they are the same... | 0 | 2016-09-30T14:34:12Z | 39,794,075 | <p>You can use a <code>set</code> comprehension to create a set of unique shapes then check if the length of the set is more than 1:</p>
<pre><code>shapes = {arr.shape[0] for arr in my_list}
if len(shapes) > 1:
# return None
</code></pre>
<p>Or as a better way try to apply a numpy function on your array, if th... | 2 | 2016-09-30T14:38:15Z | [
"python",
"arrays",
"numpy"
] |
pandas: create single size & sum columns after group by multiple columns | 39,794,016 | <p>I have a dataframe where I am doing groupby on 3 columns and aggregating the sum and size of the numerical columns. After running the code </p>
<pre><code>df = pd.DataFrame.groupby(['year','cntry', 'state']).agg(['size','sum'])
</code></pre>
<p>I am getting something like below:</p>
<p><a href="http://i.stack.img... | 3 | 2016-09-30T14:35:26Z | 39,796,429 | <p><strong><em>Setup</em></strong> </p>
<pre><code>d1 = pd.DataFrame(dict(
year=np.random.choice((2014, 2015, 2016), 100),
cntry=['United States' for _ in range(100)],
State=np.random.choice(states, 100),
Col1=np.random.randint(0, 20, 100),
Col2=np.random.randint(0, 20, 100),
... | 5 | 2016-09-30T16:53:31Z | [
"python",
"pandas"
] |
pandas: create single size & sum columns after group by multiple columns | 39,794,016 | <p>I have a dataframe where I am doing groupby on 3 columns and aggregating the sum and size of the numerical columns. After running the code </p>
<pre><code>df = pd.DataFrame.groupby(['year','cntry', 'state']).agg(['size','sum'])
</code></pre>
<p>I am getting something like below:</p>
<p><a href="http://i.stack.img... | 3 | 2016-09-30T14:35:26Z | 39,796,737 | <p>piRSquared beat me to it but if you must do it this way and want to keep the alignment with columns and sum or size underneath you could reindex the columns to remove the size value and then add in a new column to contain the size value.</p>
<p>For example:</p>
<pre><code>group = df.groupby(['year', 'cntry','state... | 2 | 2016-09-30T17:14:48Z | [
"python",
"pandas"
] |
Specifying Readonly access for Django.db connection object | 39,794,123 | <p>I have a series of integration-level tests that are being run as a management command in my Django project. These tests are verifying the integrity of a large amount of weather data ingested from external sources into my database. Because I have such a large amount of data, I really have to test against my productio... | 2 | 2016-09-30T14:41:21Z | 39,794,212 | <p>If you add a serializer for you model, you could specialized in the serializer that is working in readonly mode</p>
<pre><code>class AccountSerializer(serializers.ModelSerializer):
class Meta:
model = Account
fields = ('id', 'account_name', 'users', 'created')
read_only_fields = ('accoun... | 0 | 2016-09-30T14:45:40Z | [
"python",
"django",
"django-testing",
"django-database",
"django-postgresql"
] |
Specifying Readonly access for Django.db connection object | 39,794,123 | <p>I have a series of integration-level tests that are being run as a management command in my Django project. These tests are verifying the integrity of a large amount of weather data ingested from external sources into my database. Because I have such a large amount of data, I really have to test against my productio... | 2 | 2016-09-30T14:41:21Z | 39,794,285 | <p>Man, once again, I should read the docs more carefully before I post questions here. I can define a readonly connection to my production database in the settings file, and then straight from the <a href="https://docs.djangoproject.com/en/1.10/topics/db/sql/" rel="nofollow">docs</a>:</p>
<p>If you are using more tha... | 1 | 2016-09-30T14:49:05Z | [
"python",
"django",
"django-testing",
"django-database",
"django-postgresql"
] |
Python lxml - retrieved elements nodes aren't removed | 39,794,161 | <p>I have an xml doxument I want to remove any line of xml that contains</p>
<pre><code>number="0"
</code></pre>
<p>This is a sample</p>
<pre><code> <race id="219729" number="2" nomnumber="8" division="0" name="NEWGATE BREEDERS' PLATE" mediumname="BRDRS PLTE" shortname="BRDRS PLTE" stage="Acceptances" distance="... | 1 | 2016-09-30T14:43:22Z | 39,794,574 | <p>I cannot reproduce it, here is the processing code completely based on yours:</p>
<pre><code>from lxml import etree
with open("input.xml", 'rb') as input_file, open("output.xml", 'wb') as output_file:
tree = etree.parse(input_file)
root = tree.getroot()
for nom in root.iter("nomination"):
if no... | 1 | 2016-09-30T15:02:48Z | [
"python"
] |
In python how can you select the integer that closest to 0? | 39,794,193 | <p>list [1,2,3,4,5,6]</p>
<p>How would you write a line or lines of code that could sort through the list and find the value closest to 0?</p>
| -4 | 2016-09-30T14:45:00Z | 39,794,229 | <p>If you don't care about negative numbers use <a href="https://docs.python.org/2/library/functions.html#min" rel="nofollow">min</a>:</p>
<pre><code>>>> arr = [1, 2, 3, 4, 5]
>>> min(arr)
1
</code></pre>
| 2 | 2016-09-30T14:46:25Z | [
"python",
"for-loop"
] |
Python logging setLevel() not taking effect | 39,794,194 | <p>I have a python program that utilizes multiprocessing to increase efficiency, and a function that creates a logger for each process. The logger function looks like this:</p>
<pre><code>import logging
import os
def create_logger(app_name):
"""Create a logging interface"""
# create a logger
if logging in... | 1 | 2016-09-30T14:45:02Z | 39,794,595 | <p>Here is an easy way to create a logger object:</p>
<pre><code>import logging
import os
def create_logger(app_name):
"""Create a logging interface"""
logging_level = os.getenv('logging', logging.INFO)
logging.basicConfig(
level=logging_level,
format='%(asctime)s - %(name)s - %(levelname)... | 1 | 2016-09-30T15:03:54Z | [
"python",
"logging",
"python-multiprocessing"
] |
Python filling string column "forward" and groupby attaching groupby result to dataframe | 39,794,206 | <p>I have a dataframe looking generated by:</p>
<pre><code>df = pd.DataFrame([[100, ' tes t ', 3], [100, np.nan, 2], [101, ' test1', 3 ], [101,' ', 4]])
</code></pre>
<p>It looks like</p>
<pre><code> 0 1 2
0 100 tes t 3
1 100 NaN 2
2 101 test1 3
3 101 ... | 2 | 2016-09-30T14:45:25Z | 39,795,135 | <p>IIUC, you could use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.strip.html" rel="nofollow"><code>str.strip</code></a> and then check if the stripped string is empty.
Then, perform <code>groupby</code> operations and filling the <code>Nans</code> by the method <code>ffill</code> a... | 2 | 2016-09-30T15:34:19Z | [
"python",
"pandas"
] |
Can't change a variable using a function Python | 39,794,225 | <p>I'm playing with functions in Python and i though I could do the JOptionPane from Java using the Tkinter... I'm running Python 3.x but I'm having a little trouble</p>
<pre><code>from tkinter import *
def showMessageDialog(text):
text = text
janela = Tk()
janela.geometry("400x100")
janela["bg"] = "g... | 0 | 2016-09-30T14:46:18Z | 39,794,484 | <p>The call to mainloop does not stop until all tkinter Windows close. Therefore your function hangs when you call <code>janela.mainloop()</code>. Instead, it's best practice to call mainloop in the main thread (at the bottom of your script), and use callbacks to process input. For example, once your message dialog box... | 0 | 2016-09-30T14:58:47Z | [
"python",
"function",
"tkinter"
] |
Precise nth root | 39,794,338 | <p>I'm looking for Python Nth root function/algorithm but before you post: NO INTEGER ROOT, HELL!<br>
Where could I obtain at least a guide how to program <strong>Nth root function that produces precise <code>float</code>/<code>Decimal</code></strong>?<br>
Such function that <strong>doesn't return <code>1</code> nor <c... | 2 | 2016-09-30T14:51:33Z | 39,794,435 | <p>You mean something like that:</p>
<pre><code>>>> 125**(1/9.0)
1.7099759466766968
</code></pre>
<p>Something else that might interest you is <a href="https://pythonhosted.org/bigfloat/" rel="nofollow">bigfloat</a> module (haven't used personally just know it exists :) - actually had problem installing it i... | 1 | 2016-09-30T14:56:01Z | [
"python",
"algorithm",
"floating-point",
"precision",
"nth-root"
] |
Precise nth root | 39,794,338 | <p>I'm looking for Python Nth root function/algorithm but before you post: NO INTEGER ROOT, HELL!<br>
Where could I obtain at least a guide how to program <strong>Nth root function that produces precise <code>float</code>/<code>Decimal</code></strong>?<br>
Such function that <strong>doesn't return <code>1</code> nor <c... | 2 | 2016-09-30T14:51:33Z | 39,794,437 | <p>It's the function <code>pow</code> of <code>math</code> module.</p>
<pre><code>import math
math.pow(4, 0.5)
</code></pre>
<p>will return the square root of 4, which is <code>2.0</code>.</p>
<p>For <code>root(125, 1756482845)</code>, what you need to do is</p>
<pre><code>math.pow(125, 1.0 / 1756482845)
</code></... | 0 | 2016-09-30T14:56:05Z | [
"python",
"algorithm",
"floating-point",
"precision",
"nth-root"
] |
Precise nth root | 39,794,338 | <p>I'm looking for Python Nth root function/algorithm but before you post: NO INTEGER ROOT, HELL!<br>
Where could I obtain at least a guide how to program <strong>Nth root function that produces precise <code>float</code>/<code>Decimal</code></strong>?<br>
Such function that <strong>doesn't return <code>1</code> nor <c... | 2 | 2016-09-30T14:51:33Z | 39,795,201 | <p>I would try the <a href="https://pypi.python.org/pypi/gmpy2" rel="nofollow">gmpy2</a> library.</p>
<pre><code>>>> import gmpy2
>>> gmpy2.root(125,3)
mpfr('5.0')
>>>
</code></pre>
<p><code>gmpy2</code> uses the <a href="http://www.mpfr.org/" rel="nofollow">MPFR</a> library to perform cor... | 4 | 2016-09-30T15:38:34Z | [
"python",
"algorithm",
"floating-point",
"precision",
"nth-root"
] |
Precise nth root | 39,794,338 | <p>I'm looking for Python Nth root function/algorithm but before you post: NO INTEGER ROOT, HELL!<br>
Where could I obtain at least a guide how to program <strong>Nth root function that produces precise <code>float</code>/<code>Decimal</code></strong>?<br>
Such function that <strong>doesn't return <code>1</code> nor <c... | 2 | 2016-09-30T14:51:33Z | 39,802,349 | <p>You can do a binary search on the answer. If you want to find the X that is equal to the kth root of N, you can do a binary search on X testing for each step of the binary search whether X^k equals N +- some small constant to avoid precision issues.</p>
<p>Here is the code:</p>
<pre><code>import math
N,K = map(fl... | 2 | 2016-10-01T02:10:39Z | [
"python",
"algorithm",
"floating-point",
"precision",
"nth-root"
] |
Precise nth root | 39,794,338 | <p>I'm looking for Python Nth root function/algorithm but before you post: NO INTEGER ROOT, HELL!<br>
Where could I obtain at least a guide how to program <strong>Nth root function that produces precise <code>float</code>/<code>Decimal</code></strong>?<br>
Such function that <strong>doesn't return <code>1</code> nor <c... | 2 | 2016-09-30T14:51:33Z | 39,822,888 | <p>In Squeak Smalltalk, there is a <code>nthRoot:</code> message that answers the exact <code>Integer</code> result if ever the Integer receiver is exact nth power of some whole number. However, if the solution is an algebraic root, then the implementation does not fallback to a naive <code>n**(1/exp)</code>; the metho... | 1 | 2016-10-02T23:48:59Z | [
"python",
"algorithm",
"floating-point",
"precision",
"nth-root"
] |
Hadoop Streaming simple job fails error python | 39,794,372 | <p>I'm new to hadoop and mapreduce, I'm trying to write a mapreduce that counts the top 10 count words of a word count txt file.</p>
<p>My txt file 'q2_result.txt' looks like:</p>
<pre><code>yourself 268
yourselves 73
yoursnot 1
youst 1
youth 270
youthat 1
youthful 31
youths 9
youtli 1... | 0 | 2016-09-30T14:53:00Z | 39,800,438 | <p>I know, "file not found error" means something completely different from "file cannot be executed", in this case the problem is that the file cannot be executed.</p>
<p>In Reducer.py:</p>
<p>Wrong:</p>
<pre><code>#!usr/bin/env/ python
</code></pre>
<p>Correct:</p>
<pre><code>#!/usr/bin/env python
</code></pre>
| 0 | 2016-09-30T21:37:46Z | [
"java",
"python",
"hadoop",
"mapreduce",
"streaming"
] |
Subprocess terminating when Python exits when using disown in i3 | 39,794,457 | <p>I currently have the following setup:</p>
<p>in i3 config:</p>
<pre><code>bindsym $mod+d exec xfce4-terminal --title="Supermenu" -e "path/to/supermenu"
for_window [title="Supermenu"] floating enable
</code></pre>
<p>The script it executes is a Python script executable (using a shebang and chmod +x), that has this... | 0 | 2016-09-30T14:57:23Z | 39,808,750 | <p>You aren't redirecting standard input. I'm guessing it gets an EOF when <code>xfce4-terminal</code> closes.</p>
| 1 | 2016-10-01T16:08:40Z | [
"python",
"linux",
"process"
] |
Python argparse does not parse images with wildcard | 39,794,501 | <p>I use this library <a href="https://github.com/cmusatyalab/openface" rel="nofollow">https://github.com/cmusatyalab/openface</a> for image comparison. </p>
<p>I have downloaded Docker container with preinstalled environment. </p>
<p>I start the container and I'm accessing this file:
<a href="https://github.com/cmu... | 0 | 2016-09-30T14:59:28Z | 39,794,606 | <p>Neither python nor <code>argparse</code> do <em>any</em> wildcard expansion on the <code>argv</code> list passed in from the parent process. Instead, this is handled by the shell.</p>
<p>It'll depend on the shell wether or not your style of expansion is even supported. Evidently, the shell that <code>shell_exec()</... | 2 | 2016-09-30T15:04:26Z | [
"php",
"python",
"django",
"python-2.7"
] |
Cannot successfully redirect stdout from Popen to temp file | 39,794,541 | <p>The title says it all, really. Currently running Python 2.7.8, using <code>subprocess32</code>. Minimum reproducing snippet, copied directly from the REPL:</p>
<pre><code>Python 2.7.8 (default, Aug 14 2014, 13:26:38)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" f... | 2 | 2016-09-30T15:01:27Z | 39,794,799 | <p>The file is properly written to, but your <code>tfil.read()</code> command will start reading at the point where the last write happened, so it will return nothing. You need to call <code>tfil.seek(0)</code> first.</p>
| 2 | 2016-09-30T15:14:17Z | [
"python",
"subprocess",
"io-redirection",
"temporary-files"
] |
How should I escape commas in Active Directory filters? | 39,794,550 | <p>I'm using python-ldap to query Active Directory</p>
<p>I have this DN </p>
<pre><code>CN=Whalen\, Sean,OU=Users,OU=Users and Groups,DC=example,DC=net
</code></pre>
<p>That works fine as a base in a query, but if I try to use it in a search filter like this</p>
<pre><code>(&(objectClass=group)(memberof:1.2.84... | 0 | 2016-09-30T15:02:02Z | 39,805,523 | <p>The LDAP filter specification assigns special meaning to the following characters <code>* ( ) \ NUL</code> that should be escaped with the backslash escape character followed by the two character ASCII hexadecimal representation of the character (<a href="https://tools.ietf.org/search/rfc2254#page-5" rel="nofollow">... | 1 | 2016-10-01T10:29:26Z | [
"python",
"active-directory",
"ldap",
"ldap-query",
"python-ldap"
] |
Pywinauto: unable to bring window to foreground | 39,794,729 | <p>Working on the Python-powered automation tool.</p>
<p>Imagine there is a pool of apps running:</p>
<pre><code>APPS_POOL = ['Chrome', 'SomeApp', 'Foo']
</code></pre>
<p>The script runs in the loop (every second) and needs to switch randomly between them:</p>
<pre><code># Init App object
app = application.Applicat... | 2 | 2016-09-30T15:10:32Z | 39,800,690 | <p>I think the <code>SetFocus</code> is a bit buggy. At least on my machine I get an error: <code>error: (87, 'AttachThreadInput', 'The parameter is incorrect.')</code>. So maybe you can play with Minimize/Restore. Notice that this approach is not bullet proof either.</p>
<pre><code>import random
import time
from pywi... | 2 | 2016-09-30T22:02:02Z | [
"python",
"pywinauto"
] |
Pandas DataFrame.values conversion error or feature? | 39,794,731 | <p>I having some difficulty with some "behind the scenes" conversions that <code>pandas</code> (v. 0.18.0) seems to be performing for the <code>values</code> property of a <code>DataFrame</code>.
I have a data set that looks something like the following: </p>
<pre><code>data = [(1473897600000000, 9.9166, 1.8621, 15), ... | 2 | 2016-09-30T15:10:39Z | 39,795,869 | <p>At the risk of sounding stupid, I'll answer my own question, should have dug a little deeper in the first place. The root of the problem is the conversion to the lowest common denominator type, quoting from the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.values.html#pandas.DataFr... | 1 | 2016-09-30T16:16:33Z | [
"python",
"pandas"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.