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 |
|---|---|---|---|---|---|---|---|---|---|
Need to assign each tuple in a list to a value in a dict | 37,590,875 | <p>I want to assign a value to each tuple in a list. Let's say my list looks like this:</p>
<pre><code>[(68, 125), (113, 69), (65, 86), (108, 149), (152, 53), (78, 90), (54, 160), (20, 137), (107, 90), (48, 12)]
</code></pre>
<p>I need to assign each of these tuples into a dict where it should look like:</p>
<pre><c... | -3 | 2016-06-02T11:42:33Z | 37,590,971 | <p>There are some problems in your code.</p>
<ul>
<li>iterate over the tuples, you don't have to split them</li>
<li>compare using <code>in</code>, it's shorter than using <code>or</code></li>
<li>use <code>append</code> to add to an existing list</li>
</ul>
<p>Try this:</p>
<pre><code>new_dict = {"1":[], "2":[], "3... | 1 | 2016-06-02T11:46:55Z | [
"python",
"list",
"python-3.x",
"dictionary",
"tuples"
] |
Need to assign each tuple in a list to a value in a dict | 37,590,875 | <p>I want to assign a value to each tuple in a list. Let's say my list looks like this:</p>
<pre><code>[(68, 125), (113, 69), (65, 86), (108, 149), (152, 53), (78, 90), (54, 160), (20, 137), (107, 90), (48, 12)]
</code></pre>
<p>I need to assign each of these tuples into a dict where it should look like:</p>
<pre><c... | -3 | 2016-06-02T11:42:33Z | 37,591,353 | <p>If you know the group of each element (as you mentioned), you can proceed with:</p>
<pre><code>from itertools import groupby
L = [(68, 125), (113, 69), (65, 86), (108, 149), (152, 53), (78, 90), (54, 160), (20, 137), (107, 90), (48, 12)]
ix = [1, 2, 2, 2, 3, 3, 4]
{i:map(lambda x: x[0], g) for i, g in groupby(zi... | 1 | 2016-06-02T12:03:09Z | [
"python",
"list",
"python-3.x",
"dictionary",
"tuples"
] |
Invert a matrix in place with NumPy | 37,590,881 | <p>I have a very big matrix that I want to invert. <code>numpy.linalg.inv</code> works great but is it also possible to do this in place (without allocating a new matrix)?</p>
| 2 | 2016-06-02T11:42:48Z | 37,591,299 | <p>No. However scipy.linalg.inv gives you roughly this functionality with the <code>overwrite_a</code> option:
<a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.inv.html#scipy.linalg.inv" rel="nofollow">http://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.inv.html#scipy.linalg.inv</... | 4 | 2016-06-02T12:01:00Z | [
"python",
"numpy"
] |
High performance many-to-many relationships in python | 37,590,903 | <p>Given <code>cluster</code> and <code>node</code> objects: </p>
<pre class="lang-py prettyprint-override"><code>class Cluster():
def __init__(self):
pass
class Node():
def __init__(self):
pass
</code></pre>
<p>I am wondering what is the best data structure or design that meets the following ... | 0 | 2016-06-02T11:43:54Z | 37,595,697 | <p>I implemented a similar data structure on a home project ; my own requirements called for a look alike architecture, except i called cluster "tags" (but the core concept is the same).</p>
<p>Here is how you may implement it:</p>
<ul>
<li>A list of clusters' names (or classes)</li>
<li>A dictionnary of lists. In th... | 0 | 2016-06-02T15:10:21Z | [
"python"
] |
File not opening past NUL byte | 37,591,016 | <p>I'm having trouble seeing the contents of an entire file due to there being NUL bytes throughout the file.</p>
<p>The following is a hexdump of my file(it's in a code segment to maintain readability):</p>
<pre><code>0000-0010: 22 fc 6b 0c-6c 3f 6d 0c-a2 ea da b6-dc d6 6e 00 ".k.l?m. ......n.
0000-0020: 22 d4 66... | 0 | 2016-06-02T11:48:45Z | 37,591,391 | <p>There is a problem with windows, that nul-bytes terminates any text-string. So Windows stops printing at the first <code>\0</code>. You can use <code>repr</code> to print escape characters.</p>
| 1 | 2016-06-02T12:04:54Z | [
"python",
"file"
] |
Get instance variables in order in Python | 37,591,180 | <p>Let's say I have the following class:</p>
<pre><code>class Foo(object):
def __init__(self, value):
self.d = value
self.a = value
self.s = value
self.k = value
</code></pre>
<p>I want to <a href="http://stackoverflow.com/questions/109087/how-to-get-instance-variables-in-python">r... | 1 | 2016-06-02T11:55:20Z | 37,591,669 | <p>You can't easily do this without using metaclasses (as @Daniel said). But if you want a workaround that produces a similar effect, you can store all of your "instance variables" in a <a href="https://docs.python.org/2/library/collections.html#collections.OrderedDict" rel="nofollow"><code>collections.OrderedDict</cod... | 0 | 2016-06-02T12:18:13Z | [
"python"
] |
Get instance variables in order in Python | 37,591,180 | <p>Let's say I have the following class:</p>
<pre><code>class Foo(object):
def __init__(self, value):
self.d = value
self.a = value
self.s = value
self.k = value
</code></pre>
<p>I want to <a href="http://stackoverflow.com/questions/109087/how-to-get-instance-variables-in-python">r... | 1 | 2016-06-02T11:55:20Z | 37,592,373 | <p>If you want ordering of object variables you can use something like that:</p>
<pre><code>from collections import OrderedDict
class FooModel(object):
def __new__(cls, *args, **kwargs):
instance = object.__new__(cls)
instance.__odict__ = OrderedDict()
return instance
def __setattr__(... | 2 | 2016-06-02T12:50:06Z | [
"python"
] |
Get instance variables in order in Python | 37,591,180 | <p>Let's say I have the following class:</p>
<pre><code>class Foo(object):
def __init__(self, value):
self.d = value
self.a = value
self.s = value
self.k = value
</code></pre>
<p>I want to <a href="http://stackoverflow.com/questions/109087/how-to-get-instance-variables-in-python">r... | 1 | 2016-06-02T11:55:20Z | 37,592,544 | <p>You can give your class a method that is similar to <code>__dict__</code>, but which returns an OrderedDict instead.</p>
<pre><code>from collections import OrderedDict
class Foo(object):
def __init__(self, d, a, s, k):
self.d = d
self.a = a
self.s = s
self.k = k
def ordered... | 0 | 2016-06-02T12:56:50Z | [
"python"
] |
Get instance variables in order in Python | 37,591,180 | <p>Let's say I have the following class:</p>
<pre><code>class Foo(object):
def __init__(self, value):
self.d = value
self.a = value
self.s = value
self.k = value
</code></pre>
<p>I want to <a href="http://stackoverflow.com/questions/109087/how-to-get-instance-variables-in-python">r... | 1 | 2016-06-02T11:55:20Z | 37,593,235 | <p>You can implement the <code>__setattr__</code> method to keep track of these things for you:</p>
<pre><code>#!python3
class OrderedAttrs:
def __init__(self, d, a, s, k):
self._order = []
self.d = d
self.a = a
self.s = s
self.k = k
def __setattr__(self, name, value):... | 0 | 2016-06-02T13:26:22Z | [
"python"
] |
Python Kivy using Atlas | 37,591,189 | <p>I've started using Kivy for python app's UI.
I want to style my buttons using an atlas with images.
I've created one, with some standard 100x100 png images: btn_up, btn_down.</p>
<pre><code>Button:
text: _('State')
font_size: 22
on_press: screens.current = 'current_... | 0 | 2016-06-02T11:55:53Z | 37,593,935 | <p>The Button stretches its image disproportionately in order to let you use a single image for different button shapes (note how the default image always has borders of the same width, no matter the button size). I think the way to disable this is just to add <code>border: 0, 0, 0, 0</code>, or other options will have... | 0 | 2016-06-02T13:55:08Z | [
"python",
"button",
"kivy",
"atlas"
] |
Twilio Python : Get participants in completed Conference | 37,591,286 | <p>I have been trying to get all calls that were in particular conference. What I do is select calls by conference id like this,</p>
<pre><code>calls = client.calls.list(conferenceid="thiswillbevalidconferenceid")
</code></pre>
<p>I tried with <code>conferenceid</code> and <code>conference_id</code> but its not worki... | 1 | 2016-06-02T12:00:25Z | 37,657,192 | <p>Twilio developer evangelist here.</p>
<p>I'm afraid there's no way to get the participants of a conference call that has completed.</p>
<p>The <a href="https://www.twilio.com/docs/api/rest/conference" rel="nofollow">Conference resource</a> in the REST API does have a <a href="https://www.twilio.com/docs/api/rest/p... | 0 | 2016-06-06T12:14:56Z | [
"python",
"twilio"
] |
Getting information of a panoram in google street view python | 37,591,645 | <p>I'm using the following url to get important information of one latitud-longitud coordinate points in google street view.</p>
<p><a href="http://maps.google.com/cbk?output=xml&ll=" rel="nofollow">http://maps.google.com/cbk?output=xml&ll=</a>....</p>
<p>Specifically I need to know what is the real coordinat... | 0 | 2016-06-02T12:17:12Z | 37,592,336 | <p>From the <a href="https://developers.google.com/maps/terms" rel="nofollow">Google Maps API TOS</a>: 10.4d</p>
<blockquote>
<p>No use of Content without a Google map. Unless the Maps APIs Documentation expressly permits you to do so, you will not use the Content in a Maps API Implementation without a corresponding... | 0 | 2016-06-02T12:48:08Z | [
"python",
"google-street-view"
] |
Running multiple functions at the same time | 37,591,684 | <p>I'm new to python, I'm trying to write a small program that will update find files and update then in directory ( this is working ) </p>
<p>The problem I'm facing is that I can not get two functions to run at the same time. For example While the code searches for the file and replaces them, also display a small pop... | 1 | 2016-06-02T12:18:54Z | 37,592,810 | <pre><code>import thread
from template import *
from graph import *
try:
thread.start_new_thread(main,())
thread.start_new_thread(graph,())
except KeyboardInterrupt:
thread.exit()
while 1:
pass
</code></pre>
<p>This is an example of how to call 2 functions at a time using multiThreads. Calling Function ... | 0 | 2016-06-02T13:08:42Z | [
"python",
"python-2.7",
"tkinter"
] |
Django Test unittest.loader.ModuleImportFailure | 37,591,726 | <p>I can't import my models in my tests directory, this is my error :</p>
<pre><code>======================================================================
ERROR: tests.test_views (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import ... | 1 | 2016-06-02T12:20:42Z | 37,593,914 | <p>You shouldn't normally need a <code>models.py</code> in your tests directory.</p>
<p>If you want to import your <code>Entreprise</code> model from the <code>front</code> app, then change your import from</p>
<pre><code>from .models import Entreprise
</code></pre>
<p>to</p>
<pre><code>from front.models import Ent... | 0 | 2016-06-02T13:54:17Z | [
"python",
"django",
"unit-testing"
] |
Start GPIO Script on startup | 37,591,820 | <p>I have searched far and wide and tried a million different methods, but nothing works.</p>
<p>This is the scenario.</p>
<p>I have an RPi A+, it is connected to a sound sensor via GPIO.</p>
<p>I need this script to start when the Pi starts up. The Pi won't be near me or connected to a screen, so if the power fails... | 0 | 2016-06-02T12:25:41Z | 37,592,216 | <p>First of all make your python script as a standalone, it should start with something like
<code>#!/usr/bin/python</code> and could be executed only by typing the script name in shell.</p>
<p>Then take a look at several topics such as "starting a python program at boot". You will find several methods : </p>
<ul>
<... | 0 | 2016-06-02T12:42:34Z | [
"python",
"linux",
"python-3.x"
] |
Why PyTypeObject has so many specific members for specific functionality | 37,591,824 | <p>For example, the <code>PyFloat_Type</code> has many operations in <code>tp_as_number</code>. When this type object gets initialized, all these operations will be written into <code>tp_dict</code> of it with slots.</p>
<p>On the other hand, when I write a custom class with <code>__add__</code> in it, it's <code>tp_d... | 0 | 2016-06-02T12:25:56Z | 37,595,093 | <p>Because when a C level function is using your type, it isn't performing lookup by name in <code>tp_dict</code> (slow), it's directly pulling the pointer from <code>tp_as_number</code> (fast).</p>
<p>A couple pointer dereferences is a trivial cost, requires no reference counting boilerplate, etc.; the cost is measur... | 0 | 2016-06-02T14:44:45Z | [
"python",
"c",
"interpreter",
"cpython"
] |
Scapy with Python to save packets in a log file with time stamp | 37,591,879 | <p>I am using the Scapy library with Pyhton to collect data such as mac address. I am creating a log file that saves the data collected and timestamps it. I would like to save the packet as well, just in case I will need any of the data at a later case. </p>
<p>I've been using some of their methods that displays the p... | 1 | 2016-06-02T12:28:04Z | 37,602,524 | <p>I solved it:</p>
<pre><code>pac=p.show
</code></pre>
<p>And then in logger:</p>
<pre><code>logger.log(
mac=mac,
signal=signal,
channel = channel,
pi=pi_id,
ap=ap,
s_id=s_id,
packet=packet,
)
</code></pre>
<p>Thanks</p>
| 2 | 2016-06-02T21:36:21Z | [
"python",
"logging",
"scapy"
] |
How to configure pybuilder tool? | 37,591,881 | <p>I have downloaded pybuilder and installed pyhon 3.4. How to configure pybuilder and build automation with it.</p>
| 0 | 2016-06-02T12:28:10Z | 37,592,023 | <p>Just google it? There are enough tutorials out there. For example <a href="http://pybuilder.readthedocs.io/en/latest/" rel="nofollow">Pybuilder tutorial</a></p>
| 0 | 2016-06-02T12:34:33Z | [
"python",
"automation"
] |
Odoo change inventory_value in stock.quant | 37,592,026 | <p>I need to change inventory value in stock.quant, I want to add shipping cost and technician cost (A technician is specified in each sale order line, he has a cost for checking the product). I have overridden the '_get_inventory_value' function in stock.py </p>
<pre><code>def _get_inventory_value(self, cr, uid, quan... | 1 | 2016-06-02T12:34:39Z | 37,593,596 | <p>delivered order (model <code>stock.picking</code>) have a field <strong>Source Document</strong> (<code>origin</code>), so using <strong>origin</strong> you can get the record of <code>sale.order</code> and <code>sale.order.line</code>
<a href="http://i.stack.imgur.com/yFqhK.png" rel="nofollow"><img src="http://i.... | 0 | 2016-06-02T13:40:44Z | [
"python",
"openerp",
"odoo-9"
] |
PyQt5 GUI crashes when traversing iglob iterator on large directory | 37,592,039 | <pre><code>from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import os
from os import scandir, walk
from time import sleep
from glob import iglob, glob
class FileRead(QWidget):
def __init__(self, parent=None):
super(FileRead, self).__init__(parent)
self.resize(600... | 0 | 2016-06-02T12:35:14Z | 37,614,421 | <p>The solution I used was to use QThreads instead of running a for loop for every d in dir. This way the GUI event loop isn't blocked and it doesn't look like the GUI crashes. In addition the program runs faster as a whole. </p>
| 0 | 2016-06-03T12:28:46Z | [
"python",
"file",
"user-interface",
"pyqt5"
] |
getting related object in single row .get() query (OneToOneField ) | 37,592,056 | <p>here is my account model which is related to User</p>
<pre><code>class Accounts(models.Model):
user = models.OneToOneField(User , unique=True)
name = models.CharField(max_length=50 , default='')
lastname = models.CharField(max_length=50, default='')
phone = models.CharField(max_length=11, default... | 0 | 2016-06-02T12:35:56Z | 37,592,074 | <p>You can use <a href="https://docs.djangoproject.com/en/1.9/ref/models/querysets/#first" rel="nofollow"><code>first</code></a> instead of get</p>
<blockquote>
<p>Returns the first object matched by the queryset, or None if there is no matching object. If the QuerySet has no ordering defined, then the queryset is a... | 0 | 2016-06-02T12:36:41Z | [
"python",
"django"
] |
Passing arrays from Python to Fortran with F2PY results error=2 (shape related) | 37,592,168 | <p>I have Fortran code which I'd like to feed from Python with f2py. But I am not able to pass Numpy arrays of a known shape via f2py. (I'm on Python 2.7.10 and using gfortran and mingw32 as compilers).</p>
<p>Here is my Fortran code:</p>
<pre><code>Subroutine test(nx,ny,mask)
Integer, intent(inout) :: mask(ny,nx) ... | 1 | 2016-06-02T12:40:50Z | 37,592,956 | <p>The following seems to work for me</p>
<p>Fortran block in <code>untitled.f90</code>:</p>
<pre><code>subroutine test(nx,ny,mask)
integer, intent(in) :: nx, ny
integer, dimension(nx,ny), intent(inout) :: mask
!f2py intent(in,out) mask ... | 1 | 2016-06-02T13:14:27Z | [
"python",
"arrays",
"numpy",
"fortran",
"f2py"
] |
installing lxml in python34 on amazon ec2 | 37,592,172 | <p>I have seen many threads on this topic but I still can't get the lxml module installed in python34 on Amazon EC2.</p>
<p>I have installed the requests module with</p>
<pre><code>sudo easy_install-3.4 requests
</code></pre>
<p>But if I try installing the lxml module with</p>
<pre><code>sudo easy_install-3.4 lxml
... | 3 | 2016-06-02T12:40:58Z | 37,592,395 | <p>Based on the following error message, it does not look like you have a compiler installed.</p>
<pre><code>/usr/lib64 unable to execute 'gcc': No such file or directory
</code></pre>
<p>You need to install a compiler as well, in addition to the development libraries.</p>
<pre><code>sudo yum install gcc libxml2-dev... | 0 | 2016-06-02T12:50:50Z | [
"python",
"amazon-ec2",
"lxml"
] |
how Fitting a curve to a histogram in python | 37,592,212 | <p>I need to fit a curve to my histogram. It just shows me the histogram not the curve fitted. This is my code:</p>
<pre><code>from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
import matplotlib.mlab as mlab
f= np.loadtxt('data Ties', unpack='False')
bins = [0,1000... | 0 | 2016-06-02T12:42:17Z | 37,592,969 | <p>The pdf is on the graph, it is just really small. Just look at the values of <code>y</code>:</p>
<pre><code>array([ 8.83232194e-07, 9.10034504e-07, 1.17854794e-06,
1.53635735e-06, 1.95663517e-06, 2.43444572e-06,
2.95912259e-06, 3.51397321e-06, 4.07667940e-06,
4.62048215e-06, ... | 0 | 2016-06-02T13:15:09Z | [
"python",
"curve-fitting"
] |
Django get app name from file | 37,592,297 | <p>I need to execute some custom raw SQL in Django (1.9). Since tables in Django are prefixed with the app name I need to retrieve the app name. I want to use the same code in different apps later on, so I would like to get the app name in a soft coded way, just given the file the code resides in. What would be the bes... | 0 | 2016-06-02T12:46:14Z | 37,592,383 | <p>Instead of "guessing" the table name using the default convention you should use <code>Model.objects.model._meta.db_table</code> to get the real name.</p>
<p>A model can override the default table name convention and this will break your code reusability...</p>
| 4 | 2016-06-02T12:50:22Z | [
"python",
"django"
] |
Django reusable package - test DB is not created on the fly | 37,592,460 | <p>I'm creating tests for my django reusable package/application and my DB is not being created on the fly.</p>
<p>I'm following steps at <a href="https://docs.djangoproject.com/en/1.9/topics/testing/advanced/#using-the-django-test-runner-to-test-reusable-applications" rel="nofollow">https://docs.djangoproject.com/en/... | 1 | 2016-06-02T12:53:16Z | 37,613,795 | <p>I've found out the problem, it was missing migrations.</p>
<p>Once migrations has been created, tests with models are running just fine.</p>
| 0 | 2016-06-03T11:57:35Z | [
"python",
"django",
"django-models",
"django-testing"
] |
When would I pass in an instance of a class to a method as self? | 37,592,564 | <p>I am getting started with Python on PyCharm and NLTK and ran into the following question. I have the following code. Text source us a POS-tagged corpus. 'JJ' stands for ADJECTIVE:</p>
<p><strong>Main Script</strong>:</p>
<pre><code>for each_element in textSource[indexCounter:]:
indexCounter += 1
if "JJ" in each_e... | 2 | 2016-06-02T12:57:47Z | 37,592,693 | <p>This issue appears to be in your main script:</p>
<pre><code>p = adjectiveobject.Adjective
</code></pre>
<p>should be</p>
<pre><code>p = adjectiveobject.Adjective(<whatever tagged input should be>)
</code></pre>
<p>(note the trailing parentheses). The line you have saves a reference to the <em>class</em> ... | 2 | 2016-06-02T13:03:37Z | [
"python",
"object",
"nltk"
] |
When would I pass in an instance of a class to a method as self? | 37,592,564 | <p>I am getting started with Python on PyCharm and NLTK and ran into the following question. I have the following code. Text source us a POS-tagged corpus. 'JJ' stands for ADJECTIVE:</p>
<p><strong>Main Script</strong>:</p>
<pre><code>for each_element in textSource[indexCounter:]:
indexCounter += 1
if "JJ" in each_e... | 2 | 2016-06-02T12:57:47Z | 37,593,008 | <p>As others already stated, you need to instantiate the class, however, there is another bug (<code>TypeError</code>) waiting to go off in the next line. An instance method takes self as an argument but not as a parameter. The reference to the class is automatically passed by python, so you won't need to pass <code>p<... | 1 | 2016-06-02T13:16:25Z | [
"python",
"object",
"nltk"
] |
When would I pass in an instance of a class to a method as self? | 37,592,564 | <p>I am getting started with Python on PyCharm and NLTK and ran into the following question. I have the following code. Text source us a POS-tagged corpus. 'JJ' stands for ADJECTIVE:</p>
<p><strong>Main Script</strong>:</p>
<pre><code>for each_element in textSource[indexCounter:]:
indexCounter += 1
if "JJ" in each_e... | 2 | 2016-06-02T12:57:47Z | 37,593,046 | <blockquote>
<p>When would I pass in an instance of a class to a method as self? </p>
</blockquote>
<p>For typical usage of python, you never need to pass an explicit <code>self</code> to a method.</p>
<p>Once you have a class instance, all methods calls will receive <code>self</code> as an automatic first argument... | 1 | 2016-06-02T13:17:55Z | [
"python",
"object",
"nltk"
] |
Scikit-learn random forest tree - how to interpret 'samples' and 'values'? | 37,592,568 | <p>I've made a random forest with the scikit learn package (python). However, when showing the trees, there seems to be something wrong.
The total samples per node is not the sum of the values. Also, the values associated with the position in the list of values does not seem to correspond with the class label it assig... | 1 | 2016-06-02T12:58:00Z | 37,592,794 | <p>You star with 64 samples and all your terminating nodes have a total of 64 samples. The terminating nodes don't have to be at the same level, in this case three of the terminating nodes have enough information after two decisions, but two of them need a third one.</p>
<p>Whenever a node splits the samples are split... | 0 | 2016-06-02T13:07:40Z | [
"python",
"scikit-learn",
"classification",
"random-forest",
"decision-tree"
] |
Adjusting widget size in QGraphicsGridLayout | 37,592,580 | <p>I am trying to make a grid on a QGraphicsView and QGraphicsScene with custom QGraphicsWidgets, but I am not sure how the best way to do this would be. I'm working with PyQt4, but this is a general Qt question.</p>
<p>My current implementation contains the following. One QGraphicsScene (with view) and one QGraphicsW... | 0 | 2016-06-02T12:58:37Z | 37,598,213 | <blockquote>
<ol>
<li>Is there a better way to make the hierarchy of widgets, my current one seems excessive (Scene > Widget > Layout > Widgets)</li>
</ol>
</blockquote>
<p>When I use the <code>QGraphics....</code> classes, I generally will subclass <code>QGraphicsView</code>. The view will create it's own scen... | 1 | 2016-06-02T17:14:16Z | [
"python",
"c++",
"qt",
"qt4",
"pyqt4"
] |
Can I export RapidMiner model to integrate with python? | 37,592,608 | <p>I have trained a classifier model using RapidMiner after a trying a lot of algorithms and evaluate it on my dataset.
I also export the model from RapidMiner as XML and pkl file, but I can't read it in my python program (scikit-learn).
Is there any way to import RapidMiner classifier/model in a python program and u... | 0 | 2016-06-02T13:00:05Z | 37,593,003 | <p>Practically, I would say no - just train your model in sklearn from the beginning if that's where you want it.</p>
<p>Your RapidMiner model is some kind of object. The two formats you are exporting as are just storage methods. Sklearn models are a different kind of object. You can't directly save one and load it... | 1 | 2016-06-02T13:16:18Z | [
"python",
"machine-learning",
"scikit-learn",
"rapidminer"
] |
Can I export RapidMiner model to integrate with python? | 37,592,608 | <p>I have trained a classifier model using RapidMiner after a trying a lot of algorithms and evaluate it on my dataset.
I also export the model from RapidMiner as XML and pkl file, but I can't read it in my python program (scikit-learn).
Is there any way to import RapidMiner classifier/model in a python program and u... | 0 | 2016-06-02T13:00:05Z | 37,653,717 | <p>You could use the <a href="https://marketplace.rapidminer.com/UpdateServer/faces/product_details.xhtml?productId=rmx_pmml" rel="nofollow" title="pmml extenstion">pmml extenstion</a> for RapidMiner to export your model.</p>
<p>For python there is for example the <a href="https://code.google.com/archive/p/augustus/" ... | 0 | 2016-06-06T09:19:55Z | [
"python",
"machine-learning",
"scikit-learn",
"rapidminer"
] |
Pygame game not starting | 37,592,626 | <p>So the idea is the game will open up to menu where the users can select a level, Easy, Medium, Hard, or exit the game. Right now all that happens is that the game opens to a black screen the size of my game (1024, 768) where the close, maximize, and minimize aren't clickable. Any help is greatly appreciated.</p>
<p... | 1 | 2016-06-02T13:00:55Z | 37,594,988 | <p>At no point in your program are you starting the main() function or anything else for that matter.</p>
<p>A common piece found at the bottom of many python scripts is:</p>
<pre><code>if __name__ == '__main__':
main()
</code></pre>
<p>This is used to kick start everything if the script is the top level python ... | 3 | 2016-06-02T14:40:06Z | [
"python",
"pygame"
] |
Pygame game not starting | 37,592,626 | <p>So the idea is the game will open up to menu where the users can select a level, Easy, Medium, Hard, or exit the game. Right now all that happens is that the game opens to a black screen the size of my game (1024, 768) where the close, maximize, and minimize aren't clickable. Any help is greatly appreciated.</p>
<p... | 1 | 2016-06-02T13:00:55Z | 37,633,070 | <p>To declare them as globals write this after the line: <code>def main():</code> :</p>
<pre><code> global running, players, finishes, walls, currentLevel
</code></pre>
| 1 | 2016-06-04T17:25:47Z | [
"python",
"pygame"
] |
Is logging from multiple celery worker into one file safe? | 37,592,637 | <p>I run celeryd in prefork mode with cuncurrency > 1 like below:</p>
<pre><code>celery worker -c 100 -A x.y.z.tasks -f mylogfile.log --loglevel=INFO -n myworker
</code></pre>
<p>As Pythons's logging from multiple processes into one file is not safe (<a href="https://docs.python.org/3/howto/logging-cookbook.html#logg... | 2 | 2016-06-02T13:01:26Z | 37,643,334 | <p>only master process is handling this log file, so you are safe</p>
| 0 | 2016-06-05T15:00:22Z | [
"python",
"logging",
"celery"
] |
Scipy interpolate returns a 'dimensionless' array | 37,592,643 | <p>I understand that <code>interp1d</code> expects an array of values to interpolate, but the behavior when passing it a float is strange enough to ask what is going on and what exactly is being returned</p>
<pre><code>import numpy as np
from scipy.interpolate import interp1d
x = np.array([1,2,3,4])
y = np.array([5,7... | 2 | 2016-06-02T13:01:35Z | 37,597,901 | <p>The <code>interp1d</code> returns a value that matches the input in shape - after wrapping in <code>np.array()</code> if needed:</p>
<pre><code>In [324]: f([1,2,3])
Out[324]: array([ 5., 7., 9.])
In [325]: f([2.5])
Out[325]: array([ 7.75])
In [326]: f(2.5)
Out[326]: array(7.75)
In [327]: f(np.array(2.5))
Out[3... | 2 | 2016-06-02T16:58:04Z | [
"python",
"numpy",
"scipy",
"interpolation"
] |
remove extension in list python | 37,592,721 | <p>I have the following code whereby I would like to find all files in a certain folder (this folder contains .TIF files), then store these names in a .txt file which works so far. However, I don't want the extensions, of anything that would be in the folder.</p>
<pre><code>import os, sys
f = []
b = os.walk('C:\\Use... | 0 | 2016-06-02T13:04:43Z | 37,592,860 | <p>Replace this line:</p>
<pre><code>f.extend(filenames)
</code></pre>
<p>with something like this:</p>
<pre><code>filenames_stripped = [os.path.splitext(file)[0] for file in filenames]
f.extend(filenames_stripped)
</code></pre>
<p>or even simpler: </p>
<pre><code>f.extend([os.path.splitext(file)[0] for file in fi... | 0 | 2016-06-02T13:10:39Z | [
"python",
"os.walk"
] |
remove extension in list python | 37,592,721 | <p>I have the following code whereby I would like to find all files in a certain folder (this folder contains .TIF files), then store these names in a .txt file which works so far. However, I don't want the extensions, of anything that would be in the folder.</p>
<pre><code>import os, sys
f = []
b = os.walk('C:\\Use... | 0 | 2016-06-02T13:04:43Z | 37,592,876 | <p>Remove the extension in a generator expression when you get the filenames with <a href="https://docs.python.org/3/library/os.path.html#os.path.splitext" rel="nofollow"><code>os.path.splitext</code></a>. Change:</p>
<pre><code>f.extend(filenames)
</code></pre>
<p>to:</p>
<pre><code>f.extend(os.path.splitext(name)[... | 1 | 2016-06-02T13:11:17Z | [
"python",
"os.walk"
] |
Combing 2D list of tuples and then sorting them in Python | 37,592,787 | <p>Update: The list are filled with strings I edited the list to show this</p>
<p>I have 3 different list such as</p>
<pre><code>Section = [('1', '1.1', '1.2'), ('1', '2', '2.2', '3'), ('1', '1.2', '3.2', '3.5')]
Page = [('1', '1', '3'), ('1', '2', '2', '2'), ('1', '2', '3', '5')]
Titles = [('General', 'Info', 'Titl... | 7 | 2016-06-02T13:07:09Z | 37,593,035 | <p>You can do:</p>
<pre><code>from itertools import chain
tuples = zip(map(float, list(chain(*Section))),
list(chain(*Page)),
list(chain(*Title)))
zip(*sorted(tuples, key=lambda x: x[0]))
Out[232]:
[(1.0, 1.0, 1.0, 1.1, 1.2, 1.2, 2.0, 2.2, 3.0, 3.2, 3.5),
('1', '1', '1', '1', '3', '2', ... | 2 | 2016-06-02T13:17:33Z | [
"python",
"list",
"sorting"
] |
Combing 2D list of tuples and then sorting them in Python | 37,592,787 | <p>Update: The list are filled with strings I edited the list to show this</p>
<p>I have 3 different list such as</p>
<pre><code>Section = [('1', '1.1', '1.2'), ('1', '2', '2.2', '3'), ('1', '1.2', '3.2', '3.5')]
Page = [('1', '1', '3'), ('1', '2', '2', '2'), ('1', '2', '3', '5')]
Titles = [('General', 'Info', 'Titl... | 7 | 2016-06-02T13:07:09Z | 37,593,267 | <p>Try this,</p>
<pre><code>Section = [('1', '1.1', '1.2'), ('1', '2', '2.2', '3'), ('1', '1.2', '3.2', '3.5')]
Page = [('1', '1', '3'), ('1', '2', '2', '2'), ('1', '2', '3', '5')]
Titles = [('General', 'Info', 'Titles'), ('More', 'Info', 'Section', 'Here'), ('Another', 'List', 'Of', 'Strings')]
# Flat a list of tup... | 2 | 2016-06-02T13:27:39Z | [
"python",
"list",
"sorting"
] |
Combing 2D list of tuples and then sorting them in Python | 37,592,787 | <p>Update: The list are filled with strings I edited the list to show this</p>
<p>I have 3 different list such as</p>
<pre><code>Section = [('1', '1.1', '1.2'), ('1', '2', '2.2', '3'), ('1', '1.2', '3.2', '3.5')]
Page = [('1', '1', '3'), ('1', '2', '2', '2'), ('1', '2', '3', '5')]
Titles = [('General', 'Info', 'Titl... | 7 | 2016-06-02T13:07:09Z | 37,593,307 | <p>My approach. List comprehension and no need to import modules. I think its fast, and its very simple.</p>
<p>EDIT: I've added an unsorted approach and a sorted approach.</p>
<pre><code>#Unsorted
newList =[
[item for sublist in Section for item in sublist],
[item for sublist in Page for item in sublist],
... | -1 | 2016-06-02T13:29:16Z | [
"python",
"list",
"sorting"
] |
Django Custom Auth Model can't login from Admin portal | 37,592,872 | <p>I've created custom user profile model for Django's auth app, and the issue that I can't login using Django Admin login form.</p>
<p>Note: User <code>is_superuser=1</code> and <code>is_staff=1</code></p>
<pre><code>models.py
=======================
class UserProfile(AbstractUser):
gender = models.IntegerField(... | 0 | 2016-06-02T13:11:10Z | 37,593,029 | <p>You can't use admin login if the user is not a staff member (as the error sais).
If you want a built in login page you can probably use <code>/accounts/login</code> which is the default value for <code>settings.LOGIN_URL</code></p>
| 0 | 2016-06-02T13:17:20Z | [
"python",
"django",
"django-admin"
] |
How to append dynamically generated values into NumPy array? | 37,592,935 | <p>I want to add some dynamically calculated values to result array:</p>
<pre><code>out = []
for item in foo:
spam = get_spam(foo)
out.append(spam)
return np.array(out)
</code></pre>
<p>Unfortunately, this doesn't work, because <strong>spam</strong> shape is (10,1) and <strong>out</strong> array has one extr... | 0 | 2016-06-02T13:13:29Z | 37,593,277 | <p>You can use numpy <code>concatenate</code> function:</p>
<pre><code>np.concatenate([get_spam(foo) for item in foo])
</code></pre>
<p>It eventually accepts an argument <em>axes</em> for the direction of concatenation (vertically/horizontally).</p>
| 3 | 2016-06-02T13:28:01Z | [
"python",
"arrays",
"numpy"
] |
How to append dynamically generated values into NumPy array? | 37,592,935 | <p>I want to add some dynamically calculated values to result array:</p>
<pre><code>out = []
for item in foo:
spam = get_spam(foo)
out.append(spam)
return np.array(out)
</code></pre>
<p>Unfortunately, this doesn't work, because <strong>spam</strong> shape is (10,1) and <strong>out</strong> array has one extr... | 0 | 2016-06-02T13:13:29Z | 37,593,361 | <p>if <strong>spam</strong> always has the shape (10,1) you could slice the returned array with <code>[:,0]</code></p>
<pre><code>for item in foo:
spam = get_spam(foo)
out.append(spam[:,0])
return np.array(out)
</code></pre>
| 1 | 2016-06-02T13:31:15Z | [
"python",
"arrays",
"numpy"
] |
Deep copy of a np.array of np.array | 37,593,013 | <p>I have a numpy array of different numpy arrays and I want to make a deep copy of the arrays. I found out the following:</p>
<pre><code>import numpy as np
pairs = [(2, 3), (3, 4), (4, 5)]
array_of_arrays = np.array([np.arange(a*b).reshape(a,b) for (a, b) in pairs])
a = array_of_arrays[:] # Does not work
b = array_... | 0 | 2016-06-02T13:16:31Z | 37,593,181 | <pre><code>import numpy as np
import copy
pairs = [(2, 3), (3, 4), (4, 5)]
array_of_arrays = np.array([np.arange(a*b).reshape(a,b) for (a, b) in pairs])
a = copy.deepcopy(array_of_arrays)
</code></pre>
<p>Feel free to read up more about this <a href="https://docs.python.org/2/library/copy.html" rel="nofollow">here</... | 1 | 2016-06-02T13:24:25Z | [
"python",
"arrays",
"numpy"
] |
Deep copy of a np.array of np.array | 37,593,013 | <p>I have a numpy array of different numpy arrays and I want to make a deep copy of the arrays. I found out the following:</p>
<pre><code>import numpy as np
pairs = [(2, 3), (3, 4), (4, 5)]
array_of_arrays = np.array([np.arange(a*b).reshape(a,b) for (a, b) in pairs])
a = array_of_arrays[:] # Does not work
b = array_... | 0 | 2016-06-02T13:16:31Z | 37,593,311 | <p>Beaten by one minute. Indeed, deepcopy is the answer here.</p>
<p>To your second question abut indexing: I have a feeling that you may be better off with a simple list or a dictionary-type data structure here. np.arrays make sense primarily if each array element is of the same type. Of course you can argue that eac... | 2 | 2016-06-02T13:29:30Z | [
"python",
"arrays",
"numpy"
] |
Deep copy of a np.array of np.array | 37,593,013 | <p>I have a numpy array of different numpy arrays and I want to make a deep copy of the arrays. I found out the following:</p>
<pre><code>import numpy as np
pairs = [(2, 3), (3, 4), (4, 5)]
array_of_arrays = np.array([np.arange(a*b).reshape(a,b) for (a, b) in pairs])
a = array_of_arrays[:] # Does not work
b = array_... | 0 | 2016-06-02T13:16:31Z | 37,597,524 | <pre><code>In [276]: array_of_arrays
Out[276]:
array([array([[0, 1, 2],
[3, 4, 5]]),
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]]),
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19]])], dtype=object)
</c... | 1 | 2016-06-02T16:38:28Z | [
"python",
"arrays",
"numpy"
] |
sqlalchemy bind table to multiple engines | 37,593,048 | <p>I have two different mysql databases with the same schema.
In short I want to use sqlalchemy to read from one database and insert the data into the other one. </p>
<p>Here is my code so far</p>
<pre><code> Base = declarative_base()
class Test(Base):
__tablename__ = 'test'
ID = Column(Integer,... | 0 | 2016-06-02T13:18:04Z | 37,595,612 | <p>You have to call <code>make_transient</code> to transfer an object from one session to another. You may also want to clear the <code>obj.id</code> column by setting it to <code>None</code>.</p>
<p>This SO question should help you further.
<a href="http://stackoverflow.com/questions/30287042/how-to-use-make-transie... | 1 | 2016-06-02T15:06:46Z | [
"python",
"sqlalchemy"
] |
Is it safe to set python bin in $PATH to another python version? | 37,593,092 | <p>I have installed Anaconda3 just now, and I noticed that now, when I run <code>python</code> command from terminal, <code>Python 3.5.1 |Anaconda 4.0.0 (64-bit)|</code> is starting. Anaconda installer had added path to anaconda dir in <code>$PATH</code> and there is symlink from <code>python</code> to <code>python3.5<... | 0 | 2016-06-02T13:20:17Z | 37,594,042 | <p>That depends on your OS. <a href="https://wiki.ubuntu.com/Python" rel="nofollow">Debian and Ubuntu both have ongoing projects to move the "default" version from 2 to 3</a> (also <a href="https://wiki.ubuntu.com/Python/Python35Transition" rel="nofollow">here</a>). But it's not recommended to point /usr/bin/python to ... | 1 | 2016-06-02T13:58:41Z | [
"python",
"debian",
"anaconda"
] |
Is it safe to set python bin in $PATH to another python version? | 37,593,092 | <p>I have installed Anaconda3 just now, and I noticed that now, when I run <code>python</code> command from terminal, <code>Python 3.5.1 |Anaconda 4.0.0 (64-bit)|</code> is starting. Anaconda installer had added path to anaconda dir in <code>$PATH</code> and there is symlink from <code>python</code> to <code>python3.5<... | 0 | 2016-06-02T13:20:17Z | 37,594,156 | <blockquote>
<p>My question is: will programs, that depends from python command and
expects python2, work correctly?</p>
</blockquote>
<p>Those programs should use full path of the python binary. Something like <code>/usr/bin/python</code>, and so <code>$PATH</code> is irrelevant. As long as you don't change <code... | 1 | 2016-06-02T14:03:06Z | [
"python",
"debian",
"anaconda"
] |
counting the number of articles that do not possess specific words using pandas | 37,593,208 | <p>I am trying to find which rows of my JSON file contain texts that do not possess certain words. The way I am trying to do it is though pandas and regular expressions in the following way:</p>
<pre><code># import json module for parsing
import json
import re
import pandas
keywords1 = ('economic', 'economy', 'econom... | 1 | 2016-06-02T13:25:17Z | 37,593,364 | <p>I think you need if need groupby by <code>index</code>:</p>
<pre><code>counts = matchingbodies.groupby(df.index).size()
</code></pre>
<p>Or:</p>
<pre><code>counts = matchingbodies.groupby(level=0).size()
</code></pre>
<p>EDIT:</p>
<p>It seems you need:</p>
<pre><code>matchingbodies = df.loc[(~df.body.str.conta... | 1 | 2016-06-02T13:31:23Z | [
"python",
"pandas"
] |
Lookup values are not being recognized in dictionary | 37,593,292 | <p>I created a dictionary with values such as 2100 and 97AK. I created a dataframe to have values mapped to the dictionary. The values that have mixed numbers and letters are found but all the integers ones are returned as NaN. What could cause t... | -1 | 2016-06-02T13:28:32Z | 37,594,041 | <p>Your <code>abbreviations</code> dictionary shows the <code>integers</code> stored as <code>strings</code> (note the surrounding single quotes in your code). <code>2100</code> does not match <code>'2100'</code>.</p>
<p>You either need to populate that dictionary with integers where appropriate, or read/cast your dat... | 0 | 2016-06-02T13:58:36Z | [
"python",
"dictionary"
] |
What is the simplest way to get tfidf with pandas dataframe? | 37,593,293 | <p>I want to calculate tf-idf from the documents below. I'm using python and pandas.</p>
<pre><code>import pandas as pd
df = pd.DataFrame({'docId': [1,2,3],
'sent': ['This is the first sentence','This is the second sentence', 'This is the third sentence']})
</code></pre>
<p>First, I thought I would ne... | 2 | 2016-06-02T13:28:33Z | 37,593,408 | <p>Scikit-learn implementation is really easy : </p>
<pre><code>from sklearn.feature_extraction.text import TfidfVectorizer
v = TfidfVectorizer()
x = v.fit_transform(df['sent'])
</code></pre>
<p>There are plenty of parameters you can specify. See the documentation <a href="http://scikit-learn.org/stable/modules/gener... | 4 | 2016-06-02T13:33:02Z | [
"python",
"pandas",
"scikit-learn",
"tf-idf",
"gensim"
] |
gevent and strong hashing password method | 37,593,310 | <p>I am using gevent greenlet so I am very constrained by everything related to CPU computation. And I need to use a strong hashing method for password storage.</p>
<p>When I am not in a gevent context, I have the habit of using bcrypt but I did this small test :</p>
<pre><code>import bcrypt
import time
password = b... | 0 | 2016-06-02T13:29:21Z | 37,594,726 | <p>Gevent works well with network and IO bound functions that take advantage of concurrency but bcrypt does not have this functionality.</p>
<p>Try using Processlet and ObjectPool. Processlet focuses on CPU bound tasks, like hashing, not IO bound tasks. A great example of using bcrypt with Processlet and ObjectPool... | 1 | 2016-06-02T14:28:20Z | [
"python",
"bcrypt",
"gevent"
] |
Jquery $.get using selenium python | 37,593,322 | <p>I was trying make a jquery get request using selenium python from the web page but I am always getting None as the response. Here is the code.</p>
<pre><code> from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.PhantomJS()
driver.get(url)... | 0 | 2016-06-02T13:29:44Z | 39,279,581 | <p><code>$.get</code> is asynchronous.</p>
<p>You can do a promise with the <code>$.get</code> and in a success (or failed), you can create a DOM element with the answer and with Selenium you can use a WebDriverWait, for wait for that element with the response.</p>
| 0 | 2016-09-01T19:35:01Z | [
"jquery",
"python",
"selenium"
] |
Stdin Stdout python | 37,593,340 | <p>For my work i'm used to work with matlab. No i try to learn the basic skills of python as well. Currently I'm working on on the following excersise: </p>
<blockquote>
<p>You are interested in extracting all of the occurrences that look like
this</p>
<p><code><Aug22-2008> <15:37:37> Bond Energy ... | -1 | 2016-06-02T13:30:16Z | 37,593,433 | <p>Why use a regular expression? Split the input:</p>
<pre><code>>>> s = """<Aug22-2008> <15:37:37> Bond Energy LDA -17.23014168 eV"""
>>> s.split()[5]
'-17.23014168'
</code></pre>
<p>Of course, if you can provide more sample input that does not put the number on the 5th position, this ... | 0 | 2016-06-02T13:34:02Z | [
"python"
] |
Stdin Stdout python | 37,593,340 | <p>For my work i'm used to work with matlab. No i try to learn the basic skills of python as well. Currently I'm working on on the following excersise: </p>
<blockquote>
<p>You are interested in extracting all of the occurrences that look like
this</p>
<p><code><Aug22-2008> <15:37:37> Bond Energy ... | -1 | 2016-06-02T13:30:16Z | 37,593,765 | <p>To find the numbers your looking for I would use a positive lookbehind and lookahead function in your regular expression. </p>
<pre><code>(?<=Bond Energy LDA ).*(?= eV)
</code></pre>
<p>This checks to see if the thing you are looking at is proceeded by 'Bond Energy LDA' and followed by 'eV' but does not include... | 1 | 2016-06-02T13:47:13Z | [
"python"
] |
Stdin Stdout python | 37,593,340 | <p>For my work i'm used to work with matlab. No i try to learn the basic skills of python as well. Currently I'm working on on the following excersise: </p>
<blockquote>
<p>You are interested in extracting all of the occurrences that look like
this</p>
<p><code><Aug22-2008> <15:37:37> Bond Energy ... | -1 | 2016-06-02T13:30:16Z | 37,593,886 | <p>If you want to use regex you may use:</p>
<pre><code>(?:<.*>\W+)[a-zA-Z ]+([-+]?[0-9]*\.?[0-9]+)
</code></pre>
<p><a href="https://regex101.com/r/uT7hO9/1" rel="nofollow">Demo</a></p>
| 0 | 2016-06-02T13:53:07Z | [
"python"
] |
python 3.5 32 bit windows import module fails but pip install worked | 37,593,483 | <p>new to python installed python 3.5 32-bit on windows 10, used pip to install a module </p>
<pre>
C:\Users\Lopez\Anaconda3\Scripts>pip install ystockquote
Requirement already satisfied (use --upgrade to upgrade): ystockquote in c:\users\lopez\anaconda3\lib\site-packages
You are using pip version 7.1.2, however versi... | 0 | 2016-06-02T13:36:14Z | 37,594,200 | <p>Run <code>pip --version</code> and check the Python version and start IDLE and check the Python version and see if they match.</p>
<p>If not, use explicit <code>pipx.y</code> matching IDLE or start IDLE from a Python matching plain <code>pip</code>.</p>
| 0 | 2016-06-02T14:04:56Z | [
"python",
"python-3.x"
] |
python 3.5 32 bit windows import module fails but pip install worked | 37,593,483 | <p>new to python installed python 3.5 32-bit on windows 10, used pip to install a module </p>
<pre>
C:\Users\Lopez\Anaconda3\Scripts>pip install ystockquote
Requirement already satisfied (use --upgrade to upgrade): ystockquote in c:\users\lopez\anaconda3\lib\site-packages
You are using pip version 7.1.2, however versi... | 0 | 2016-06-02T13:36:14Z | 37,594,282 | <p>thanks for your help guys,
I beleive the issues where with adding paths to my environment variables not the version of pip. I managed to get this working using the window pip install once i installed python 3 in a custom directory C:\Python35 rather than the deafault long windows suggested path </p>
<p><strong>Inst... | 0 | 2016-06-02T14:08:15Z | [
"python",
"python-3.x"
] |
rpy2: how to convert str vector into numeric vector | 37,593,506 | <p>Anyone know how to convert str vector in rpy2 to a numeric vector?</p>
<pre><code>r('x_num = as.numeric(x)')
</code></pre>
<p>works, but x_num is not in the python environment. I can't call it from python.</p>
<p>I tried:</p>
<pre><code>x_num = base.as_numeric(x)
r('class(x_num)')
</code></pre>
<p>which shows:<... | 0 | 2016-06-02T13:36:53Z | 37,599,694 | <p>Regarding to your 1st problem, if the <code>x_num</code> variable is in the format you want in the R environment, you can get its <em>view</em> in python using the <code>numpy.asarray()</code> method (as stated in the <a href="http://rpy2.readthedocs.io/en/latest/numpy.html" rel="nofollow">documentation</a>), so cha... | 1 | 2016-06-02T18:36:05Z | [
"python",
"rpy2"
] |
rpy2: how to convert str vector into numeric vector | 37,593,506 | <p>Anyone know how to convert str vector in rpy2 to a numeric vector?</p>
<pre><code>r('x_num = as.numeric(x)')
</code></pre>
<p>works, but x_num is not in the python environment. I can't call it from python.</p>
<p>I tried:</p>
<pre><code>x_num = base.as_numeric(x)
r('class(x_num)')
</code></pre>
<p>which shows:<... | 0 | 2016-06-02T13:36:53Z | 37,605,282 | <p>It easier to identify an issue with a fully working example. Without it I am tempted to say that it is working as expected.</p>
<pre><code>In [1]: import rpy2.robjects as ro
In [2]: ro.vectors.FloatVector((1,2,3,4,5))
Out[2]:
<FloatVector - Python:0x7f3541c68788 / R:0x3541468>
[1.000000, 2.000000, 3.000000,... | 1 | 2016-06-03T03:01:47Z | [
"python",
"rpy2"
] |
Feeding a Python array into a Perl script | 37,593,542 | <p>So I'm working on an automation script for a workflow in my company. I have written the whole thing in Python, as most of our databases API's were in Python. However, one of our databases uses Perl for their API. It would obviously take me weeks if not months to port their excellent API into python. So, and I assume... | 5 | 2016-06-02T13:38:44Z | 37,595,378 | <p>I've created an example using three scripts. </p>
<p>The first one is a Python script that creates a list, then writes it to a JSON file. We then have a Perl script that reads in the JSON, modifies it (adds three more elements to the array), then writes it back to the JSON data file. The last script, in Python, sho... | 6 | 2016-06-02T14:57:12Z | [
"python",
"perl"
] |
Pandas replacing elements not working | 37,593,550 | <p>I have looked up this issue and most questions are for more complex replacements. However in my case I have a very simple dataframe as a test dummy.</p>
<p>The aim is to replace a string anywhere in the dataframe with an nan, however this does not seem to work (i.e. does not replace; no errors whatsoever). I've tri... | 1 | 2016-06-02T13:38:55Z | 37,593,583 | <p>You need to assign back </p>
<pre><code>df = df.replace('white', np.nan)
</code></pre>
<p>or pass param <code>inplace=True</code>:</p>
<pre><code>In [50]:
d = {'color' : pd.Series(['white', 'blue', 'orange']),
'second_color': pd.Series(['white', 'black', 'blue']),
'value' : pd.Series([1., 2., 3.])}
df = pd.... | 2 | 2016-06-02T13:40:13Z | [
"python",
"numpy",
"pandas",
"replace"
] |
Pandas replacing elements not working | 37,593,550 | <p>I have looked up this issue and most questions are for more complex replacements. However in my case I have a very simple dataframe as a test dummy.</p>
<p>The aim is to replace a string anywhere in the dataframe with an nan, however this does not seem to work (i.e. does not replace; no errors whatsoever). I've tri... | 1 | 2016-06-02T13:38:55Z | 37,593,604 | <p>When you use <code>df.replace()</code> it creates a new temporary object, but doesn't modify yours. You can use one of the two following lines to modify df:</p>
<pre><code>df = df.replace('white', np.nan)
df.replace('white', np.nan, inplace = True)
</code></pre>
| 2 | 2016-06-02T13:41:01Z | [
"python",
"numpy",
"pandas",
"replace"
] |
Masking with 'where' using Python xarray is not working anymore | 37,593,785 | <p>I am running into troubles after updating <code>xarray</code>.</p>
<p>I have a salinity dataset whose dimensions are:</p>
<pre><code>(u'time', u'stations', u'layer')
</code></pre>
<p>For a specific station, I want to get the salinity of a chosen depth, say -10 m. The dimension layer contains the values of depth t... | 1 | 2016-06-02T13:48:18Z | 37,602,811 | <p>Installing the packages from the IOOS channel together with dask solved the problem. For setting up the IOOS Python environment follow the steps at: </p>
<p><a href="https://github.com/ioos/conda-recipes/wiki/Setting-up-the-IOOS-Python-environment" rel="nofollow">https://github.com/ioos/conda-recipes/wiki/Setting-u... | 1 | 2016-06-02T21:55:52Z | [
"python",
"dask",
"python-xarray"
] |
Select rows randomly based on condition pandas python | 37,593,901 | <p>I have a small test data sample:</p>
<pre><code>import pandas as pd
df = {'ID': ['H900','H901','H902','','M1435','M149','M157','','M699','M920','','M789','M617','M991','H903','M730','M191'],
'Clone': [0,1,2,2,2,2,2,2,3,3,3,4,4,4,5,5,6],
'Length': [48,42 ,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48]}
df = pd... | 1 | 2016-06-02T13:53:55Z | 37,594,015 | <p>I think you need filter empty <code>ID</code> with <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a>:</p>
<pre><code>import pandas as pd
import numpy as np
df = {'ID': ['H900','H901','H902','','M1435','M149','M157','','M699','M920'... | 3 | 2016-06-02T13:57:43Z | [
"python",
"pandas",
"random"
] |
Django list of json objects | 37,593,902 | <p>I have a django backend and from my view I want to return a list of json objects. </p>
<pre><code>@api_view(('GET',))
def get_analytics(request):
# Number of users who dogged in once to our system today
login_count= User.objects.filter(last_login__startswith=
timezone.now().date()).count() # return... | 0 | 2016-06-02T13:53:56Z | 37,594,070 | <p>You need <code>JsonResponse</code>. But if you are going to use it you don't need <code>json.dumps(data)</code>, <code>JsonResponse</code> dose it for you. Quoting from <a href="https://docs.djangoproject.com/en/1.9/ref/request-response/#jsonresponse-objects" rel="nofollow">django doc</a>:</p>
<blockquote>
<pre><co... | 2 | 2016-06-02T13:59:35Z | [
"python",
"django"
] |
Django list of json objects | 37,593,902 | <p>I have a django backend and from my view I want to return a list of json objects. </p>
<pre><code>@api_view(('GET',))
def get_analytics(request):
# Number of users who dogged in once to our system today
login_count= User.objects.filter(last_login__startswith=
timezone.now().date()).count() # return... | 0 | 2016-06-02T13:53:56Z | 37,594,078 | <p>Use <code>JsonResponse</code> instead, to properly parse the <code>json</code> object:</p>
<pre><code>from django.http import JsonResponse
</code></pre>
<p>then, you can use your original <code>dict</code> object:</p>
<pre><code>return JsonResponse(data)
</code></pre>
| 1 | 2016-06-02T14:00:00Z | [
"python",
"django"
] |
Simple TCP EchoServer in Python | 37,593,915 | <p>I found this script of TCP server which "echoes" back the data to the client. </p>
<pre><code>#!/usr/bin/env python
import socket
host = ''
port = 50000
backlog = 5
size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port))
s.listen(backlog)
while 1:
client, address = s.accep... | 0 | 2016-06-02T13:54:18Z | 37,595,239 | <p>Perhaps you accidentally ran the EchoServer twice in different windows? You can only bind one receiver to a port/address combination.</p>
| 2 | 2016-06-02T14:51:03Z | [
"python",
"sockets",
"tcp"
] |
Simple TCP EchoServer in Python | 37,593,915 | <p>I found this script of TCP server which "echoes" back the data to the client. </p>
<pre><code>#!/usr/bin/env python
import socket
host = ''
port = 50000
backlog = 5
size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port))
s.listen(backlog)
while 1:
client, address = s.accep... | 0 | 2016-06-02T13:54:18Z | 37,595,447 | <p>Seems like there is some other application running on those ports. </p>
<p>Can you try checking if there are any other app listening on same port using:</p>
<pre><code>netstat -ntlpu | grep 50000
</code></pre>
| 0 | 2016-06-02T15:00:13Z | [
"python",
"sockets",
"tcp"
] |
How to use a argument variable argv? | 37,593,934 | <p>I wrote the following command but I don't understand it.<br>
<code>from sys import argv</code><br>
what is argv?<br>
how to use it?<br>
I wrote <code>sycript,a,b=argv</code><br>
but I am getting the error that need more than one value to unpack.</p>
| 0 | 2016-06-02T13:55:04Z | 37,594,246 | <p><code>argv</code> - The list of command line arguments passed to a Python script.</p>
<p><code>sycript,a,b=argv</code> gives you "ValueError: need more than 1 value to unpack" because you have just run the script as <code>python <script_name.py></code> without giving the two arguments.</p>
<p>Run the script ... | 0 | 2016-06-02T14:06:46Z | [
"python",
"argv"
] |
How to use a argument variable argv? | 37,593,934 | <p>I wrote the following command but I don't understand it.<br>
<code>from sys import argv</code><br>
what is argv?<br>
how to use it?<br>
I wrote <code>sycript,a,b=argv</code><br>
but I am getting the error that need more than one value to unpack.</p>
| 0 | 2016-06-02T13:55:04Z | 39,300,051 | <p>I think you should run the command by typing</p>
<pre><code>python scriptname a b
</code></pre>
<p>By <code>scriptname</code> I mean the name by which you have saved the program code.</p>
<p>I hope this helps..</p>
| 0 | 2016-09-02T20:10:30Z | [
"python",
"argv"
] |
CBC - know "why" a program is infeasible | 37,593,986 | <p>I use CBC to solve different integer linear programming problems. For some of them, the set of constraints is such that there is no solution. In this case, I get something like this:</p>
<pre><code>Problem is infeasible - 0.30 seconds
Infeasible - objective value -6832.50000000
</code></pre>
<p>Is there any way CB... | 0 | 2016-06-02T13:56:48Z | 37,599,586 | <p>I'm pretty sure, this functionality is not implemented in CBC.</p>
<h3>Alternative software</h3>
<p>There is support for this concept in <a href="http://www-03.ibm.com/software/products/en/ibmilogcpleoptistud/" rel="nofollow">Cplex</a> and <a href="http://www.gurobi.com/" rel="nofollow">Gurobi</a> though. For the ... | 2 | 2016-06-02T18:30:15Z | [
"python",
"linear-programming"
] |
How to setup a configuration file for Pylint in Spyder IDE | 37,594,025 | <p>How do I specify a custom configuration file for Pylint (command line switch <code>--rcfile</code>) in Spyder IDE?</p>
<p>I tried editing <code>pylint.bat</code> and <code>pylint-gui.bat</code> like this:</p>
<pre><code>python "%~dpn0" %* --rcfile="P:/path/to/pylintrc"
</code></pre>
<p>but without success. I alwa... | 1 | 2016-06-02T13:58:07Z | 37,712,571 | <p>Spyder will run pylint.exe, not pylint.bat, that's why what you tried doesn't work.</p>
<p>The easiest way is to put your pylintrc in your project folder, as pylint will automatically look there.</p>
<p><a href="https://docs.pylint.org/run.html#command-line-options" rel="nofollow">https://docs.pylint.org/run.html#... | 1 | 2016-06-08T20:44:04Z | [
"python",
"batch-file",
"ide",
"spyder",
"pylint"
] |
How to do random sampling within interval with given interval value? | 37,594,204 | <p>How can I do random sampling within interval with given interval?
For example, I want to do single random sampling between 1 to 10 but with each interval is 0.5. So when I do the sampling, it will give me value for example 5.5 or 2 or 8.5.</p>
<p>I have tried with
np.random.random_integers(1,10)
but this just g... | 2 | 2016-06-02T14:05:02Z | 37,594,367 | <p>You can use <code>linspace</code> from the <code>numpy</code> library. Here is an example:</p>
<pre><code>>>> import numpy
>>> numpy.linspace(0.5, 10, 20)
array([ 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5,
5. , 5.5, 6. , 6.5, 7. , 7.5, 8. , 8.5, 9. ,
... | 1 | 2016-06-02T14:11:51Z | [
"python"
] |
How to do random sampling within interval with given interval value? | 37,594,204 | <p>How can I do random sampling within interval with given interval?
For example, I want to do single random sampling between 1 to 10 but with each interval is 0.5. So when I do the sampling, it will give me value for example 5.5 or 2 or 8.5.</p>
<p>I have tried with
np.random.random_integers(1,10)
but this just g... | 2 | 2016-06-02T14:05:02Z | 37,594,392 | <p>You can do:</p>
<pre><code>from random import randrange
random_number = randrange(2,21)*.5
</code></pre>
| 0 | 2016-06-02T14:13:11Z | [
"python"
] |
How to do random sampling within interval with given interval value? | 37,594,204 | <p>How can I do random sampling within interval with given interval?
For example, I want to do single random sampling between 1 to 10 but with each interval is 0.5. So when I do the sampling, it will give me value for example 5.5 or 2 or 8.5.</p>
<p>I have tried with
np.random.random_integers(1,10)
but this just g... | 2 | 2016-06-02T14:05:02Z | 37,594,589 | <p>You can write your own function which scales, generates a random integer, and then unscales.</p>
<pre><code>from math import floor, ceil
from random import randint
def random_step(low, high, step):
low_scaled = ceil(float(low)/step)
high_scaled = floor(float(high)/step)
return randint(low_scaled, high_... | 2 | 2016-06-02T14:22:17Z | [
"python"
] |
How to do math calculation on each number in a specific column | 37,594,294 | <p>I imported an Excel file by using <code>pandas.read_excel()</code> in Python.<br>
Then I want to do math calculation to each number in a specific column, and generate a new column. But there is an error:</p>
<blockquote>
<p>TypeError: cannot convert the series to </p>
</blockquote>
<p>How can I solve this? Belo... | 1 | 2016-06-02T14:08:33Z | 37,594,347 | <p>I think you need <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.exp.html" rel="nofollow"><code>numpy.exp</code></a>:</p>
<pre><code>import numpy as np
rchdecay=N_DATA['column_name']
rchdcayf=np.exp(-rchdecay*0.008)
</code></pre>
<p>Sample:</p>
<pre><code>import pandas as pd
import nump... | 1 | 2016-06-02T14:10:51Z | [
"python",
"numpy",
"pandas",
"math",
"exp"
] |
Need to contour an object using OpenCV | 37,594,338 | <p>I am playing with image analysis for a project using OpenCV 3.1.0 and Python 2.7 in a virtual environment. I have to be able to detect my object as a region of interest. So far I was able to determine the contours of the object. However, as you may see below the results is far from what I need. </p>
<p><a href="htt... | 0 | 2016-06-02T14:10:21Z | 39,088,055 | <p>Inorder to detect your object you can perform in two approaches:</p>
<ol>
<li><p>As the background is white, you can do threshold based on colour. Also, try with different colour spaces.</p></li>
<li><p>Adjust the Threshold so that the background is black and foreground object is white. Here, your Threshold is inap... | 0 | 2016-08-22T20:19:23Z | [
"python",
"opencv",
"opencv3.0"
] |
Restrict form field in CreateView to not show current-user as a choice in template | 37,594,354 | <p>I am using simple forms and the generic CBV UpdateView to all a user to use "tokens" to give other users extra-credit. A user should not be allowed to give themselves extra-credit, so they should not show-up in the select field as a choice. I am not using a model form here and would like to know how to do this wit... | 0 | 2016-06-02T14:11:14Z | 37,594,639 | <p>You say that you want to avoid defining a model form, but that's the best approach here. It <em>might</em> be possible to hack the form's fields in the <a href="https://github.com/django/django/blob/779829662d48a54ac427574e5e0c279b69519e42/django/views/generic/edit.py#L39" rel="nofollow"><code>get_form</code></a> me... | 3 | 2016-06-02T14:24:48Z | [
"python",
"django",
"dictionary",
"django-views",
"django-class-based-views"
] |
os.path.basename(path) what does "AttributeError: 'unicode' object has no attribute 'path'" mean? | 37,594,419 | <p>I am trying to use <code>os.path.basename(path)</code> on a string. I thought that was how it was used. In the <a href="https://docs.python.org/3/library/os.path.html" rel="nofollow">doc for version 3</a> it clearly says that is the case but I am using 2.7. How do I use the method if all I have is a string (which cl... | 0 | 2016-06-02T14:14:19Z | 37,594,543 | <p>You probably have overridden <code>os</code> with your own variable.</p>
<p>Something like this:</p>
<pre><code>import os
# ...
os = "abc"
# ...
os.path # <-- error
</code></pre>
<p>Make sure you don't <a href="https://en.wikipedia.org/wiki/Variable_shadowing" rel="nofollow">shadow</a> imported libraries.</p>
| 1 | 2016-06-02T14:20:30Z | [
"python",
"path"
] |
Error when trying to encode | 37,594,439 | <p>Why can't I use <code>sourcecode = "myFile.txt" f = open(sourcecode, mode='rb')</code> to open my file and compress it? This is all pretty new to me. I would be glad if some of you could give me some advice on how to solve the problem. </p>
<pre><code>def compress(uncompressed):
"""Compress a string to a list o... | 0 | 2016-06-02T14:15:02Z | 37,594,735 | <p>One problem is the fact that you open the file inside the <code>compress</code> function. That means that <code>f</code> is not visible outside the function, and therefore calling <code>compress(f)</code> will give you an error that it does not find <code>f</code>. The correct syntax would be to move the lines <code... | 0 | 2016-06-02T14:28:42Z | [
"python",
"file",
"lzw"
] |
Parse a website after POST request with Python | 37,594,443 | <p>I want to scrap some addresses off of a store locator for a website to make it easier to put into google maps and see where all the stores in my state are located.</p>
<p>Here is the store locator website:
<a href="http://www.rockyboots.com/locator" rel="nofollow">http://www.rockyboots.com/locator</a></p>
<p>When ... | 0 | 2016-06-02T14:15:23Z | 37,597,542 | <p>A user on Reddit (<a href="https://www.reddit.com/user/commandlineluser" rel="nofollow">commandlineluser</a>) helped me with the solution. Turns out, there was another parameter that had to be passed to the POST request, but that parameter changed every time you access the URL. </p>
<p><a href="https://gist.github.... | 0 | 2016-06-02T16:39:26Z | [
"python",
"post",
"python-requests"
] |
How to make matplotlibs nbagg backend generate SVGs? | 37,594,446 | <p>Currently, I'm using the following at the start of my notebook to generate SVG plots:</p>
<pre><code>%matplotlib inline
%config InlineBackend.figure_format = 'svg'
</code></pre>
<p>When using the <a href="http://matplotlib.org/users/whats_new.html?highlight=nbagg#the-nbagg-backend" rel="nofollow"><code>nbagg</code... | 1 | 2016-06-02T14:15:29Z | 37,594,878 | <p>The <a href="https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/backend_agg.py" rel="nofollow">Agg</a> backend in matplotlib uses the <a href="http://www.antigrain.com/" rel="nofollow">Anti-Grain Geometry</a> 2D graphics library to generate bitmap graphics. The documentation for the backend... | 2 | 2016-06-02T14:34:55Z | [
"python",
"matplotlib",
"jupyter-notebook"
] |
passing textures to GLSL | 37,594,540 | <p>I'm trying to read a texture in a shader. And I only get a uniform screen (only one value seems to be read). If I comment the shader lines declaration (64 to 74), my texture is displayed correctly. So I guess it is correctly declared. </p>
<p>here is my code:</p>
<pre><code>#!/usr/bin/python
import sys
import num... | 1 | 2016-06-02T14:20:13Z | 37,595,319 | <p>Sorry guys,
I just found the answer.
Here are the shaders lines I'll use:</p>
<pre><code>f_shader = """
#version 120
uniform sampler2D texture_w;
void main() {
gl_FragColor = texture2D(texture_w, gl_TexCoord[0].xy);
}
"""
v_shader = """
#version 120
void main() {
gl_FrontColor = gl_Color;
gl_Position =... | 1 | 2016-06-02T14:54:39Z | [
"python",
"opengl",
"glsl",
"textures",
"shader"
] |
How to construct the header when a single key has multiple possible value? | 37,594,578 | <p>Now I wish to scrape a web page with python and when I look into the header constructed by the web browser, there are several keys have multiple values:</p>
<pre><code>Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:zh-CN,zh;q... | 0 | 2016-06-02T14:22:00Z | 37,594,686 | <p>This would be wiser to separate the different values, hence use an array. You can do the following :</p>
<pre><code>>>> accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
>>> header = {'Accept': accept.split(',')}
>>> header
{'Accept': ['text/html', 'app... | 0 | 2016-06-02T14:26:42Z | [
"python",
"header",
"web-crawler"
] |
On-demand imports for huge imports in __all__ | 37,594,698 | <p>I am am making a Python library with the following structure:</p>
<pre><code>my_amazing_lib
+--- __init__.py
+--- _core.py
+--- _gui.py
</code></pre>
<p>In <code>__init__.py</code> I have the following:</p>
<pre><code>from ._core import core_lib
from ._gui import huge_lib_with_gui
__all__ = ['core_lib', 'huge_li... | 3 | 2016-06-02T14:27:13Z | 37,603,706 | <p>I'd suggest keeping the expensive-to-initialize parts of your library in a separate sub-module, rather than including it directly in the top-level package namespace. While you could use proxy functions to expose the API of the expensive bits in the top level namespace without preemptively importing it all, it's prob... | 0 | 2016-06-02T23:27:55Z | [
"python"
] |
openpyxl Python Iterating Through Large Data List | 37,594,707 | <p>I have a large excel workbook with 1 sheet with roughly 45,000 rows and 45 columns. I want to iterate through the columns looking for duplicates and unique items and its taking a very long time to go through individual columns. Is there anyway to optimize my code or make this go faster? I either want to print the in... | 2 | 2016-06-02T14:27:30Z | 37,595,611 | <p>As VedangMehta mentioned, Pandas will do it very quickly for you. </p>
<h3>Run this code:</h3>
<pre><code>import pandas as pd
#read in the dataset:
df = pd.read_excel('file.xlsx', sheetname = 'file')
df_dup = df.groupby(axis=1, level=0).apply(lambda x: x.duplicated())
#save duplicated values from first column
df... | -1 | 2016-06-02T15:06:45Z | [
"python",
"excel",
"duplicates",
"openpyxl"
] |
openpyxl Python Iterating Through Large Data List | 37,594,707 | <p>I have a large excel workbook with 1 sheet with roughly 45,000 rows and 45 columns. I want to iterate through the columns looking for duplicates and unique items and its taking a very long time to go through individual columns. Is there anyway to optimize my code or make this go faster? I either want to print the in... | 2 | 2016-06-02T14:27:30Z | 37,597,209 | <p>When working with read-only mode don't use the columns property to read a worksheet. This is because data is stored in rows so columns require the parser to continually re-read the file.</p>
<p><a href="http://openpyxl.readthedocs.io/en/latest/pandas.html#converting-a-worksheet-to-a-dataframe" rel="nofollow">This i... | 0 | 2016-06-02T16:20:29Z | [
"python",
"excel",
"duplicates",
"openpyxl"
] |
I need to sort a dictionary by order of value and RETURN it | 37,594,755 | <p>So I have this code:</p>
<pre><code>new_dict = {"1":[], "2":[], "3":[], "4":[]}
for coordinates in numbers:
if coordinates == (48, 12):
new_dict["1"].append(coordinates)
elif coordinates in [(68, 125), (54, 160), (20, 137)]:
new_dict["2"].append(coordinates)
elif coordinates in [(113, 69... | -2 | 2016-06-02T14:29:55Z | 37,595,208 | <pre><code>return '\n'.join([' '.join([str(x),str(y)]) for x,y in sorted_dict])
</code></pre>
<p>From what you write I collect that you'd want it to be returned 'the same as I showed above'.</p>
<p>Edit: sorry didn't put elements <code>x,y</code> it in <code>str()</code>, corrected now</p>
| 1 | 2016-06-02T14:49:37Z | [
"python",
"python-3.x",
"dictionary"
] |
Pass all data from 2 column MySQL table into Python variable | 37,594,908 | <p>I'm trying to pass all data from 2 column (label, tweets) from my table in MySQL into Python variable and use it as training data for my classifier. what I want is for example if I print(data[0]), then I can get ([('tweet'), 'label'] using the code below</p>
<p><div class="snippet" data-lang="js" data-hide="false" ... | -1 | 2016-06-02T14:35:57Z | 37,616,402 | <p>I'm not sure about the structure of your tables, and I don't really understand what you are trying to calculate in your <code>review</code>. Anyway, I hope this might help: the result of <code>read_sql_query</code> is a dataframe, thus you have to treat it as such.</p>
<p>In the example below the table "tweet" cont... | 1 | 2016-06-03T14:00:08Z | [
"python",
"mysql",
"twitter",
"machine-learning",
"text-classification"
] |
OpenCV v3.1.0 with CRF-RNN | 37,594,925 | <p>I'm building <a href="https://github.com/torrvision/crfasrnn" rel="nofollow">CRFasRNN</a> which itself is based on caffe) after upgrading openCV to version 3.1.0 (the previous one was 2.4 I think). I keep getting errors like </p>
<pre><code>io.cpp:(.text+0x11f8): undefined reference to `cv::imdecode(cv::_InputArray... | 0 | 2016-06-02T14:36:36Z | 37,596,014 | <p>OK I solved the problem by copying code from Makefile in the Caffe installation to Makefile for caffe-crfrnn. By 'code' I mean bits related to opencv. In addition to OPENCV_VERSION := 3 in Makefile.config I added</p>
<pre><code>USE_OPENCV ?= 1
ifeq ($(USE_OPENCV), 1)
LIBRARIES += opencv_core opencv_highgui... | 0 | 2016-06-02T15:23:58Z | [
"python",
"c++",
"opencv",
"caffe",
"crf"
] |
Odoo overriden function call order | 37,594,983 | <p>It is to my understanding that odoo does not extend its models as Python extends its classes (<code>_inherit = 'model'</code>. And that seems pretty reasonable. My question though is this:</p>
<p>If I have <code>customModule1</code> that extends <code>sale.order</code> and overrides the <code>write</code> method ad... | 1 | 2016-06-02T14:40:01Z | 37,596,660 | <blockquote>
<p><code>write</code> of <strong>last</strong> installed module will call <strong>first</strong>.</p>
</blockquote>
<p><code>write</code> of <code>customModule2</code> will call first(because it last installed ) , in-case if you have called the <strong>super</strong> in write then on the basis of supe... | 1 | 2016-06-02T15:52:47Z | [
"python",
"openerp"
] |
Odoo overriden function call order | 37,594,983 | <p>It is to my understanding that odoo does not extend its models as Python extends its classes (<code>_inherit = 'model'</code>. And that seems pretty reasonable. My question though is this:</p>
<p>If I have <code>customModule1</code> that extends <code>sale.order</code> and overrides the <code>write</code> method ad... | 1 | 2016-06-02T14:40:01Z | 37,606,530 | <p>Yes it's very interesting point and no one can predict which method from which module called first because odoo manages hierarchical structure for dependency.</p>
<blockquote>
<p>Calling pattern comes into the picture only when the method will be
called from object (manually from code) and if write method call ... | 1 | 2016-06-03T05:24:49Z | [
"python",
"openerp"
] |
Argparse: Hiding usage when using argparse.ArgumentTypeError | 37,595,025 | <p>Whenever a user doesn't provide suitable parameters to arguments in my script, I raise argparse.ArgumentTypeError with the error string I provided. My problem is that argparse also prints the usage, while it seems irrelevant to me to tell the user how to use my script when he just got a parameter wrong.</p>
<p>Is t... | 0 | 2016-06-02T14:41:50Z | 37,596,911 | <p>Where are you raising the <code>ArgumentTypeError</code>? In a <code>type</code> function?</p>
<p>The definition of <code>ArgumentTypeError</code> is just <code>pass</code>; it doesn't do anything except subclass <code>Exception</code>.</p>
<p>It is referenced in <code>_get_value</code>, which calls the <code>typ... | 0 | 2016-06-02T16:04:48Z | [
"python",
"argparse"
] |
Python, Tkinter : if there a way to check checkboxes by default? | 37,595,078 | <p>I have this piece of code that will create a simple checkbox :</p>
<pre><code>from Tkinter import *
CheckVar = IntVar()
self.checkbutton = Checkbutton(self.root, text = "Test", variable = CheckVar)
</code></pre>
<p>However this checkbox in unchecked by default and I'm searching for a way to check it.</p>
<p>So f... | 1 | 2016-06-02T14:43:36Z | 37,595,436 | <p>I think the function you are looking for is <code>.select()</code></p>
<p>This function selects the checkbutton (as can be assumed from the function name)</p>
<p>Try calling this function after your widget is defined:</p>
<pre><code>from Tkinter import *
CheckVar = IntVar()
self.checkbutton = Checkbutton(self.ro... | 0 | 2016-06-02T14:59:26Z | [
"python",
"checkbox",
"tkinter"
] |
Python, Tkinter : if there a way to check checkboxes by default? | 37,595,078 | <p>I have this piece of code that will create a simple checkbox :</p>
<pre><code>from Tkinter import *
CheckVar = IntVar()
self.checkbutton = Checkbutton(self.root, text = "Test", variable = CheckVar)
</code></pre>
<p>However this checkbox in unchecked by default and I'm searching for a way to check it.</p>
<p>So f... | 1 | 2016-06-02T14:43:36Z | 37,595,809 | <p>Your <code>CheckVar</code> is a local variable. It's getting garbage collected. Save it as an object attribute. Also, you can create the variable and initialize it all in one step:</p>
<pre><code>self.CheckVar = IntVar(value=1)
self.checkbutton = Checkbutton(..., variable = self.CheckVar)
</code></pre>
| 0 | 2016-06-02T15:15:05Z | [
"python",
"checkbox",
"tkinter"
] |
boto3 check for new SQS messages in the background | 37,595,130 | <p>I have the following python script that polls sqs and processes any messages that get pushed to the queue. I run <code>python process.py</code> in terminal and see that it processing as it should.</p>
<p>What is the best or preferred method to have this script run in the background? </p>
<pre><code>conn = boto.sqs... | 0 | 2016-06-02T14:46:12Z | 37,595,236 | <p>You can use <code>bash</code> capabilites here.</p>
<p><strong>Quick and dirty :</strong></p>
<p>Running <code>python process.py &</code> will launch it as a background process.</p>
<p>Have a look at <code>nohup</code>, which stores the process logs etc.</p>
<p><strong>Clean way to do this :</strong></p>
<p... | 0 | 2016-06-02T14:51:01Z | [
"python",
"amazon-sqs",
"boto3"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.