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 |
|---|---|---|---|---|---|---|---|---|---|
Sum Each Column of CSV file | 37,602,344 | <p>I have a large CSV file with 32 column headers. I'd like to sum up each column and the result be 32 individual summations of each column header. I have access to both python and powershell. Any help would be appreciated.</p>
<p>The furthest I got was this site: <a href="http://stackoverflow.com/questions/33542977/p... | 0 | 2016-06-02T21:22:19Z | 37,602,813 | <pre><code>import pandas as pd
pd.read_csv(r'my_path_to_file/my_file.csv', sep=';').sum().values
</code></pre>
<p>Pandas is definitly the way to go . these two lines of code will print out the sum of the columns. if you are on windows use a '\' for specifying your path. I assume your csv file uses a semicolon as a sep... | 0 | 2016-06-02T21:56:31Z | [
"python",
"powershell"
] |
Sum Each Column of CSV file | 37,602,344 | <p>I have a large CSV file with 32 column headers. I'd like to sum up each column and the result be 32 individual summations of each column header. I have access to both python and powershell. Any help would be appreciated.</p>
<p>The furthest I got was this site: <a href="http://stackoverflow.com/questions/33542977/p... | 0 | 2016-06-02T21:22:19Z | 37,603,070 | <pre><code>import csv
with open('yourBigFile.csv', 'rb') as f:
spreadsheet=csv.reader(f) #you may need some options
#depending on the format of the file
header=None
for row in spreadsheet:
if header is None:
header=row
mySums=[0]*len(row) # ini... | 0 | 2016-06-02T22:19:21Z | [
"python",
"powershell"
] |
OpenCV: 4 camera Bird's Eye view? | 37,602,383 | <p>I am having quite a lot of trouble thinking of how to make a four camera bird's eye view like that <a href="https://i.ytimg.com/vi/uh5aUJ4TMyc/maxresdefault.jpg" rel="nofollow">seen in luxury cars</a>. Here is the original that I will be using as an example for this question...<a href="http://i.stack.imgur.com/1DiNe... | 7 | 2016-06-02T21:24:53Z | 37,756,999 | <p>To implement the transform, you need to refer to the <code>getPerspectiveTransform</code> function. It takes: </p>
<ul>
<li>src: Coordinates of quadrangle vertices in the source image.</li>
<li><p>dst: Coordinates of the corresponding quadrangle vertices in the destination image.</p>
<p>I think that it's not an e... | 2 | 2016-06-10T20:51:55Z | [
"python",
"opencv",
"computer-vision",
"perspectivecamera"
] |
"GenerateMatrix" equivalent command in SymPy | 37,602,446 | <p>In Maple there is a command "GenerateMatrix" that will take a collection of linear equations and generate a symbolic matrix A and symbolic vector b in "Ax=b" where "x" is a vector of variables specified by the command. The help page can be found here if this isn't clear:</p>
<p><a href="http://www.maplesoft.com/sup... | 2 | 2016-06-02T21:29:16Z | 37,609,304 | <p>The SymPy analog is <a href="http://docs.sympy.org/latest/modules/solvers/solveset.html#linear-eq-to-matrix" rel="nofollow">linear_eq_to_matrix</a>. Usage example:</p>
<pre><code>from sympy import *
variables = symbols('x y z')
equations = [3*x-z+2, y-3*z-5, x+y-z]
A, b = linear_eq_to_matrix(equations, variables)
l... | 1 | 2016-06-03T08:13:41Z | [
"python",
"sympy",
"maple",
"maxima"
] |
python for loop modify line in file skips every second line | 37,602,585 | <p>i have a Problem with my for loop and i allready read in the Documentation why python have problems by modifing the iterator. Now I have following code:</p>
<pre><code>f = open('test.txt', 'r')
g = open('test1.txt', 'w')
for line in f:
k = ast.literal_eval(f.readline())
p = Polygon(k)
c = ... | 0 | 2016-06-02T21:40:22Z | 37,602,628 | <p>You don't need to <code>readline</code> in your loop, just use the current line. <code>readline</code> calls a <code>next</code> on your file iterator, so the current line in the loop is skipped.</p>
<pre><code>k = ast.literal_eval(line)
</code></pre>
| 2 | 2016-06-02T21:42:53Z | [
"python",
"file",
"for-loop",
"duplicates"
] |
python for loop modify line in file skips every second line | 37,602,585 | <p>i have a Problem with my for loop and i allready read in the Documentation why python have problems by modifing the iterator. Now I have following code:</p>
<pre><code>f = open('test.txt', 'r')
g = open('test1.txt', 'w')
for line in f:
k = ast.literal_eval(f.readline())
p = Polygon(k)
c = ... | 0 | 2016-06-02T21:40:22Z | 37,602,632 | <p>You have <code>for line in f</code>, which iterates through the lines in the file. Then in your very next line of code you have <code>f.readline()</code> which reads the <em>next</em> line in the file. Thus, you are skipping every other line in the file.</p>
<p>Just use <code>line</code> rather than <code>f.readlin... | 2 | 2016-06-02T21:43:06Z | [
"python",
"file",
"for-loop",
"duplicates"
] |
python for loop modify line in file skips every second line | 37,602,585 | <p>i have a Problem with my for loop and i allready read in the Documentation why python have problems by modifing the iterator. Now I have following code:</p>
<pre><code>f = open('test.txt', 'r')
g = open('test1.txt', 'w')
for line in f:
k = ast.literal_eval(f.readline())
p = Polygon(k)
c = ... | 0 | 2016-06-02T21:40:22Z | 37,602,646 | <p>Don't use both <code>for line in file</code> and <code>file.readline()</code>. Your "missing" lines were in the variable <code>line</code>, which you didn't use for anything.</p>
<pre><code>with open('test.txt') as f, open('test1.txt', 'w') as g:
for line in f:
k = ast.literal_eval(line)
p = Pol... | 2 | 2016-06-02T21:44:01Z | [
"python",
"file",
"for-loop",
"duplicates"
] |
python for loop modify line in file skips every second line | 37,602,585 | <p>i have a Problem with my for loop and i allready read in the Documentation why python have problems by modifing the iterator. Now I have following code:</p>
<pre><code>f = open('test.txt', 'r')
g = open('test1.txt', 'w')
for line in f:
k = ast.literal_eval(f.readline())
p = Polygon(k)
c = ... | 0 | 2016-06-02T21:40:22Z | 37,602,653 | <p>Your problem is right at the start:</p>
<pre><code>for line in f:
k = ast.literal_eval(f.readline())
</code></pre>
<p>The <strong>for</strong> statement reads a line from generator <strong>f</strong> and stores it in the variable <strong>line</strong>, which you never use again. Your first statement in the lo... | 1 | 2016-06-02T21:44:35Z | [
"python",
"file",
"for-loop",
"duplicates"
] |
python for loop modify line in file skips every second line | 37,602,585 | <p>i have a Problem with my for loop and i allready read in the Documentation why python have problems by modifing the iterator. Now I have following code:</p>
<pre><code>f = open('test.txt', 'r')
g = open('test1.txt', 'w')
for line in f:
k = ast.literal_eval(f.readline())
p = Polygon(k)
c = ... | 0 | 2016-06-02T21:40:22Z | 37,602,658 | <p>Your code has <code>for line in f:</code> and <code>f.readline()</code>. So you're reading two lines per loop.</p>
<p>Use <code>k = ast.literal_eval(line)</code>.</p>
| 0 | 2016-06-02T21:44:56Z | [
"python",
"file",
"for-loop",
"duplicates"
] |
Is Google Cloud Datastore a Column Oriented NoSQL database? | 37,602,604 | <p>From my understanding BigTable is a Column Oriented NoSQL database. Although Google Cloud Datastore is built on top of Googleâs BigTable infrastructure I have yet to see documentation that expressively says that Datastore itself is a Column Oriented database. The fact that names reserved by the Python API are enfo... | 0 | 2016-06-02T21:41:09Z | 37,609,672 | <p>Strictly speaking, Google Cloud Datastore is distributed multi-dimensional sorted map. As you mentioned it is based on Google BigTable, however, it is only a foundation.</p>
<p>From high level point of view Datastore actually consists of three layers.</p>
<p><strong>BigTable</strong></p>
<p>This is a necessary ba... | 0 | 2016-06-03T08:35:21Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
What Scipy modules are actually calls to Numpy ones? | 37,602,680 | <p>I am confused by the fact that some modules in Scipy are not actually part of the library but are rather calls to modules in Numpy.</p>
<p>One example for all is <code>linalg</code>:</p>
<pre><code>import scipy
scipy.linalg
</code></pre>
<p>this gives </p>
<blockquote>
<p>AttributeError: 'module' object has no... | 4 | 2016-06-02T21:46:49Z | 37,602,744 | <blockquote>
<p>the right way to call it from Scipy is</p>
<pre><code>from scipy import linalg
scipy.linalg
</code></pre>
<p>which must be a handle for</p>
<pre><code>numpy.linalg
</code></pre>
</blockquote>
<p>Nope! They're totally different modules. Also, it'd be either <code>import scipy.linalg</code> and ... | 3 | 2016-06-02T21:50:21Z | [
"python",
"numpy",
"scipy"
] |
Python - write to javascript api | 37,602,829 | <p>I have a .js file with the following content:</p>
<pre><code>function get_test1_data() {
return [
['2016-02-12','32765','87917',-55152,'2016-04-27','10:52'],
['2016-02-19','32765','87917',-55152,'2016-04-27','10:52'],
['2016-02-26','32765','87917',-55152,'2016-04-27','10:52'],
['2016-03-04','32765','87917',-55152... | 1 | 2016-06-02T21:57:48Z | 37,603,306 | <p>Although your implementation does not look like a very good idea for a javascript file, you may want to look at <code>file.seek</code> with the file opened in binary mode to allow seeking from the end of the file with a negative offset. But finding the correct offset in bytes is hard enough.</p>
<p>I'll suggest you... | 0 | 2016-06-02T22:43:36Z | [
"python"
] |
Python - write to javascript api | 37,602,829 | <p>I have a .js file with the following content:</p>
<pre><code>function get_test1_data() {
return [
['2016-02-12','32765','87917',-55152,'2016-04-27','10:52'],
['2016-02-19','32765','87917',-55152,'2016-04-27','10:52'],
['2016-02-26','32765','87917',-55152,'2016-04-27','10:52'],
['2016-03-04','32765','87917',-55152... | 1 | 2016-06-02T21:57:48Z | 37,604,281 | <p>As I mentioned in the comments, you probably should be using JSON for this. It's really not good practice to embed large amounts of data into program source. But anyway...</p>
<p>As Moses Koledoye suggests, the way to do this (without using JSON) is to read the lines of your .js file into a list, modify that list, ... | 0 | 2016-06-03T00:45:13Z | [
"python"
] |
Adding units to heatmap annotation in Seaborn | 37,602,885 | <p>I am trying to show a table of percentages as a heatmap in Seaborn:</p>
<pre><code>sns.heatmap(S, annot=True, fmt=".1f", linewidths=1.0, square=1)
</code></pre>
<p>However, I'd like the percent sign to appear after each number in the heatmap annotations. The <code>fmt</code> flag only seems to accept number format... | 2 | 2016-06-02T22:02:00Z | 37,603,535 | <p>You have to iterate over all text values of a heatmap and add % sign:</p>
<pre><code>import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from matplotlib.ticker import FuncFormatter
sns.set()
fig, ax0 = plt.subplots(1,1)
data = np.array([[10.01,20.20],[-0.23,0.],[23.1049,-100.000000]])
ax = sns... | 2 | 2016-06-02T23:08:25Z | [
"python",
"matplotlib",
"seaborn"
] |
What is the most efficient way to partition an input file in pyspark? | 37,602,886 | <p>I am reading in an input file using PySpark and I'm wondering what's the best way to repartition the input data so it can be spread out evenly across the Mesos cluster.</p>
<p>Currently, I'm doing:</p>
<pre><code>rdd = sc.textFile('filename').repartition(10)
</code></pre>
<p>I was looking at <code>sparkContext</c... | 0 | 2016-06-02T22:02:11Z | 37,617,374 | <p>There are two main differences between these methods:</p>
<ul>
<li><code>repartition</code> shuffles the data after loading while using <code>minPartitions</code> doesn't</li>
<li><code>repartition</code> results in exact number of partitions while <code>minPartitions</code> provides only a lower bound (see <a href... | 1 | 2016-06-03T14:44:55Z | [
"python",
"apache-spark",
"pyspark"
] |
Is boto3.Bucket.upload_file blocking or non-blocking? | 37,603,148 | <p>Is <a href="http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Bucket.upload_file" rel="nofollow">boto3.Bucket.upload_file</a> blocking or non-blocking?</p>
<p>i.e. if I were to run the following</p>
<pre><code>bucket = session.Bucket(bucket_name)
bucket.upload_file(Key=s3_key, Filename=source_pat... | 2 | 2016-06-02T22:27:47Z | 37,603,277 | <p>The fact <code>upload_file()</code> uses S3Transfer indicates the call is non-blocking. You need to track the progress (S3Transfer's APIs) and delete the file after making sure the transfer is complete.</p>
| 1 | 2016-06-02T22:41:01Z | [
"python",
"amazon-web-services",
"amazon-s3",
"boto3"
] |
Is boto3.Bucket.upload_file blocking or non-blocking? | 37,603,148 | <p>Is <a href="http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Bucket.upload_file" rel="nofollow">boto3.Bucket.upload_file</a> blocking or non-blocking?</p>
<p>i.e. if I were to run the following</p>
<pre><code>bucket = session.Bucket(bucket_name)
bucket.upload_file(Key=s3_key, Filename=source_pat... | 2 | 2016-06-02T22:27:47Z | 37,611,509 | <p>Whether blocking or unblocking, you SHOULD NOT rely on the API alone when things went bad. You MUST add exception handling if the upload fail in the middle for any reason(e.g. admin decide to restart the router when you doing the upload). </p>
<pre><code>bucket = session.Bucket(bucket_name)
try :
bucket.upload_fi... | 0 | 2016-06-03T10:07:54Z | [
"python",
"amazon-web-services",
"amazon-s3",
"boto3"
] |
Is boto3.Bucket.upload_file blocking or non-blocking? | 37,603,148 | <p>Is <a href="http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Bucket.upload_file" rel="nofollow">boto3.Bucket.upload_file</a> blocking or non-blocking?</p>
<p>i.e. if I were to run the following</p>
<pre><code>bucket = session.Bucket(bucket_name)
bucket.upload_file(Key=s3_key, Filename=source_pat... | 2 | 2016-06-02T22:27:47Z | 37,619,499 | <p>The current boto3 <code>upload_file</code> is blocking. As mootmoot said, you should definitely implement some error handling to be safe if you delete the file.</p>
| 1 | 2016-06-03T16:37:57Z | [
"python",
"amazon-web-services",
"amazon-s3",
"boto3"
] |
Replacing python list elements with key | 37,603,164 | <p>I have a list of non-unique strings:</p>
<pre><code>list = ["a", "b", "c", "a", "a", "d", "b"]
</code></pre>
<p>I would like to replace each element with an integer key which uniquely identifies each string:</p>
<pre><code>list = [0, 1, 2, 0, 0, 3, 1]
</code></pre>
<p>The number does not matter, as long as it is... | 4 | 2016-06-02T22:28:57Z | 37,603,248 | <pre><code>>>> lst = ["a", "b", "c", "a", "a", "d", "b"]
>>> nums = [ord(x) for x in lst]
>>> print(nums)
[97, 98, 99, 97, 97, 100, 98]
</code></pre>
| 3 | 2016-06-02T22:37:33Z | [
"python",
"list",
"key"
] |
Replacing python list elements with key | 37,603,164 | <p>I have a list of non-unique strings:</p>
<pre><code>list = ["a", "b", "c", "a", "a", "d", "b"]
</code></pre>
<p>I would like to replace each element with an integer key which uniquely identifies each string:</p>
<pre><code>list = [0, 1, 2, 0, 0, 3, 1]
</code></pre>
<p>The number does not matter, as long as it is... | 4 | 2016-06-02T22:28:57Z | 37,603,259 | <p>If you are not picky, then use the hash function: it returns an integer. For strings that are the same, it returns the same hash:</p>
<pre><code>li = ["a", "b", "c", "a", "a", "d", "b"]
li = map(hash, li) # Turn list of strings into list of ints
li = [hash(item) for item in li] # Same as above
</cod... | 2 | 2016-06-02T22:38:48Z | [
"python",
"list",
"key"
] |
Replacing python list elements with key | 37,603,164 | <p>I have a list of non-unique strings:</p>
<pre><code>list = ["a", "b", "c", "a", "a", "d", "b"]
</code></pre>
<p>I would like to replace each element with an integer key which uniquely identifies each string:</p>
<pre><code>list = [0, 1, 2, 0, 0, 3, 1]
</code></pre>
<p>The number does not matter, as long as it is... | 4 | 2016-06-02T22:28:57Z | 37,603,292 | <p>This will guarantee uniqueness and that the id's are contiguous starting from <code>0</code>:</p>
<pre><code>id_s = {c: i for i, c in enumerate(set(list))}
li = [id_s[c] for c in list]
</code></pre>
<p>On a different note, you should not use <code>'list'</code> as variable name because it will shadow the built-in ... | 9 | 2016-06-02T22:42:06Z | [
"python",
"list",
"key"
] |
Replacing python list elements with key | 37,603,164 | <p>I have a list of non-unique strings:</p>
<pre><code>list = ["a", "b", "c", "a", "a", "d", "b"]
</code></pre>
<p>I would like to replace each element with an integer key which uniquely identifies each string:</p>
<pre><code>list = [0, 1, 2, 0, 0, 3, 1]
</code></pre>
<p>The number does not matter, as long as it is... | 4 | 2016-06-02T22:28:57Z | 37,603,489 | <p>Here's a single pass solution with <a href="https://docs.python.org/2/library/collections.html#collections.defaultdict" rel="nofollow">defaultdict</a>:</p>
<pre><code>from collections import defaultdict
seen = defaultdict()
seen.default_factory = lambda: len(seen) # you could instead bind to seen.__len__
In [11]:... | 4 | 2016-06-02T23:03:05Z | [
"python",
"list",
"key"
] |
Replacing python list elements with key | 37,603,164 | <p>I have a list of non-unique strings:</p>
<pre><code>list = ["a", "b", "c", "a", "a", "d", "b"]
</code></pre>
<p>I would like to replace each element with an integer key which uniquely identifies each string:</p>
<pre><code>list = [0, 1, 2, 0, 0, 3, 1]
</code></pre>
<p>The number does not matter, as long as it is... | 4 | 2016-06-02T22:28:57Z | 37,603,690 | <p>A functional approach:</p>
<pre><code>l = ["a", "b", "c", "a", "a", "d", "b", "abc", "def", "abc"]
from itertools import count
from operator import itemgetter
mapped = itemgetter(*l)(dict(zip(l, count())))
</code></pre>
<p>You could also use a simple generator function:</p>
<pre><code>from itertools import count... | 0 | 2016-06-02T23:25:58Z | [
"python",
"list",
"key"
] |
Using additional fields of a through m2m on template | 37,603,176 | <p>My <code>models.py</code>:</p>
<pre><code>class Profile(models.Model):
name = models.CharField(max_length=32)
gender = models.CharField(max_length=1, choices=(('m', 'male'),
('f', 'female')), default='m')
addresses = models.ManyToManyField(City,
related_name='user_city', through='User_C... | 0 | 2016-06-02T22:29:59Z | 37,603,962 | <p><code>addresses</code> is a <code>ManyToManyField</code>, so how is <code>{{ user.addresses.phone }}</code> (or the likes thereof) supposed to know which of the addresses (<code>City</code> instances) is meant there to look up <code>phone</code>.</p>
<p>Just loop directly over <code>User_City</code> objects, not <... | 2 | 2016-06-02T23:58:39Z | [
"python",
"html",
"django",
"m2m"
] |
Can a QtCore Signal be set to the current class? | 37,603,339 | <p>I am attempting to use a <code>QtCore.Signal</code> to send a new instance of a class to the object's parent.
What I am attempting to do is as follows, but fails with:</p>
<blockquote>
<p><code>NameError: name 'myClass' is not defined</code></p>
</blockquote>
<pre><code>class myClass(QtGui.QMainWindow):
mySi... | 2 | 2016-06-02T22:46:51Z | 37,605,795 | <p>The typical way to do this would be to define the signal as</p>
<pre><code>mySignal = QtCore.Signal(object)
</code></pre>
<p>since you wish to emit an instance of a class.</p>
<p><strong>EDIT</strong>: If you wish to work around the circular dependency, you can place your signal in a wrapper class. E.g.</p>
<pre... | 2 | 2016-06-03T04:13:16Z | [
"python",
"python-2.7",
"pyside",
"qt4.8"
] |
Obtain a function expression that is product between two other functions expressions | 37,603,390 | <p>I have a function that calculates <code>x^2</code> and another that calculates <code>x^3</code>. I wanna obtain the expression of <code>x**5</code> by multiplying the two other functions.</p>
<p>Here is what I've been trying to do:</p>
<pre><code>def pol1(x):
f=x**2
return f
def pol2(x):
f=x**3
ret... | 0 | 2016-06-02T22:52:11Z | 37,603,638 | <p>Your code is just missing to pass the parameter <code>x</code> for the <code>f</code> and <code>g</code> in the <code>new</code> function.</p>
<pre><code>def pol1(x):
f=x**2
return f
def pol2(x):
f=x**3
return f
def new(f,g,x):
n=f(x)*g(x)
return n
neo=new(pol1, pol2, 2)
print(neo)
</code><... | 0 | 2016-06-02T23:20:55Z | [
"python",
"function",
"multiplying"
] |
Obtain a function expression that is product between two other functions expressions | 37,603,390 | <p>I have a function that calculates <code>x^2</code> and another that calculates <code>x^3</code>. I wanna obtain the expression of <code>x**5</code> by multiplying the two other functions.</p>
<p>Here is what I've been trying to do:</p>
<pre><code>def pol1(x):
f=x**2
return f
def pol2(x):
f=x**3
ret... | 0 | 2016-06-02T22:52:11Z | 37,603,640 | <p>You're passing the <code>x</code> parameter unused. And function objects are not to be multiplied in python.</p>
<p>Here is what you want:</p>
<pre><code>def new(f, g, x):
n = f(x) * g(x)
return n
neo = new(pol1, pol2, 2)
print(neo)
# 32
</code></pre>
| 0 | 2016-06-02T23:21:07Z | [
"python",
"function",
"multiplying"
] |
Obtain a function expression that is product between two other functions expressions | 37,603,390 | <p>I have a function that calculates <code>x^2</code> and another that calculates <code>x^3</code>. I wanna obtain the expression of <code>x**5</code> by multiplying the two other functions.</p>
<p>Here is what I've been trying to do:</p>
<pre><code>def pol1(x):
f=x**2
return f
def pol2(x):
f=x**3
ret... | 0 | 2016-06-02T22:52:11Z | 37,603,652 | <p>You're passing in x to the new function, so why don't you just utilize it when assigning n:</p>
<pre><code>def new(f,g,x):
n=f(x)*g(x)
return n
</code></pre>
| 1 | 2016-06-02T23:22:32Z | [
"python",
"function",
"multiplying"
] |
In a Django ModelForm, I want to display a CharField as a Select Field with defined choices | 37,603,394 | <p>I am trying to follow the documentation on the Django site to overwrite the default formatting of the form. I have tried a number of solutions (all commented out and they give me an error). The non-commented section, works but just renders a select box without any choices. Could you please let me know what I am d... | 0 | 2016-06-02T22:52:50Z | 37,603,463 | <p>The choices options takes an iterable. A list or tuple of 2-tuples, which would be of the format:</p>
<pre><code>(value, value to display)
</code></pre>
<p>So, you need to iterate over your values and create this format.</p>
| 1 | 2016-06-02T23:00:31Z | [
"python",
"django",
"django-forms"
] |
list out of range error - plotting from .dat file | 37,603,425 | <p>I am trying to plot a .dat file using python. However I get an error message. I'll call it 'file.dat', it's of the following form</p>
<pre><code>1 2
3 4
5 6
7 8
</code></pre>
<p>Using my code below:</p>
<pre><code>import matplotlib.pyplot as plt
with open("file.dat") as f:
data = f.read()
data = data.spli... | 0 | 2016-06-02T22:56:15Z | 37,603,525 | <p>insert</p>
<pre><code>print data
</code></pre>
<p>Just before you find the x and y lists. You have a newline at the end of the file, so <strong>data</strong> has an empty string at the end:</p>
<pre><code>['1 2', '3 4', '5 6', '7 8', '']
</code></pre>
<p>Instead, add a slice to "massage" <strong>data</strong>, ... | 2 | 2016-06-02T23:07:02Z | [
"python",
"matplotlib",
"plot",
"text-files"
] |
Calculating near gps coordinates in django | 37,603,454 | <p>I have got a model in django that stores a list of gps coordinates for location. What i need to do is implement a search. I take the coordinates of the user from his device. What i need to do is show him locations nearby, and also the functionalituy that he can filter his search radius.</p>
<p>What we initially had... | 1 | 2016-06-02T22:59:18Z | 37,604,551 | <p>Once you have <a href="https://docs.djangoproject.com/en/1.9/ref/contrib/gis/install/" rel="nofollow">installed Geodjango</a> you can convert your models to spatial<br>
models by changing your import to</p>
<pre><code>from django.contrib.gis.db import models
</code></pre>
<p>As you rightly guessed your Location mo... | 1 | 2016-06-03T01:26:50Z | [
"python",
"django"
] |
Numpy: Set array element to another array | 37,603,491 | <p>I'm trying to set an element of a Numpy array to be another Numpy array. I'm not sure on how to do this since every time I try I get <code>ValueError: setting an array element with a sequence.</code></p>
<p>I know this is possible with Python's <code>list</code> since I can append the new array to list and it will ... | 1 | 2016-06-02T23:03:26Z | 37,603,566 | <p>Numpy arrays cannot be filled with arbitrary types. They are more like the arrays of C or Java. To create a two dimensional array, feed a two dimensional list into the np.array function. For example, </p>
<pre><code>x = np.array([[0,0,0],[0,0,0],[0,0,0]])
</code></pre>
<p>creates a 3x3 two dimensional array filled... | 1 | 2016-06-02T23:11:48Z | [
"python",
"arrays",
"numpy"
] |
Numpy: Set array element to another array | 37,603,491 | <p>I'm trying to set an element of a Numpy array to be another Numpy array. I'm not sure on how to do this since every time I try I get <code>ValueError: setting an array element with a sequence.</code></p>
<p>I know this is possible with Python's <code>list</code> since I can append the new array to list and it will ... | 1 | 2016-06-02T23:03:26Z | 37,603,646 | <p>I think you're looking for <a href="http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.concatenate.html" rel="nofollow"><code>numpy.concatenate</code></a>:</p>
<pre><code>In [11]: np.concatenate((a, b, c))
Out[11]:
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
... | 1 | 2016-06-02T23:21:54Z | [
"python",
"arrays",
"numpy"
] |
Numpy: Set array element to another array | 37,603,491 | <p>I'm trying to set an element of a Numpy array to be another Numpy array. I'm not sure on how to do this since every time I try I get <code>ValueError: setting an array element with a sequence.</code></p>
<p>I know this is possible with Python's <code>list</code> since I can append the new array to list and it will ... | 1 | 2016-06-02T23:03:26Z | 37,604,226 | <p>It would work if</p>
<pre><code>finalArray = np.zeros(3, dtype=object)
finalArray[0] = a
</code></pre>
<p>Then <code>finalArray</code> takes object points like a list. </p>
<p>But I hesitate suggesting this because this feature is being abused or misused by beginners.</p>
<p><a href="http://stackoverflow.com/a/... | 0 | 2016-06-03T00:37:10Z | [
"python",
"arrays",
"numpy"
] |
Sympy Solve For All Solutions On Domain | 37,603,511 | <p>For periodic functions, how do I tell <code>sympy</code> I want ALL the solutions on some domain?</p>
<p>Example:</p>
<pre><code>import sympy
import sympy.parsing.sympy_parser
SympyExpression = sympy.parsing.sympy_parser.parse_expr( 'sin(pi* x)*sin(pi*y)' )
Variables = [sympy.Symbol('x'),sympy.Symbol('y') ]
Zeros... | 3 | 2016-06-02T23:05:26Z | 37,617,439 | <p>I don't think that can be done directly, but there is a work-around (at least for this particular function you posted):</p>
<pre><code>import sympy
x = sympy.Symbol('x')
y = sympy.Symbol('y')
n = sympy.Symbol('n')
sol = sympy.solve('sin(pi*(x + n))*sin(pi*(y+n))', [x, y])
</code></pre>
<p>which gives:</p>
<pre>... | 1 | 2016-06-03T14:47:28Z | [
"python",
"sympy",
"solver"
] |
How do I read a SQLite file stored in Object Storage from a Python notebook in Spark as a Service all on Bluemix? | 37,603,581 | <p>I have a SQLite file in an Object Storage instance on IBM's Bluemix. I want to access that file from a Python notebook in Spark as a Service. Right now, the following code does not work:</p>
<pre><code>df = sqlContext.read.format('jdbc').\
options(url='jdbc:sqlite:swift://container.spark/db.sqlite',\
db... | 2 | 2016-06-02T23:14:14Z | 37,621,757 | <p>You are missing one parameter to specify in option that is which driver to look for.</p>
<pre><code>df = sqlContext.read.format('jdbc').\
options(url='jdbc:sqlite:Chinook_Sqlite.sqlite',\
dbtable='employee',driver='org.sqlite.JDBC').load()
</code></pre>
<p>Add <code>driver='org.sqlite.JDBC'</code> and yo... | 1 | 2016-06-03T19:06:47Z | [
"python",
"sqlite",
"apache-spark",
"ibm-bluemix",
"object-storage"
] |
are there any limitations on the number of locks a python program can create? | 37,603,610 | <p>I have a single-threaded python3 program that I'm trying to convert to use many threads. I have a tree-like data structure that gets read from and written to. Potentially many threads will want to read and write at the same time.</p>
<p>One obvious way about this is to have a single lock for the entire data struc... | 5 | 2016-06-02T23:18:18Z | 37,603,825 | <h3>Premature Optimization</h3>
<p>This is a classic example of premature optimization. Without knowing how much time your threads spend blocking, presumably waiting for other writes to happen, it's unclear what you have to gain from creating the added complexity of managing thousands of locks. </p>
<h3>The Global ... | 2 | 2016-06-02T23:42:15Z | [
"python",
"multithreading"
] |
are there any limitations on the number of locks a python program can create? | 37,603,610 | <p>I have a single-threaded python3 program that I'm trying to convert to use many threads. I have a tree-like data structure that gets read from and written to. Potentially many threads will want to read and write at the same time.</p>
<p>One obvious way about this is to have a single lock for the entire data struc... | 5 | 2016-06-02T23:18:18Z | 37,604,436 | <p>Echoing Brendan Abel: avoid premature optimization. If I have 16 cores, there can be no more than 16 parallel accesses (reads/writes). There's no point having a kajillion locks hanging around. A limited number of locks will suffice. The question then becomes: if I have random access on a set of resources, what i... | 1 | 2016-06-03T01:09:35Z | [
"python",
"multithreading"
] |
How to handle many users in slack app for in Python? How to use the multiple tokens? | 37,603,634 | <p>I am making a slack bot. I have been using python slackclient library to develop the bot. Its working great with one team. I am using Flask Webframework.</p>
<p>As many people add the app to slack via "Add to Slack" button, I get their <strong><em>bot_access_token</em></strong>.</p>
<p>Now
<strong>how should I run... | 0 | 2016-06-02T23:20:33Z | 37,603,922 | <p>If you're using the real-time API, you'll need one WebSocket open per team. Yes, you would typically use a loop to establish these connections. Depending on the way <code>slackclient</code> works, you might need to start each in a separate thread or process.</p>
<p><strong>EDIT</strong>: As mentioned in the comment... | 1 | 2016-06-02T23:53:32Z | [
"python",
"oauth",
"slack-api",
"slack"
] |
How to handle many users in slack app for in Python? How to use the multiple tokens? | 37,603,634 | <p>I am making a slack bot. I have been using python slackclient library to develop the bot. Its working great with one team. I am using Flask Webframework.</p>
<p>As many people add the app to slack via "Add to Slack" button, I get their <strong><em>bot_access_token</em></strong>.</p>
<p>Now
<strong>how should I run... | 0 | 2016-06-02T23:20:33Z | 37,614,761 | <p>You do indeed need to</p>
<ol>
<li>Store each team token. <strong>Please remember to encrypt it</strong></li>
<li>When a team installs your app, create a new RTM connection. When your app/server restarts, loop across all your teams, open a RTM connection for each of them</li>
<li>each connection will receive events... | 0 | 2016-06-03T12:45:26Z | [
"python",
"oauth",
"slack-api",
"slack"
] |
Python Segmentation fault in numpy multiarray | 37,603,635 | <p>I am trying to run a python script in a virtual environment. It returns a Segmentation Fault and when running gdb, it returns the segmentation fault inside numpy multiarray.so</p>
<pre><code>Program received signal SIGSEGV, Segmentation fault.
0x00007ffff347be20 in PyArray_API () from /home/jeremy/anaconda/envs/cop... | 0 | 2016-06-02T23:20:36Z | 39,756,742 | <p>I had a similar issue which turned out to be a conflict between scipy and another package (pybel). Same message from gdb as you had. Importing numpy before anything else solved the problem for me.</p>
| 0 | 2016-09-28T20:06:57Z | [
"python",
"numpy",
"virtualenv"
] |
How to read each line of a file to a separate list to process them individually | 37,603,738 | <p>There are already several questions to similar topics, but none of them solves mine.</p>
<p>I've written multiple lists to a text file. There, every line represents a list. Looks like this:</p>
<pre><code>1: ['4bf58dd8d48988d1ce941735', '4bf58dd8d48988d157941735', '4bf58dd8d48988d1f1931735', etc.]
2: ['4bf58dd8d48... | 0 | 2016-06-02T23:31:06Z | 37,603,785 | <p>You should use a proper serializer like JSON to write your lists. Then, you can use the same to deserialize them:</p>
<pre><code>import json
# when writing the lists
f.write(json.dumps(temp_list) + "\n")
# when reading
lst = json.loads(line)
</code></pre>
| 0 | 2016-06-02T23:37:31Z | [
"python",
"list",
"file"
] |
How to read each line of a file to a separate list to process them individually | 37,603,738 | <p>There are already several questions to similar topics, but none of them solves mine.</p>
<p>I've written multiple lists to a text file. There, every line represents a list. Looks like this:</p>
<pre><code>1: ['4bf58dd8d48988d1ce941735', '4bf58dd8d48988d157941735', '4bf58dd8d48988d1f1931735', etc.]
2: ['4bf58dd8d48... | 0 | 2016-06-02T23:31:06Z | 37,603,857 | <ol>
<li>Use <a href="https://docs.python.org/2/library/pickle.html" rel="nofollow">Pickle</a> or <a href="https://docs.python.org/2/library/json.html" rel="nofollow">JSON</a> to serialize/deserialize your data</li>
<li>If you absolutely need to do your way, you can use <a href="https://docs.python.org/2/library/ast.ht... | 0 | 2016-06-02T23:45:58Z | [
"python",
"list",
"file"
] |
How to convert sort using cmp from python 2 to python 3? | 37,603,757 | <p>I'm trying to convert this code which is written in python 2 to python 3</p>
<pre><code>nums = ["30", "31"]
num.sort(cmp=lambda x, y: cmp(y + x, x + y))
</code></pre>
<p>Not sure how to do that in python 3 since cmp is removed (I believed)</p>
<p>The result should be <code>["31", "30"]</code> instead of <code>["3... | 5 | 2016-06-02T23:32:58Z | 37,603,846 | <p>This is one of the rare cases where a comparator is much cleaner than a key function. I'd actually just reimplement <code>cmp</code>:</p>
<pre><code>try:
cmp
except NameError:
def cmp(x, y):
if x < y:
return -1
elif x > y:
return 1
else:
retur... | 8 | 2016-06-02T23:43:58Z | [
"python",
"sorting",
"python2to3"
] |
How to keep dates as index and inner join keys in multiple excel files | 37,603,762 | <p>I am trying to concatenate different excel files - same columns, each file comes from a different category - using the date (as an index) from the first file.</p>
<p>The excel file format is basically a Date column (19.09.2014) and other columns with float. </p>
<pre><code>import pandas as pd
import matplotlib.pyp... | 0 | 2016-06-02T23:33:29Z | 37,603,923 | <p>Without having an example dataframes, it is hard to determine the issue but I presume that the <code>pd.concat</code> operation overrides the index.</p>
<p>You should usually read all of the files in and then concatenate them, that's faster and more efficient (described in pd.concat <a href="http://pandas.pydata.or... | 0 | 2016-06-02T23:53:35Z | [
"python",
"pandas",
"dataframe"
] |
How to keep dates as index and inner join keys in multiple excel files | 37,603,762 | <p>I am trying to concatenate different excel files - same columns, each file comes from a different category - using the date (as an index) from the first file.</p>
<p>The excel file format is basically a Date column (19.09.2014) and other columns with float. </p>
<pre><code>import pandas as pd
import matplotlib.pyp... | 0 | 2016-06-02T23:33:29Z | 37,604,068 | <p>I'd use <code>pd.concat</code> on a list compression where I apply the file parsing via a function and pass the <code>keys</code> parameter to get the proper column headings.</p>
<pre><code>def get_df(ct):
fn = str(ct) + ".xls"
kw = dict(parse_dates=True,
format='%dd%.mm.%YYYY',
... | 0 | 2016-06-03T00:15:10Z | [
"python",
"pandas",
"dataframe"
] |
2-D Matrix: Finding and deleting columns that are subsets of other columns | 37,603,764 | <p>I have a problem where I want to identify and remove columns in a logic matrix that are subsets of other columns. i.e. [1, 0, 1] is a subset of [1, 1, 1]; but neither of [1, 1, 0] and [0, 1, 1] are subsets of each other. I wrote out a quick piece of code that identifies the columns that are subsets, which does (n^2-... | 4 | 2016-06-02T23:33:54Z | 37,606,172 | <p>Define subset as <code>col1.dot(col1) == col1.dot(col2)</code> if and only if <code>col1</code> is a subset of <code>col2</code></p>
<p>Define <code>col1</code> and <code>col2</code> are the same if and only if <code>col1</code> is subset of <code>col2</code> and vice versa.</p>
<p>I split the work into two. Firs... | 0 | 2016-06-03T04:51:20Z | [
"python",
"numpy",
"matrix",
"scipy",
"vectorization"
] |
2-D Matrix: Finding and deleting columns that are subsets of other columns | 37,603,764 | <p>I have a problem where I want to identify and remove columns in a logic matrix that are subsets of other columns. i.e. [1, 0, 1] is a subset of [1, 1, 1]; but neither of [1, 1, 0] and [0, 1, 1] are subsets of each other. I wrote out a quick piece of code that identifies the columns that are subsets, which does (n^2-... | 4 | 2016-06-02T23:33:54Z | 37,606,181 | <p>Here's another approach using <a href="http://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html" rel="nofollow"><code>NumPy broadcasting</code></a> -</p>
<pre><code>A[:,~((np.triu(((A[:,:,None] - A[:,None,:])>=0).all(0),1)).any(0))]
</code></pre>
<p>A detailed commented explanation is listed below -... | 0 | 2016-06-03T04:51:59Z | [
"python",
"numpy",
"matrix",
"scipy",
"vectorization"
] |
2-D Matrix: Finding and deleting columns that are subsets of other columns | 37,603,764 | <p>I have a problem where I want to identify and remove columns in a logic matrix that are subsets of other columns. i.e. [1, 0, 1] is a subset of [1, 1, 1]; but neither of [1, 1, 0] and [0, 1, 1] are subsets of each other. I wrote out a quick piece of code that identifies the columns that are subsets, which does (n^2-... | 4 | 2016-06-02T23:33:54Z | 37,636,266 | <p>Since the <code>A</code> matrices I'm actually dealing with are 5000x5000 and sparse with about 4% density, I decided to try a sparse matrix approach combined with Python's "set" objects. Overall it's much faster than my original solution, but I feel like my process of going from matrix <code>A</code> to list of set... | 0 | 2016-06-05T00:19:39Z | [
"python",
"numpy",
"matrix",
"scipy",
"vectorization"
] |
Unable to import view in Django project | 37,603,849 | <p>I am starting a very basic Django project (using PyCharm IDE in the process). This is what I do initially.</p>
<ol>
<li><code>cd</code> into my <code>workspace</code> directory and run <code>django-admin.py startproject mysite</code>. This creates the following directory structure:</li>
</ol>
<p><a href="http://i.... | 1 | 2016-06-02T23:44:24Z | 37,603,873 | <p>Can you please us the code of the file where you want to import the view?
I think you have missed to create a <code>__init__.py</code> inside the customviews folder?</p>
| 1 | 2016-06-02T23:47:37Z | [
"python",
"django",
"pycharm",
"pythonpath"
] |
Unable to import view in Django project | 37,603,849 | <p>I am starting a very basic Django project (using PyCharm IDE in the process). This is what I do initially.</p>
<ol>
<li><code>cd</code> into my <code>workspace</code> directory and run <code>django-admin.py startproject mysite</code>. This creates the following directory structure:</li>
</ol>
<p><a href="http://i.... | 1 | 2016-06-02T23:44:24Z | 37,608,061 | <p>You shouldn't add that directory to the path.</p>
<p>You have two issues: firstly, as adriansq points out, you need an empty <code>__init__.py</code> in that directory. And secondly, it is in the wrong place; it should be one level higher, directly under the outer <code>mysite</code> directory.</p>
| 1 | 2016-06-03T07:07:59Z | [
"python",
"django",
"pycharm",
"pythonpath"
] |
Distributed dask matrix from flat text file | 37,603,989 | <p>I'm attempting to read a flat text file (tab-delimited) representation of a matrix into a <code>dask</code> array, using <code>distributed</code> to distributed the chunks of the array across the cluster.</p>
<p><em>(Aside: this is not unlike PySpark's <a href="http://spark.apache.org/docs/latest/api/python/pyspark... | 1 | 2016-06-03T00:03:02Z | 37,604,199 | <p>There are a few steps here:</p>
<h3>Break apart a single file into many files with read_text</h3>
<p>By default <code>read_text</code> treats each file as a single streaming partition. If you prefer to break data into pieces then use the <code>blocksize=</code> keyword argument</p>
<pre><code>futures = db.read_t... | 0 | 2016-06-03T00:32:44Z | [
"python",
"apache-spark",
"dataframe",
"pyspark",
"dask"
] |
OpenCV cap.get(cv2.CAP_PROP_FRAME_COUNT) returning -1 | 37,604,008 | <p>I recently setup opencv 3.0 for python on my ubuntu pc using the following tutorial <a href="http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/" rel="nofollow">http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/</a></p>
<p>So I ran the following cod... | 0 | 2016-06-03T00:05:54Z | 37,830,789 | <p>The problem was with the opencv build (as it also occured in c++). I ended up re-building my opencv and everything worked fine after</p>
| 0 | 2016-06-15T09:02:20Z | [
"python",
"opencv",
"image-processing",
"computer-vision"
] |
Creating a Python Dictionary using Keys with Wildcards | 37,604,019 | <p>I am looking to create <strong>a Python dictionary with keys that contain wildcards</strong>. Is this possible?</p>
<p>Currently, I am creating a program that finds the point values associated with a particular type of scoring. For example, what is the point value associated with a <code>'Four-of-a-Kind'</code> or ... | 0 | 2016-06-03T00:07:42Z | 38,620,913 | <p>First, you should have the values separately (and without the parenthesis):</p>
<pre><code>type = 'Three-of-a-Kind'
mode = '1'
</code></pre>
<p>(This can either be done by parsing or storing the data differently.)</p>
<p>After that, you can look at the problem a little differently. </p>
<p>You are looking to get... | 1 | 2016-07-27T18:47:15Z | [
"python",
"python-2.7",
"dictionary",
"wildcard"
] |
Creating a Python Dictionary using Keys with Wildcards | 37,604,019 | <p>I am looking to create <strong>a Python dictionary with keys that contain wildcards</strong>. Is this possible?</p>
<p>Currently, I am creating a program that finds the point values associated with a particular type of scoring. For example, what is the point value associated with a <code>'Four-of-a-Kind'</code> or ... | 0 | 2016-06-03T00:07:42Z | 38,621,474 | <p>A possible function you can use is the following based on the inputs you have provided:</p>
<pre><code>def hand_score(hand, cards=None):
fixed = {
"Four-of-a-Kind": 1000,
"Four-of-a-Kind-w/Pair": 1500,
"Five-of-a-Kind": 2000,
"Six-of-a-Kind": 3000,
"Three-Pairs": 1500,
... | 1 | 2016-07-27T19:20:20Z | [
"python",
"python-2.7",
"dictionary",
"wildcard"
] |
import: command not found with python 3.5 | 37,604,045 | <p>I'm looking some clues or solutions to fix below weird problem.</p>
<pre><code>[sc-d02-087-017:~]$ cat mytest.py
#!/build/toolchain/lin64/python-3.5.1/bin/python
import platform, sys
print(platform.system())
sys.exit(0)
</code></pre>
<p>I'm trying to run my test program as shell executable, but shell not recognizi... | 1 | 2016-06-03T00:12:13Z | 37,653,016 | <p>I have no idea why you used <code>./</code>.</p>
<p>Execute Python script like this:</p>
<pre><code>python mytest.py # and then just hit enter.
</code></pre>
<p>If that doesn't work then just let me know.</p>
| -2 | 2016-06-06T08:41:56Z | [
"python",
"linux",
"python-3.x",
"centos"
] |
import: command not found with python 3.5 | 37,604,045 | <p>I'm looking some clues or solutions to fix below weird problem.</p>
<pre><code>[sc-d02-087-017:~]$ cat mytest.py
#!/build/toolchain/lin64/python-3.5.1/bin/python
import platform, sys
print(platform.system())
sys.exit(0)
</code></pre>
<p>I'm trying to run my test program as shell executable, but shell not recognizi... | 1 | 2016-06-03T00:12:13Z | 37,653,625 | <p>I get a wide range of similar issues by saving the python 3 file with different encodings from UTF8 (e.g. UTF16), so I suspect that's your problem. Try making sure it is saved with a "normal" encoding (UTF8) and perhaps that will fix it!</p>
<p>If it does, I suspect that the "problem" is that python3 has much bette... | 0 | 2016-06-06T09:15:52Z | [
"python",
"linux",
"python-3.x",
"centos"
] |
import: command not found with python 3.5 | 37,604,045 | <p>I'm looking some clues or solutions to fix below weird problem.</p>
<pre><code>[sc-d02-087-017:~]$ cat mytest.py
#!/build/toolchain/lin64/python-3.5.1/bin/python
import platform, sys
print(platform.system())
sys.exit(0)
</code></pre>
<p>I'm trying to run my test program as shell executable, but shell not recognizi... | 1 | 2016-06-03T00:12:13Z | 37,667,147 | <p>Your shebang line may be <a href="http://stackoverflow.com/questions/10813538/shebang-line-limit-in-bash-and-linux-kernel">too long</a> for your system. Try shortening it. For example, create a symlink to <code>/build/toolchain/lin64/python-3.5.1</code>:</p>
<pre><code>ln -s /build/toolchain/lin64/python-3.5.1 /tmp... | 0 | 2016-06-06T21:27:20Z | [
"python",
"linux",
"python-3.x",
"centos"
] |
import: command not found with python 3.5 | 37,604,045 | <p>I'm looking some clues or solutions to fix below weird problem.</p>
<pre><code>[sc-d02-087-017:~]$ cat mytest.py
#!/build/toolchain/lin64/python-3.5.1/bin/python
import platform, sys
print(platform.system())
sys.exit(0)
</code></pre>
<p>I'm trying to run my test program as shell executable, but shell not recognizi... | 1 | 2016-06-03T00:12:13Z | 37,690,250 | <p>try to add that path to you profile /build/toolchain/lin64/python-3.5.1/bin/python & execution path file either .bash_profile or depening on the shell you use, then switch user to the same login or execute the profile like . ./.bash_profile and try agin with your script....hope it helps</p>
| 0 | 2016-06-07T22:10:31Z | [
"python",
"linux",
"python-3.x",
"centos"
] |
import: command not found with python 3.5 | 37,604,045 | <p>I'm looking some clues or solutions to fix below weird problem.</p>
<pre><code>[sc-d02-087-017:~]$ cat mytest.py
#!/build/toolchain/lin64/python-3.5.1/bin/python
import platform, sys
print(platform.system())
sys.exit(0)
</code></pre>
<p>I'm trying to run my test program as shell executable, but shell not recognizi... | 1 | 2016-06-03T00:12:13Z | 37,727,392 | <p>As you are aware, the error message is because your python script is being interpreted directly as a shell script.</p>
<p>Usually this happens when you have no "shebang" line (<code>!#/path/to/python/executable</code>). As this does not apply, I looked a bit harder and noticed that your <code>xxd</code> output doe... | 2 | 2016-06-09T13:29:10Z | [
"python",
"linux",
"python-3.x",
"centos"
] |
numerical precision of cross product in numpy | 37,604,060 | <p>I am experiencing what I think is weird behavior using cross product in <code>numpy</code> with somewhat large values.</p>
<p>E.g., the following seems correct:</p>
<pre><code>r = 1e15
a = array([1, 2, 3]) * r;
b = array([-1, 2, 1]) * r;
c = cross(a / norm(a), b / norm(b));
print(dot(c, a)) # outputs 0.0
</code... | 0 | 2016-06-03T00:14:29Z | 37,604,459 | <p>You are seeing round-off error. By default, <code>array()</code> returns an object with <code>dtype=float64</code>. As you make <code>r</code> bigger and bigger, you're running out of mantissa spaces to represent the array products exactly. Here's a way to test this:</p>
<pre><code>def testcross(r, dt):
a = ar... | 2 | 2016-06-03T01:13:27Z | [
"python",
"numpy",
"precision",
"cross-product"
] |
How can I replace a character with a number in a string? | 37,604,076 | <p>How do I place a variable in <code>.replace()</code> in python. For example:</p>
<pre><code>x = 2
example = example2.replace("1", x)
</code></pre>
<p>I think its clear what I am looking for, I just have no clue how to do it.</p>
| 0 | 2016-06-03T00:16:23Z | 37,636,682 | <p>My comments are based on Python v2.7:</p>
<p>In your code, "x" is assigned a integer value, they do not have replace method.
Instead, if "x" had carried normal string, then replace is available and this is how it works:</p>
<pre><code>var2 = "palindrome syndrome"
print var2.replace("drome", "pal", 2)
</code></pre>... | 0 | 2016-06-05T01:47:11Z | [
"python"
] |
Difficulty making a Morse to English translator via Python 3 | 37,604,086 | <p>So Here is what I have for my English-morse translator (which works fine):</p>
<pre><code>english = {'.-': 'a', '-...': 'b', '-.-.': 'c',
'-..': 'd', '.': 'e', '..-.': 'f',
'--.': 'g', '....': 'h', '..': 'i',
'.---': 'j', '-.-': 'k', '.-..': 'l',
'--': 'm', '-.': 'n', ... | 2 | 2016-06-03T00:17:21Z | 37,604,145 | <p>Split the input message on spaces, then iterate over the whole Morse patterns. Iterating one character at a time only reads a single dot or single dash.</p>
<p>This should fix it:</p>
<pre><code>for i in msg.split():
print(english[i])
</code></pre>
| 2 | 2016-06-03T00:25:25Z | [
"python",
"morse-code"
] |
Difficulty making a Morse to English translator via Python 3 | 37,604,086 | <p>So Here is what I have for my English-morse translator (which works fine):</p>
<pre><code>english = {'.-': 'a', '-...': 'b', '-.-.': 'c',
'-..': 'd', '.': 'e', '..-.': 'f',
'--.': 'g', '....': 'h', '..': 'i',
'.---': 'j', '-.-': 'k', '.-..': 'l',
'--': 'm', '-.': 'n', ... | 2 | 2016-06-03T00:17:21Z | 37,604,345 | <p>You have two problems here. The first problem is that in English, your letters are one character wide, so your naive <code>for letter in message</code> approach works.</p>
<p>In Morse, however, your 'letters' are an arbitrary number of characters wide. Therefore, you need to <a href="https://en.wikipedia.org/wiki/T... | 0 | 2016-06-03T00:55:39Z | [
"python",
"morse-code"
] |
Python erro- "too many values to unpack using numpy.loadtxt" large data file | 37,604,134 | <p>I am using numpy.loadtxt to read in dates from a csv file. I am getting the error that there are too many values to unpack. This is likely true in the literal sense because there are over 46,000 rows of dates. I would like to know if there is a way to read in the data without further breaking up the file. It has bee... | 0 | 2016-06-03T00:23:50Z | 37,604,754 | <p>The error (probably) means that <code>np.loadtxt</code> is returning more than two variables.</p>
<p>You would get the same error with</p>
<pre><code>a,b = (1,2,3)
</code></pre>
<p>My suggestion: try</p>
<pre><code>print(np.loadtxt(time, delimiter=',',dtype=str, unpack=True,converters = {0: mdates.strpdate2num('... | 0 | 2016-06-03T01:56:04Z | [
"python",
"numpy"
] |
Python erro- "too many values to unpack using numpy.loadtxt" large data file | 37,604,134 | <p>I am using numpy.loadtxt to read in dates from a csv file. I am getting the error that there are too many values to unpack. This is likely true in the literal sense because there are over 46,000 rows of dates. I would like to know if there is a way to read in the data without further breaking up the file. It has bee... | 0 | 2016-06-03T00:23:50Z | 37,604,843 | <p>Instead of this: </p>
<pre><code>date, ozone = np.loadtxt(time, delimiter=',',dtype=str, unpack=True,
converters = {0: mdates.strpdate2num('%m/%d/%Y')})
</code></pre>
<p>Try using this: </p>
<pre><code>NewData = np.loadtxt(time, delimiter=',',dtype=str, unpack=True,
converters = {0: mdates.strpdate2num('... | 2 | 2016-06-03T02:06:43Z | [
"python",
"numpy"
] |
How to print an individual field that is part of "_source" using Python with elastic search? | 37,604,195 | <p>I have very few fields in ElasticSearch and want to get individual fields from <code>_source</code>. Using the example below in a Python script gets a key error:</p>
<pre><code>es = elasticsearch.Elasticsearch( [{'host': host_name}])
res = es.search(index="collections", body={"query": {"match_all": {}}, "from": 0, ... | 1 | 2016-06-03T00:31:39Z | 37,605,456 | <p>You probably should use <code>doc ["_source"]["collection"]["id"]</code> instead of
<code>doc ["_source.collection.id"]</code></p>
<p>Example:
<code>print(doc ["_id"], doc ["_type"], doc ["_source"]["collection"]["id"])</code></p>
| 1 | 2016-06-03T03:26:18Z | [
"python",
"elasticsearch"
] |
_tkinter.TclError: no display name and no $DISPLAY environment variable | 37,604,289 | <p>I am running a simple python script in the server:</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
x = np.random.randn(60)
y = np.random.randn(60)
plt.scatter(x, y, s=20)
out_png = 'path/to/store/out_file.png'
plt.savefig(out_png, dpi=150)
</code></pre>
<p>I try to use the command <code>python... | 0 | 2016-06-03T00:45:45Z | 37,605,654 | <p>Matplotlib chooses Xwindows backend by default.
You need to set matplotlib do not use Xwindows backend. </p>
<p>Add this code to your script and try again:</p>
<pre><code>import matplotlib
matplotlib.use('Agg')
</code></pre>
<p>Or add to <code>.config/matplotlib/matplotlibrc</code> line <code>backend : Agg</code... | 1 | 2016-06-03T03:56:15Z | [
"python",
"matplotlib"
] |
Python 3.5.1 Pygame Installation | 37,604,437 | <p>I am trying to install Pygame for Python 3.5.1, but it tells me to upgrade to the new version of pip. "You are currently using 7.1.2, use 8.1.2".</p>
<p>Here is a screen shot of it: <a href="http://i.stack.imgur.com/yWSYY.png" rel="nofollow"><img src="http://i.stack.imgur.com/yWSYY.png" alt="Python 3.5.1 pip"></a><... | 0 | 2016-06-03T01:09:44Z | 37,605,705 | <p>The error clearly states Access Denied.<br>
Try to run cmd/powershell as administrator.</p>
<p>The installation error is not because of pip , though you should still upgrade pip<br>
<code>python -m pip install --upgrade pip</code></p>
<p><strong>EDIT</strong></p>
<p>Pygame does not have python3.5 support yet. Che... | 1 | 2016-06-03T04:02:53Z | [
"python",
"python-3.x",
"pygame"
] |
Python 3.5.1 Pygame Installation | 37,604,437 | <p>I am trying to install Pygame for Python 3.5.1, but it tells me to upgrade to the new version of pip. "You are currently using 7.1.2, use 8.1.2".</p>
<p>Here is a screen shot of it: <a href="http://i.stack.imgur.com/yWSYY.png" rel="nofollow"><img src="http://i.stack.imgur.com/yWSYY.png" alt="Python 3.5.1 pip"></a><... | 0 | 2016-06-03T01:09:44Z | 37,619,110 | <p>Pip seems to be having a permission problem creating this directory: c:\program files (x86)\python35-32\Lib\site-packages\pygame</p>
<p>Here are some things you can try: </p>
<ol><li>Navigate to that directory and see if it already exists. If it does exist, then try deleting it.</li>
<li>Try running pip as an admi... | 0 | 2016-06-03T16:15:11Z | [
"python",
"python-3.x",
"pygame"
] |
Python 3.5.1 Pygame Installation | 37,604,437 | <p>I am trying to install Pygame for Python 3.5.1, but it tells me to upgrade to the new version of pip. "You are currently using 7.1.2, use 8.1.2".</p>
<p>Here is a screen shot of it: <a href="http://i.stack.imgur.com/yWSYY.png" rel="nofollow"><img src="http://i.stack.imgur.com/yWSYY.png" alt="Python 3.5.1 pip"></a><... | 0 | 2016-06-03T01:09:44Z | 37,782,134 | <p>It was a problem based on the admin command run program and I figures it out. </p>
| 0 | 2016-06-13T05:04:17Z | [
"python",
"python-3.x",
"pygame"
] |
select in (select ..) using ORM django | 37,604,443 | <p>How can I make a query </p>
<pre><code>select name where id in (select id from ...)
</code></pre>
<p>using Django ORM? I think I can make this using some loop for for obtain some result and another loop for, for use this result, but I think that is not practical job, is more simple make a query sql, I think that... | 1 | 2016-06-03T01:10:31Z | 37,606,445 | <p>You can traverse <code>ForeignKey</code> relations using double underscores (<code>__</code>) in Django ORM. For example, your query could be implemented as:</p>
<pre><code>payments = invoicePayments.objects.filter(invoice__store_id=3,
date__range=["2016-05-01", "2016-05-0... | 1 | 2016-06-03T05:18:09Z | [
"python",
"django"
] |
select in (select ..) using ORM django | 37,604,443 | <p>How can I make a query </p>
<pre><code>select name where id in (select id from ...)
</code></pre>
<p>using Django ORM? I think I can make this using some loop for for obtain some result and another loop for, for use this result, but I think that is not practical job, is more simple make a query sql, I think that... | 1 | 2016-06-03T01:10:31Z | 37,606,517 | <p>Your mysql raw query is a sub query.</p>
<pre><code>select name where id in (select id from ...)
</code></pre>
<p>In mysql this will usually be slower than an INNER JOIN (refer : [<a href="http://dev.mysql.com/doc/refman/5.7/en/rewriting-subqueries.html]" rel="nofollow">http://dev.mysql.com/doc/refman/5.7/en/rewr... | 1 | 2016-06-03T05:24:06Z | [
"python",
"django"
] |
Pandas - Get value as frequency in groupby | 37,604,496 | <p>Can someone help me with the (possible) groupby in pandas.</p>
<p>Here is the df:</p>
<pre><code> easy_donor v_fam count
0 donor_1_NS IGHV1 5202376
1 donor_1_NS IGHV2 1955547
2 donor_1_NS IGHV3 70426272
3 donor_1_NS IGHV4 452367
4 donor_1_NS IGHV5 4842145
5 donor_1_NS IGHV6 4901... | 1 | 2016-06-03T01:18:49Z | 37,604,665 | <p>Try:</p>
<pre><code>df.groupby('easy_donor')["count"].apply(lambda x: x / x.sum())
</code></pre>
| 4 | 2016-06-03T01:44:18Z | [
"python",
"pandas"
] |
Change Cursor when Hovering Over Part of Frame TKinter | 37,604,508 | <p>How can you make the cursor change when you hover over a certain part of a frame? I am trying to make it so there is a background image and when someone hovers over a certain part that, if clicked on, will make the frame change, the cursor will change to signal that interaction will occur if they click.</p>
<pre><c... | 0 | 2016-06-03T01:20:22Z | 37,604,578 | <p>Use <strong>cursor</strong> attrubute like this:</p>
<pre><code>YourFrame.cursor = pencil
</code></pre>
<p>See: <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/cursors.html" rel="nofollow">http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/cursors.html</a>
<a href="http://infohost.nmt.edu/tcc/help/pubs/t... | 0 | 2016-06-03T01:30:37Z | [
"python",
"binding",
"tkinter",
"cursor"
] |
Change Cursor when Hovering Over Part of Frame TKinter | 37,604,508 | <p>How can you make the cursor change when you hover over a certain part of a frame? I am trying to make it so there is a background image and when someone hovers over a certain part that, if clicked on, will make the frame change, the cursor will change to signal that interaction will occur if they click.</p>
<pre><c... | 0 | 2016-06-03T01:20:22Z | 37,604,729 | <p>To get your cursor coordinates:</p>
<pre><code>import Tkinter as tk
from Tkinter import Frame
root = tk.Tk()
frame1 = Frame(root, bg='blue',width='100px', height='100px')
frame1.pack()
def motion(event):
x, y = event.x, event.y
print('{}, {}'.format(x, y))
frame1.bind('<Motion>', motion)
root.mainl... | 2 | 2016-06-03T01:52:17Z | [
"python",
"binding",
"tkinter",
"cursor"
] |
Python 2.7.11 - ImportError: cannot import name QtWebKit - Kali Linux / Debian 8 | 37,604,532 | <p>I'm trying to launch an app dependant on QtWebKit but i'm unable to import the module. I've tried debugging by launching python and importing other modules. They all work fine (e.g. from PyQt4 import QtGui, QtCore) works without any issues, but when i run </p>
<pre><code>from PyQt4 import QtGui, QtCore, QtWebKit
</... | 0 | 2016-06-03T01:24:32Z | 37,616,466 | <p>This is an issue with the app, sparta?.
Debian Stretch which Kali Rolling is based on has <a href="https://lists.debian.org/debian-devel-announce/2015/05/msg00001.html" rel="nofollow">mothballed</a> QtWebKit in PyQt4.</p>
<p>The latest version does not contain QtWebkit.so.</p>
<p>Unfortunately the code in question... | 1 | 2016-06-03T14:03:13Z | [
"python",
"linux",
"debian",
"qtwebkit"
] |
pymysql returns error if long query is used | 37,604,573 | <p>With the following code if I use a long query then I get an error. Is there a limit on the query size that I give?</p>
<p>Sorry, but I can't share the exact query that I'm passing. If the same query is given in MySQL workbench then the data is returned correctly. Any advice would be appreciated.</p>
<p>My code:</p... | 0 | 2016-06-03T01:29:53Z | 37,604,740 | <pre><code>def sql_to_df(sql_query):
df = pd.read_sql(sql_query, connection)
connection.close()
return df
query = '''long query'''
#use pandas to pass SQL query
df = sql_to_df(query)
df.head()
</code></pre>
<p>You just need below.. </p>
<pre><code>df = pd.read_sql(query, connection)
connection.c... | 1 | 2016-06-03T01:54:24Z | [
"python",
"mysql",
"pymysql"
] |
Two Class Based View on the same url | 37,604,593 | <p>I'm using the generic DetailView to display the details of my model Ticket.
There's a boostrap modal to create comments on this ticket in the template.</p>
<p>How can I use the CreateView to display the form in the modal?</p>
<p>Is it possible to use some type of inheritance to combine DetailView with CreateView t... | 0 | 2016-06-03T01:32:35Z | 37,703,892 | <p>I found a way to solve here : <a href="https://docs.djangoproject.com/en/1.9/topics/class-based-views/mixins/#using-formmixin-with-detailview" rel="nofollow">Using FormMixin with DetailView</a></p>
<pre><code>class TicketDisplay(LoginRequiredMixin, DetailView):
model = Ticket
template_name = 'ticket_detail.... | 0 | 2016-06-08T13:27:19Z | [
"python",
"django",
"django-views"
] |
Transparency not showing in Python after I cropped it and added transparency | 37,604,615 | <p>I am trying to open an image that I added transparent corners to. I save it as a .png and when I open it in python the corners are still there but when I open the same image in preview the edges are present. I am also using Pillow for my image processing.</p>
<p>Also the image that I am trying to add rounded corner... | 0 | 2016-06-03T01:36:16Z | 37,608,234 | <p>The function as you have it should work perfectly. You can pass it something like a JPG image, but you must save the resulting file in PNG format as JPG does not support transparency. For example:</p>
<pre><code>img = Image.open('test.jpg')
img_corners = add_corners(img, 40)
img_corners.save('with_corners.png')
</c... | 1 | 2016-06-03T07:18:01Z | [
"python",
"image",
"python-imaging-library",
"pillow"
] |
Convert a list into a string and allow for a separator | 37,604,618 | <p>please be aware, im new to python:
i'm trying to create a defined function that can convert a list into a string, and allows me to put a separator in. The separator has to be ', '.
My current thought process is to add each item from a list to an empty string variable, and then I'm trying to make use of the range fun... | 0 | 2016-06-03T01:36:36Z | 37,604,636 | <pre><code>list=['asdf', '123', 'more items...']
print ', '.join([str(x) for x in list])
</code></pre>
<p>If you wanted to create your own function to convert you could do the following.</p>
<pre><code>def convert(list, sep):
n_str = ''
for index, I in enumerate(list): #enumerate(list) returns (current positi... | 0 | 2016-06-03T01:39:25Z | [
"python",
"string",
"list",
"function"
] |
Convert a list into a string and allow for a separator | 37,604,618 | <p>please be aware, im new to python:
i'm trying to create a defined function that can convert a list into a string, and allows me to put a separator in. The separator has to be ', '.
My current thought process is to add each item from a list to an empty string variable, and then I'm trying to make use of the range fun... | 0 | 2016-06-03T01:36:36Z | 37,604,655 | <p>First you need to convert the list of int to a list of string.</p>
<p>You can use list comprehension : <a href="https://docs.python.org/3/tutorial/datastructures.html" rel="nofollow">https://docs.python.org/3/tutorial/datastructures.html</a></p>
<pre><code>str_list = [str(x) for x in list1]
</code></pre>
<p>Then,... | 2 | 2016-06-03T01:42:13Z | [
"python",
"string",
"list",
"function"
] |
Convert a list into a string and allow for a separator | 37,604,618 | <p>please be aware, im new to python:
i'm trying to create a defined function that can convert a list into a string, and allows me to put a separator in. The separator has to be ', '.
My current thought process is to add each item from a list to an empty string variable, and then I'm trying to make use of the range fun... | 0 | 2016-06-03T01:36:36Z | 37,604,738 | <p>If no string methods (like <code>join</code>) are allowed, <a href="https://docs.python.org/2/library/functions.html#reduce" rel="nofollow"><code>reduce</code></a> should offer the shortest solution:</p>
<pre><code>def list2Str(lisConv, sep = ', '):
return reduce(lambda x, y: str(x) + sep + str(y), lisConv)
pr... | 0 | 2016-06-03T01:54:12Z | [
"python",
"string",
"list",
"function"
] |
convert from bash shell to python3 using subprocess.Popen() | 37,604,722 | <p>I'm struggling with converting from bash shell to python3.</p>
<p>Here's shell command that I want to convert to python:</p>
<blockquote>
<pre><code>cat $outDir/aDir/* | cut -f2 | sort -u > $outDir/outFile.txt
</code></pre>
</blockquote>
<p>I already use <code>subprocess.call()</code>and it worked but I want t... | 2 | 2016-06-03T01:51:49Z | 37,605,081 | <p>You need to pass a list of files to <code>cat</code>
So</p>
<pre><code>subprocess.Popen(['cat'], stdin=inFile, stdout=subprocess.PIPE)
</code></pre>
<p>should become</p>
<pre><code>subprocess.Popen(['cat'] + [fileList], stdout=subprocess.PIPE)
</code></pre>
<p>And consequently <code>inFile</code> should no longe... | 2 | 2016-06-03T02:36:32Z | [
"python",
"bash",
"shell",
"subprocess",
"popen"
] |
convert from bash shell to python3 using subprocess.Popen() | 37,604,722 | <p>I'm struggling with converting from bash shell to python3.</p>
<p>Here's shell command that I want to convert to python:</p>
<blockquote>
<pre><code>cat $outDir/aDir/* | cut -f2 | sort -u > $outDir/outFile.txt
</code></pre>
</blockquote>
<p>I already use <code>subprocess.call()</code>and it worked but I want t... | 2 | 2016-06-03T01:51:49Z | 37,605,479 | <p>What about just using <code>shell=True</code> and keeping the pipes?</p>
<pre><code>with open(files, 'r') as inFile, open(outFilePath, 'w') as outFile :
p = subprocess.Popen('cut -f2 | sort -u', shell=True, stdin=filePath, stdout=subprocess.PIPE)
p.communicate()
</code></pre>
<p>Or even, more simply:</p>
<pr... | 0 | 2016-06-03T03:29:33Z | [
"python",
"bash",
"shell",
"subprocess",
"popen"
] |
PHP bcmath versus Python Decimal | 37,604,725 | <p>I am using PHP's <code>bcmath</code> library to perform operations on fixed-point numbers. I was expecting to get the same behaviour of Python's <code>Decimal</code> class but I was quite surprised to find the following behaviour instead:</p>
<pre><code>// PHP:
$a = bcdiv('15.80', '483.49870000', 26);
$b = bcmul($a... | 4 | 2016-06-03T01:51:59Z | 37,623,899 | <p>After some experimentation, I figured it out. This is an issue with rounding vs. truncation. Python, by default, uses <code>ROUND_HALF_EVEN</code> rounding, while PHP simply truncates at the specified precision. Python also has a default precision of 28, while you're using 26 in PHP.</p>
<pre><code>In [57]: import ... | 3 | 2016-06-03T21:43:06Z | [
"php",
"python",
"decimal",
"fixed-point",
"bcmath"
] |
looping through to draw chessboard with python | 37,604,726 | <p>I'm trying to draw a chess board using turtle graphics but i'm not sure how to loop through every other square to paint it black </p>
<pre><code>for each_row in range(number_of_rows):
for each_column in range(number_of_columns):
if (each_column % 2) ==0: #this is the line that's doubtful
... | 1 | 2016-06-03T01:52:03Z | 37,604,902 | <p>The trouble with this is it will only alternate colours for changing columns, not changing rows - so you'll end up with a stripy board, not a chequered board. You need to change your conditional to include the row number, so that both rows and columns alternate colours. It so happens that simply adding the numbers t... | 1 | 2016-06-03T02:14:29Z | [
"python",
"turtle-graphics"
] |
subplot error in Matplotlib using seaborn | 37,604,730 | <p>I am plotting subplots of heatmap using seaborn with the following stripped down code. I get "AttributeError: 'numpy.ndarray' object has no attribute 'spines'" if I use nrows=2 and ncols=2, the plot works if either of nrows or ncols=1. How do I fix this?</p>
<pre><code>import pandas as pd
import matplotlib.pyplot a... | 1 | 2016-06-03T01:52:22Z | 37,605,291 | <p>Your <code>axes</code> variable is a 2x2 numpy array. So when you do <code>axes[0]</code>, it is giving you the first row. I assume you want <code>axes[0, 0]</code> or <code>axes.flat[0]</code>.</p>
| 2 | 2016-06-03T03:03:12Z | [
"python",
"numpy",
"matplotlib",
"seaborn"
] |
Merging 1D and 2D lists in python | 37,604,747 | <p>I'm trying to set up data to convert to a numpy array. I have three lists. Two are one dimensional, and one is two dimensional.</p>
<pre><code>a = [1,2,3]
b = [4,5,6]
c = [ [7,8],[9,10],[11,12] ]
</code></pre>
<p>I want to end up with this:</p>
<pre><code>[ [1,4,7,8],[2,5,9,10],[3,6,11,12] ]
</code></pre>
<p>I... | 7 | 2016-06-03T01:55:42Z | 37,604,883 | <p>Assuming you don't mind if the use of NumPy in the conversion itself, the following should work.</p>
<pre><code>from numpy import array
a = array([1, 2, 3])
b = array([4, 5, 6])
c = array([[7, 8], [9, 10], [11, 12]])
result = array(list(zip(a, b, c[:, 0], c[:, 1])))
</code></pre>
<p>Note that <code>c[:, n]</code... | 4 | 2016-06-03T02:11:43Z | [
"python",
"list",
"numpy"
] |
Merging 1D and 2D lists in python | 37,604,747 | <p>I'm trying to set up data to convert to a numpy array. I have three lists. Two are one dimensional, and one is two dimensional.</p>
<pre><code>a = [1,2,3]
b = [4,5,6]
c = [ [7,8],[9,10],[11,12] ]
</code></pre>
<p>I want to end up with this:</p>
<pre><code>[ [1,4,7,8],[2,5,9,10],[3,6,11,12] ]
</code></pre>
<p>I... | 7 | 2016-06-03T01:55:42Z | 37,605,014 | <p>In case you want to operate with standard Python lists you can use <code>zip</code> and then process each row afterwards:</p>
<pre><code>from itertools import chain
a = [1,2,3]
b = [4,5,6]
c = [[7,8], [9,10], [11,12]]
[list(chain.from_iterable(y if isinstance(y, list) else [y] for y in x)) for x in zip(a, b, c)]
... | 1 | 2016-06-03T02:28:17Z | [
"python",
"list",
"numpy"
] |
Merging 1D and 2D lists in python | 37,604,747 | <p>I'm trying to set up data to convert to a numpy array. I have three lists. Two are one dimensional, and one is two dimensional.</p>
<pre><code>a = [1,2,3]
b = [4,5,6]
c = [ [7,8],[9,10],[11,12] ]
</code></pre>
<p>I want to end up with this:</p>
<pre><code>[ [1,4,7,8],[2,5,9,10],[3,6,11,12] ]
</code></pre>
<p>I... | 7 | 2016-06-03T01:55:42Z | 37,605,112 | <p>A <code>numpy</code> solution (as per your tag) would be</p>
<pre><code>In [398]: np.vstack([a,b,np.array(c).T]).T
Out[398]:
array([[ 1, 4, 7, 8],
[ 2, 5, 9, 10],
[ 3, 6, 11, 12]])
</code></pre>
<p>this makes <code>c</code> into a 2x3 array:</p>
<pre><code>In [399]: np.array(c).T
Out[399]:
a... | 3 | 2016-06-03T02:39:51Z | [
"python",
"list",
"numpy"
] |
Merging 1D and 2D lists in python | 37,604,747 | <p>I'm trying to set up data to convert to a numpy array. I have three lists. Two are one dimensional, and one is two dimensional.</p>
<pre><code>a = [1,2,3]
b = [4,5,6]
c = [ [7,8],[9,10],[11,12] ]
</code></pre>
<p>I want to end up with this:</p>
<pre><code>[ [1,4,7,8],[2,5,9,10],[3,6,11,12] ]
</code></pre>
<p>I... | 7 | 2016-06-03T01:55:42Z | 37,605,158 | <p>With <code>python3</code> it's as simple as</p>
<pre><code>a = [1,2,3]
b = [4,5,6]
c = [ [7,8],[9,10],[11,12] ]
[[x, y, *z] for x, y, z in zip(a, b, c)]
[[1, 4, 7, 8], [2, 5, 9, 10], [3, 6, 11, 12]]
</code></pre>
| 3 | 2016-06-03T02:44:26Z | [
"python",
"list",
"numpy"
] |
Merging 1D and 2D lists in python | 37,604,747 | <p>I'm trying to set up data to convert to a numpy array. I have three lists. Two are one dimensional, and one is two dimensional.</p>
<pre><code>a = [1,2,3]
b = [4,5,6]
c = [ [7,8],[9,10],[11,12] ]
</code></pre>
<p>I want to end up with this:</p>
<pre><code>[ [1,4,7,8],[2,5,9,10],[3,6,11,12] ]
</code></pre>
<p>I... | 7 | 2016-06-03T01:55:42Z | 37,605,191 | <p>For starters, <code>zip</code> yields tuples, not lists, so you'd have to convert its output into lists:</p>
<pre><code>def lzip(*args):
'Transforms the tuples yielded by zip into equivalent lists.'
for tup in zip(*args):
yield list(tup)
return
# Later...
a = [1, 2, 3]
b = [4, 5, 6]
c = [
[7,... | 1 | 2016-06-03T02:49:30Z | [
"python",
"list",
"numpy"
] |
Concatenate two lists with nested for loops in Python | 37,604,759 | <p>I want to create a list of string elements that is a deck of cards.</p>
<p>I created two lists of strings (1-Ace and suites). I want to use nested for loops to do this, and include a word in-between the two (" of "). I did this quickly and easily when printing everything, but when I went to append to another list... | 0 | 2016-06-03T01:56:58Z | 37,604,801 | <p>The error points to improper mixing of tabs and spaces. Most text editors offer an option 'replace tabs by spaces' or something similar. Or, if you plan to stick with Python, I strongly recommend using a serious IDE like <a href="https://www.jetbrains.com/pycharm/" rel="nofollow">PyCharm</a> (my favourite) or <a hre... | 2 | 2016-06-03T02:01:19Z | [
"python",
"list",
"for-loop",
"nested",
"concatenation"
] |
How do I fill in the colour of this shape? | 37,604,811 | <pre><code>import turtle
t = turtle.Turtle
t.fillcolor("pink")
t.pencolor("red")
for x in range(10):
for x in range(10):
t.begin_fill()
right(36)
t.forward(15)
t.end_fill()
t.penup()
t.right(36)
t.forward(90)
t.pendown()
</code></pre>
<p>This was my code to make th... | -1 | 2016-06-03T02:02:12Z | 37,604,958 | <p>I found three errors. First, you must instantiate <code>Turtle</code> by using parentheses:</p>
<pre><code>t = turtle.Turtle()
</code></pre>
<p>Second, you forgot the object on the <code>right(36)</code> call in the inner loop.</p>
<pre><code>t.right(36)
</code></pre>
<p>Finally, move the <code>begin_fill()</cod... | 0 | 2016-06-03T02:21:54Z | [
"python",
"turtle-graphics"
] |
Having trouble reading CSV files with rows of different column count | 37,604,893 | <p>I am having trouble reading through a file where the rows have different lengths. Specifically, I know that the file is 13 rows long and that rows 1 and 13 have 2 values in them where the rest (2-12) have 4. I want to get one value from row 1 and one value from row 13, and one value from each of rows 2-12 depending ... | 0 | 2016-06-03T02:12:44Z | 37,605,060 | <p>Well, you have to either avoid the <code>IndexError</code></p>
<pre><code>for row in readCSV:
if len(row) > 2: # make sure the row is long enough
if (row[2] == " debit"): # now this can't fail
# ...
elif (row[2] == " credit"):
# ...
</code></pre>
<p>or handle it:</p... | 1 | 2016-06-03T02:33:44Z | [
"python",
"oop",
"csv"
] |
Passing "gets" c language function input parameter from an inline python code | 37,604,934 | <p><br>
How can I pass output of a Python script to gets function of a c program ? My c program code is below :</p>
<pre><code>#include <stdio.h>
int main()
{
char name[64];
printf("%p\n", name);
fflush(stdout);
puts("What's your name?");
fflush(stdout);
gets(name);
printf("Hello, %s!\n", n... | 0 | 2016-06-03T02:19:11Z | 37,605,104 | <pre><code> python -c 'print "A"*1000'
</code></pre>
<p>will print <code>A</code> thousand times. If you wish to pass this to the C programme then you need a buffer of size at-least one greater than <code>1000</code>, the extra 1 is to accommodate the null character.</p>
<pre><code>#include <stdio.h>
#include ... | 0 | 2016-06-03T02:38:54Z | [
"python",
"bash",
"gets"
] |
Passing "gets" c language function input parameter from an inline python code | 37,604,934 | <p><br>
How can I pass output of a Python script to gets function of a c program ? My c program code is below :</p>
<pre><code>#include <stdio.h>
int main()
{
char name[64];
printf("%p\n", name);
fflush(stdout);
puts("What's your name?");
fflush(stdout);
gets(name);
printf("Hello, %s!\n", n... | 0 | 2016-06-03T02:19:11Z | 37,605,672 | <p>To send data from the stdout of one command into the stdin of another command, you need a "pipe":</p>
<pre><code>python -c 'print "A"*1000' | ./a.out
</code></pre>
<p>I assume that the buffer overrun here is deliberate, so I'll leave out the lecture about the unsafety of <code>gets</code>.</p>
<p>Normally, a comm... | 4 | 2016-06-03T03:58:28Z | [
"python",
"bash",
"gets"
] |
How to click the button and get the source of new page with python-selenium? | 37,604,956 | <p>I wish to click the <code>next</code> button till the end and scrape all the sources of the page. My code is as below:</p>
<pre><code>from selenium import webdriver
from selenium.common import exceptions
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Firefox()
browser.get('ht... | 0 | 2016-06-03T02:21:51Z | 37,605,300 | <p>I believe that the search results that are shown on the pages are AJAX and hence you will not be able to see them in the HTML source as AJAX is dynamic and stored only in memory.</p>
<p>You can access the data by finding the elements in the DOM, for example using CSS locators.</p>
| 0 | 2016-06-03T03:04:35Z | [
"python",
"selenium"
] |
Turning a Python list of objects into a list of one-to-many objects | 37,604,978 | <p>Say we have a list of book objects, each with a title and an author ID:</p>
<pre><code>books = [
{ 'title': 'book1', 'author_id': 'author1' },
{ 'title': 'book2', 'author_id': 'author2' },
{ 'title': 'book3', 'author_id': 'author1' }
]
</code></pre>
<p>How would we efficiently go about transforming thi... | 0 | 2016-06-03T02:23:35Z | 37,605,106 | <p>I would suggest this (edit to how you see fit, I only did the titles)</p>
<pre><code>{'author1': ['book1', 'book3'], 'author2': ['book2']}
</code></pre>
<p>You can get it like so </p>
<pre><code>authors = dict()
for book in books:
author_id = book['author_id']
if author_id not in authors:
authors[... | 2 | 2016-06-03T02:39:02Z | [
"python",
"list",
"dictionary",
"one-to-many"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.