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
python - Implementing Sobel operators with python without opencv
39,035,510
<p>Given a greyscale 8 bit image (2D array with values from 0 - 255 for pixel intensity), I want to implement the Sobel operators (mask) on an image. The Sobel function below basically loops around a given pixel,applies the following weight to the pixels: <a href="http://i.stack.imgur.com/1N67K.png" rel="nofollow"><i...
2
2016-08-19T09:24:08Z
39,038,392
<p>Sticking close to what your code is doing, one elegant solution is to use the <a href="http://docs.scipy.org/doc/scipy-0.16.1/reference/generated/scipy.ndimage.filters.generic_filter.html" rel="nofollow"><code>scipy.ndimage.filters.generic_filter()</code></a> with the formula provided above.</p> <pre><code>import n...
1
2016-08-19T11:50:05Z
[ "python", "image", "vision", "sobel" ]
Satellite position computation using Runge-Kutta 4
39,035,696
<p>my issue is related to Runge-Kutta 4 (RK4) method and the correct iteration steps required for the state vector of an orbiting satellite. The below code (in Python) describes the motion based on the description as per this link (<a href="http://www.navipedia.net/index.php/GLONASS_Satellite_Coordinates_Computation" ...
3
2016-08-19T09:32:58Z
39,066,824
<p>The equation you are solving is of the type</p> <pre><code>ddot x = a(x) </code></pre> <p>where <code>a(x)</code> is the acceleration which is computed in your <code>k1</code> computation. Indeed, the first order system would be</p> <pre><code>dot v = a(x) dot x = v </code></pre> <p>The RK4 implementation thus s...
1
2016-08-21T17:15:53Z
[ "python", "runge-kutta", "orbital-mechanics", "satellite-navigation" ]
python - adding quotes for an each word and symbol on a text file
39,035,876
<p>I want to put quotation marks between each words and symbols on a text file.</p> <p>For instance;</p> <blockquote> <p>Türkiye ya da resmî adıyla Türkiye Cumhuriyeti, topraklarının büyük bölümü Anadolu'ya, küçük bir bölümü ise Balkanlar'ın uzantısı olan Trakya'ya yayılmış bir ülke.</p>...
1
2016-08-19T09:44:11Z
39,036,017
<p>Adding <code>[IVXLCDM]+\.|[\d\.]+(?:'\w+)?</code> to the beginning of the regex pattern matches the "10.000" and "10.000'lerde" and "I." as intended.</p> <pre><code>replacer = re.compile(r"\b([IVXLCDM]+\.|[\d\.]+(?:'\w+)?|[\w'-]+|[.,!?;()%])", re.UNICODE) </code></pre>
1
2016-08-19T09:52:12Z
[ "python", "regex" ]
python - adding quotes for an each word and symbol on a text file
39,035,876
<p>I want to put quotation marks between each words and symbols on a text file.</p> <p>For instance;</p> <blockquote> <p>Türkiye ya da resmî adıyla Türkiye Cumhuriyeti, topraklarının büyük bölümü Anadolu'ya, küçük bir bölümü ise Balkanlar'ın uzantısı olan Trakya'ya yayılmış bir ülke.</p>...
1
2016-08-19T09:44:11Z
39,036,161
<pre><code>with open("turkish.txt", "r") as myfile: text=myfile.read() output_text = text.split(" ") with open("Output.txt", "w",) as outfile: for word in output_text: outfile.write(' "'+ word + '" ') </code></pre> <p>May be a better solution</p>
1
2016-08-19T09:59:46Z
[ "python", "regex" ]
How to decode string representative of utf-8 with python?
39,035,899
<p>I have a <strong>unicode</strong> like this:</p> <pre><code>\xE5\xB1\xB1\xE4\xB8\x9C \xE6\x97\xA5\xE7\x85\xA7 </code></pre> <p>And I know it is the string representative of <code>bytes</code> which is encoded with <code>utf-8</code></p> <p>Note that the string <code>\xE5\xB1\xB1\xE4\xB8\x9C \xE6\x97\xA5\xE7\x85\x...
1
2016-08-19T09:45:45Z
39,035,938
<p>If you printed the <code>repr()</code> output of your <code>unicode</code> string then you appear to have a <a href="https://en.wikipedia.org/wiki/Mojibake" rel="nofollow"><em>Mojibake</em></a>, bytes data decoded using the wrong encoding.</p> <p>First encode back to bytes, then decode using the right codec. This m...
5
2016-08-19T09:48:04Z
[ "python", "utf-8", "decode", "encode" ]
How to read input to python in bash
39,035,904
<p>I have code from <a href="http://stackoverflow.com/questions/16852655/convert-a-tsv-file-to-xls-xlsx-using-python">here</a> and I would like to use this python script in bash like:</p> <blockquote> <p>python conversion.py sample.tsv sample.xlsx</p> </blockquote> <p>python script:</p> <pre><code>import csv from ...
1
2016-08-19T09:45:58Z
39,036,020
<p>You can use <a href="https://docs.python.org/2/library/sys.html" rel="nofollow">sys.argv</a>.</p> <p>....</p> <p>tsv_file = sys.argv[1]</p> <p>xlsx_file = sys.argv[2]</p> <p>...</p> <p>You can run like:</p> <pre><code>main.py sample.tsv sample.xlsx </code></pre> <p>You also can check argparse package. It prov...
2
2016-08-19T09:52:16Z
[ "python", "bash" ]
Changing values in a list with a click
39,035,956
<p>I'm working on a 'card game'. The idea is that when the user can reveal up to two cards at the same time, so when they click on a third card, the previous two disappear. Later I will modify the code, so that if the cards the user clicked on were the same, they'd stay exposed.</p> <p>The problem is that right now on...
0
2016-08-19T09:48:46Z
39,036,759
<p>I think, you are logically wrong. If you want to exposed two card and disappear then when clicked in third one, you can not use only boolean True and False. Use a list or Two variable for first two action, If action is more then two then clear all and save third action.</p>
0
2016-08-19T10:30:15Z
[ "python", "list", "counter" ]
Changing values in a list with a click
39,035,956
<p>I'm working on a 'card game'. The idea is that when the user can reveal up to two cards at the same time, so when they click on a third card, the previous two disappear. Later I will modify the code, so that if the cards the user clicked on were the same, they'd stay exposed.</p> <p>The problem is that right now on...
0
2016-08-19T09:48:46Z
39,042,126
<p>OK, here is what I found so far based on your code. First of all yes it is possible. I created a second list which is a copy of exposed list. I update it right below where you update the exposed[card]. What I realized is that it keeps a second value True, even when exposed keeps just one. <a href="http://www.codesku...
0
2016-08-19T14:56:29Z
[ "python", "list", "counter" ]
Compress/Zip numpy arrays in Memory
39,035,983
<p>My memory is too small for my data, so I tried packing it in memory.</p> <p>The following code does work, but I have to remember the type of the data, which is kind of akward (lots of different data types). </p> <p>Any better suggestions? Smaller running time would also be appreciated</p> <pre><code>import numpy ...
1
2016-08-19T09:50:25Z
39,036,831
<p>You could try using numpy's builtin array compressor <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.savez_compressed.html#numpy-savez-compressed" rel="nofollow"><code>np.savez_compressed()</code></a>. This will save you the hassle of keeping track of the data types, but would probably give simila...
2
2016-08-19T10:33:30Z
[ "python", "numpy", "memory", "zip" ]
Python numpy data pointer addresses change without modification
39,036,089
<p><strong>EDIT</strong></p> <p>After some more fiddling around, I've so far isolated the following states:</p> <ol> <li>A <strong>1D array</strong> gives <em>two</em> different addresses when entering variable directly, and only <em>one</em> when using <code>print()</code></li> <li>A <strong>2D array</strong> (or <s...
3
2016-08-19T09:56:09Z
39,037,228
<p>From the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.data.html" rel="nofollow">docs</a> </p> <blockquote> <p>ndarray.data</p> <p>Python buffer object pointing to the start of the array’s data.</p> </blockquote> <p>Which should just be a <code>memoryview</code> of the data.</...
1
2016-08-19T10:53:09Z
[ "python", "pointers", "numpy" ]
Python numpy data pointer addresses change without modification
39,036,089
<p><strong>EDIT</strong></p> <p>After some more fiddling around, I've so far isolated the following states:</p> <ol> <li>A <strong>1D array</strong> gives <em>two</em> different addresses when entering variable directly, and only <em>one</em> when using <code>print()</code></li> <li>A <strong>2D array</strong> (or <s...
3
2016-08-19T09:56:09Z
39,037,372
<p>The <code>memoryview</code> returned by <code>a.data</code> seems to alternate between two (or more) views. If you store a given instance of <code>a.data</code>, you get consistent output:</p> <pre><code>&gt;&gt;&gt; a.data &lt;memory at 0x7fb88ea1f828&gt; &gt;&gt;&gt; a.data &lt;memory at 0x7fb88e98c4a8&gt; &gt;&g...
1
2016-08-19T10:59:25Z
[ "python", "pointers", "numpy" ]
Scrapy : XPath error: Invalid expression in //media:content
39,036,100
<p>I want to extract content from a News Site RSS Feed with Item like below </p> <pre><code>&lt;item&gt; &lt;title&gt;BPS: Kartu Bansos Bantu Turunkan Angka Gini Ratio&lt;/title&gt; &lt;media:content url="/image.jpg" expression="full" type="image/jpeg"/&gt; &lt;/item&gt; </code></pre> <p>but Error raised When parsi...
0
2016-08-19T09:56:32Z
39,036,265
<p>You need to tell xpath which namespace the <code>media</code> prefix is mapped to by calling the <a href="https://parsel.readthedocs.io/en/latest/usage.html#parsel.selector.Selector.register_namespace" rel="nofollow"><code>register_namespace(prefix, namespace)</code></a> on the selector first, e.g:</p> <pre><code>s...
2
2016-08-19T10:04:57Z
[ "python", "xpath", "scrapy", "web-crawler" ]
python list of strings parsing
39,036,115
<p>I have a list of strings representing dates:</p> <pre><code>&gt;&gt;&gt; dates ['14.9.2016', '13.9.2016', '12.9.2016', '11.9.2016', '10.9.2016', '9.9.2016', '8.9.2016', '7.9.2016', '6.9.2016', '5.9.2016'] </code></pre> <p>I need to zero-padd days &amp; months and I cannot use standard calendar methods due...
2
2016-08-19T09:57:40Z
39,036,170
<p>Sure, just inline the expression you pass to the <code>parsed_dates.append()</code> call, with <code>l</code> substituted with <code>d.split('.')</code> from your <code>for</code> loop:</p> <pre><code>['.'.join([i.zfill(2) for i in d.split('.')]) for d in dates] </code></pre> <p>Demo:</p> <pre><code>&gt;&gt;&gt; ...
7
2016-08-19T10:00:12Z
[ "python", "list-comprehension" ]
How yo make a selenium Scripts faster?
39,036,137
<p>I use python Selenium and Scrapy for crawling a website.</p> <p>but my script is so slow, </p> <pre><code>Crawled 1 pages (at 1 pages/min) </code></pre> <p>i use CSS SELECTOR instead of XPATH for optimise the time. i change the midllewares</p> <pre><code>'tutorial.middlewares.MyCustomDownloaderMiddleware': 543, ...
0
2016-08-19T09:58:22Z
39,042,044
<p>So your code has few flaws here. </p> <ol> <li>You use selenium to parse the page contents when scrapy Selectors are faster and more efficient. </li> <li>You start a webdriver for every response. </li> </ol> <p>This can be resolved very eloquently by using scrapy's <code>Downloader middlewares</code>! You want ...
0
2016-08-19T14:52:34Z
[ "python", "selenium", "web-scraping", "scrapy", "middleware" ]
Storage Format for AND-OR-tree in Python 2.7
39,036,186
<p>I am doing some work with decision trees at the moment, where I am using AND-OR trees as representation. I am looking for a suitable storage format for these kind of trees.</p> <p>The node which starts with "t" is an OR node, the node starts with a "c" is an (ordered!) AND node. The leaves always start with "p".</p...
4
2016-08-19T10:01:00Z
39,039,111
<p>If you use lists, you can link them together by nesting. Something like:</p> <pre><code>['t1', ['c1', 'p1', ['c2', 'p2', 'p3']], ['c3', ['c4', 'p4', 'p5'], ['t2', ['c5', 'p6', 'p7'], 'p8']]] </code></pre> <p>The basic structure would be:</p> <pre><code>BASE := [node_name, left, right] </code></pre> <p>where:</p>...
0
2016-08-19T12:30:21Z
[ "python", "python-2.7", "tree", "decision-tree" ]
join values in sqlalchemy
39,036,221
<p>I would like to run following postgreSQL query in SQLalchemy:</p> <pre><code>select c.* from comments c join ( values (1,1), (3,2), (2,3), (4,4) ) as x (id, ordering) on c.id = x.id order by x.ordering </code></pre> <p>Is it possible to join something like list of lists or list of tuples and use ...
0
2016-08-19T10:02:34Z
39,038,772
<pre><code>from sqlalchemy import * from yourdbmodule import dbsession VALUES = ((1, 1), (3, 2), (2, 3), (4, 4)) temp_table = Table( 'temp_table', MetaData(), Column('id', INT, primary_key=True), Column('ordering', INT), prefixes=['TEMPORARY'] ) temp_table.create(bind=dbsession.bind, checkfirst=Tru...
0
2016-08-19T12:10:48Z
[ "python", "postgresql", "sqlalchemy" ]
join values in sqlalchemy
39,036,221
<p>I would like to run following postgreSQL query in SQLalchemy:</p> <pre><code>select c.* from comments c join ( values (1,1), (3,2), (2,3), (4,4) ) as x (id, ordering) on c.id = x.id order by x.ordering </code></pre> <p>Is it possible to join something like list of lists or list of tuples and use ...
0
2016-08-19T10:02:34Z
39,045,472
<p>See the <a href="https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/PGValues" rel="nofollow">PGValues recipe</a> for how to make SQLAlchemy compile the <code>VALUES</code> clause:</p> <pre><code>from sqlalchemy.ext.compiler import compiles from sqlalchemy.sql import column from sqlalchemy.sql.expression impo...
0
2016-08-19T18:19:24Z
[ "python", "postgresql", "sqlalchemy" ]
What does it mean to sort an array/matrix by the argmax as the key?
39,036,343
<p>I am struggling to understand the mechanism behind a function around the topic of sorting in numpy.</p> <pre><code> import numpy as np arr = [[8, 5, 9], [3, 9.5, 5], [5.5, 4, 3.5], [6, 2, 1], [6,1,2],[3,2,1],[8,5,3]] res = sorted(arr, key=np.argmax) </code></pre> <p>This gives m...
4
2016-08-19T10:08:40Z
39,036,469
<p>The argmax function returns the indice of the biggest element. It is used as a key in the sort function.</p> <p>If you print this:</p> <pre><code>print([np.argmax(x) for x in arr]) </code></pre> <p>you get:</p> <pre><code>[2, 1, 0, 0, 0, 0, 0] </code></pre> <p>which explains the sorting. Last elements appear fi...
2
2016-08-19T10:15:15Z
[ "python", "numpy" ]
What does it mean to sort an array/matrix by the argmax as the key?
39,036,343
<p>I am struggling to understand the mechanism behind a function around the topic of sorting in numpy.</p> <pre><code> import numpy as np arr = [[8, 5, 9], [3, 9.5, 5], [5.5, 4, 3.5], [6, 2, 1], [6,1,2],[3,2,1],[8,5,3]] res = sorted(arr, key=np.argmax) </code></pre> <p>This gives m...
4
2016-08-19T10:08:40Z
39,036,526
<p>np.argmax gives you the argument of the maximum value. In your example, it is acting on each individual list of 3 items, for example</p> <pre><code>&gt;&gt;&gt; np.argmax([8,5,3]) 0 &gt;&gt;&gt; np.argmax([1,2,3]) 2 </code></pre>
0
2016-08-19T10:17:38Z
[ "python", "numpy" ]
Using reduce to shorten a for-loop
39,036,375
<p>From an array <code>Ns</code>, I'd like to derive an array <code>multipliers</code> as follows:</p> <pre><code>Ns = [3, 3, 6, 3] multipliers = [0]*len(Ns) multipliers[0] = 1 for n in range(1,len(Ns)): multipliers[n] = multipliers[n-1] * Ns[n-1] </code></pre> <p>The resulting array <code>multipliers</code> is ...
1
2016-08-19T10:10:17Z
39,036,609
<p>You could use <a href="https://docs.python.org/3/library/itertools.html#itertools.accumulate" rel="nofollow"><code>itertools.accumulate</code></a> with a custom accumulation function (Python 3 only, if you want to use Python 2 you could install <a href="https://github.com/kachayev/fn.py" rel="nofollow"><code>fn.py</...
5
2016-08-19T10:22:33Z
[ "python" ]
Using reduce to shorten a for-loop
39,036,375
<p>From an array <code>Ns</code>, I'd like to derive an array <code>multipliers</code> as follows:</p> <pre><code>Ns = [3, 3, 6, 3] multipliers = [0]*len(Ns) multipliers[0] = 1 for n in range(1,len(Ns)): multipliers[n] = multipliers[n-1] * Ns[n-1] </code></pre> <p>The resulting array <code>multipliers</code> is ...
1
2016-08-19T10:10:17Z
39,036,625
<p><code>reduce</code> give you just the final result of the reducing process, so if you want all the intermediate values you can use list comprehension as followed:</p> <pre><code>&gt;&gt;&gt; [reduce(lambda x,y:x*y, Ns[:i], 1) for i in range(len(Ns))] [1, 3, 9, 54] </code></pre> <p>but that isn't efficient since it...
2
2016-08-19T10:23:09Z
[ "python" ]
Using reduce to shorten a for-loop
39,036,375
<p>From an array <code>Ns</code>, I'd like to derive an array <code>multipliers</code> as follows:</p> <pre><code>Ns = [3, 3, 6, 3] multipliers = [0]*len(Ns) multipliers[0] = 1 for n in range(1,len(Ns)): multipliers[n] = multipliers[n-1] * Ns[n-1] </code></pre> <p>The resulting array <code>multipliers</code> is ...
1
2016-08-19T10:10:17Z
39,036,711
<p>You can simulate the behavior of <code>accumulate</code> (see @soon's answer) in Python 2 with <code>reduce</code>. You have to manage the list by yourself. </p> <pre><code>from functools import reduce Ns = [3, 3, 6, 3] multipliers = reduce(lambda l, x: l + [l[-1] * x], Ns[:-1], [1]) </code></pre>
3
2016-08-19T10:28:02Z
[ "python" ]
Using reduce to shorten a for-loop
39,036,375
<p>From an array <code>Ns</code>, I'd like to derive an array <code>multipliers</code> as follows:</p> <pre><code>Ns = [3, 3, 6, 3] multipliers = [0]*len(Ns) multipliers[0] = 1 for n in range(1,len(Ns)): multipliers[n] = multipliers[n-1] * Ns[n-1] </code></pre> <p>The resulting array <code>multipliers</code> is ...
1
2016-08-19T10:10:17Z
39,037,117
<p>As my comment and other answers mention, this is easy in Python 3, using <a href="https://docs.python.org/3/library/itertools.html#itertools.accumulate" rel="nofollow"><code>itertools.accumulate</code></a>. However, from your previous questions it appears that you're using Python 2.</p> <p>In Python, it's almost a...
2
2016-08-19T10:47:19Z
[ "python" ]
Embed a plot into GUI
39,036,462
<p>I found a website scikit-rf</p> <p><a href="http://scikit-rf.readthedocs.io/en/latest/tutorials/plotting.html" rel="nofollow">http://scikit-rf.readthedocs.io/en/latest/tutorials/plotting.html</a></p> <p>It can create smith plot by following code</p> <pre><code>ntwk = rf.Network("my data path") ntwk.plot_s_smith()...
1
2016-08-19T10:14:51Z
39,036,725
<p><a href="http://scikit-rf.readthedocs.io/en/latest/reference/generated/skrf.network.Network.plot_s_smith.html" rel="nofollow">Network.plot_s_smith</a> has an <code>ax</code> keyword to plot on existing <em>Axes</em> object. So you can modify your plot function like this:</p> <pre><code>def plot1(self): self.fi...
1
2016-08-19T10:28:40Z
[ "python", "pyqt4" ]
Is there a way to return a dataframe from Python to R ?
39,036,561
<p>I'm using the system() function to trigger a Python script from R, The python script writes a data frame into a .csv file which then needs to be imported to R. I was wondering if I could directly return the data frame from Python to R.</p> <p><strong>R</strong> </p> <pre><code>command = "python" path2script='"/Des...
1
2016-08-19T10:20:01Z
39,036,971
<p>The <a href="https://blog.rstudio.org/2016/03/29/feather/" rel="nofollow">Feather</a> format may accelerate your code.</p> <p>I am not aware of a way to have one dataframe in r that you can access in python. The reason I doubt it is possible is that it is two different software, so the interoperability of data is r...
0
2016-08-19T10:40:25Z
[ "python", "dataframe", "return" ]
Is there a way to return a dataframe from Python to R ?
39,036,561
<p>I'm using the system() function to trigger a Python script from R, The python script writes a data frame into a .csv file which then needs to be imported to R. I was wondering if I could directly return the data frame from Python to R.</p> <p><strong>R</strong> </p> <pre><code>command = "python" path2script='"/Des...
1
2016-08-19T10:20:01Z
39,039,817
<p>Install <a href="http://rpy2.bitbucket.org/" rel="nofollow">rpy</a>. <code>rpy</code> is a simple, easy-to-use interface to R from Python. It enables one to enjoy the elegance of Python programming while having access to the rich graphical and statistical capabilities of R. The <code>feather</code> format as suggest...
1
2016-08-19T13:05:06Z
[ "python", "dataframe", "return" ]
Django+python: Use Order by to Django RawQuery objects?
39,036,577
<p>I have almost 100 million product names present in DB.I am displaying 100 products in UI each time &amp; after scrolling showing next 100 &amp; so on. For this I have used Django RawQuery as my database(mysql) doesn't support <strong>distinct functionality</strong>.</p> <p>Here 'fetch' is callback function used in ...
0
2016-08-19T10:20:48Z
39,036,909
<p>I think what you are looking for is <a href="https://docs.djangoproject.com/en/1.10/topics/pagination/" rel="nofollow">pagination</a>. This is an essential technique when you want to display data in batches(pages). </p> <pre><code>from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger def listing...
1
2016-08-19T10:37:36Z
[ "python", "django", "sorting", "django-orm" ]
Django+python: Use Order by to Django RawQuery objects?
39,036,577
<p>I have almost 100 million product names present in DB.I am displaying 100 products in UI each time &amp; after scrolling showing next 100 &amp; so on. For this I have used Django RawQuery as my database(mysql) doesn't support <strong>distinct functionality</strong>.</p> <p>Here 'fetch' is callback function used in ...
0
2016-08-19T10:20:48Z
39,038,432
<p>Below is my try &amp; I got the desired answer.</p> <p>I fetch the data from database &amp; is stored in the form of array of dictionary in a list.</p> <p>Assuming the data stored format in a list:</p> <pre><code>l = [{'productName'='soap',id=1},{'productName'='Laptop',id=2}] </code></pre> <p>Below code snippet ...
0
2016-08-19T11:51:35Z
[ "python", "django", "sorting", "django-orm" ]
Is there any function available to modify the content occuring after "?" in django?
39,036,631
<p>I am creating a middleware at my server end to modify the API calls in the following manner</p> <pre> http://example.com/xyz?<b>jdvnjvjnfjAA536sddjjfjfjdjbdfjdh656dnjd5ndjvb</b> </pre> <p>should be converted by the middleware to:</p> <pre> http://example.com/xyz?<b>user=Tango&testID=123</b> </pre> <p>where the e...
0
2016-08-19T10:23:26Z
39,045,524
<p>You can't modify the query-string from the server side. You basically have 2 options:</p> <ol> <li>issue a redirect response to tell the browser to request a different URL. See the Django docs on <a href="https://docs.djangoproject.com/en/1.10/topics/http/shortcuts/#redirect" rel="nofollow">redirect</a>.</li> <li...
0
2016-08-19T18:22:41Z
[ "python", "django", "middleware" ]
.Net dll function returns just first char of string in Python
39,036,658
<p>I want to call <strong>.NET</strong> dll in my python project. I want to use a function which returns string and gets string parameter. But somehow I cant get the string I can just get the first char of the string and sometimes it raises <strong>following error:</strong></p> <pre><code>'charmap' codec can't encode ...
0
2016-08-19T10:24:54Z
39,125,557
<p>If you using Unmanaged Exports its Marshaling Example says ".Net will marshal these strings as single-byte Ansi" by default. If so, use c_char_p and pass byte strings from Python.</p>
1
2016-08-24T14:04:51Z
[ "python", ".net", "string", "dll", "ctypes" ]
IPython parallel DirectView.apply does not run in parallel
39,036,693
<p>For some reason I cannot get IPython parallel function <code>DirectView.apply()</code> to really parallelize a function call. <code>DirectView.map()</code> works as expected. Am I doing something wrong here? A working example script</p> <pre><code>import time from datetime import datetime from ipyparallel import Cl...
0
2016-08-19T10:26:52Z
39,038,524
<p>Seems that I misinterpreted the documentation. <a href="https://ipython.org/ipython-doc/3/api/generated/IPython.parallel.client.view.html#IPython.parallel.client.view.View.apply" rel="nofollow" title="Here">Here</a> it says that <em><code>apply(f, *args, **kwargs)</code> calls <code>f(*args, **kwargs)</code> on rem...
0
2016-08-19T11:56:42Z
[ "python", "parallel-processing", "ipython", "ipython-parallel" ]
Python 3 get value by index from json
39,036,801
<p>I need to get a value from json file <strong><em>by index</em></strong> (not by key)</p> <p>Here is my json file</p> <pre><code>{ "db": { "vendor": { "product": { "fruits": { "price": { "dollars": [ 10,...
0
2016-08-19T10:32:13Z
39,037,530
<p>I think the input string is wrong.</p> <pre><code>{ "d": { "items": { "vegatables": { "spinach": 120,12,23,3445 } } } } </code></pre> <p>JSON format doesn't has the the following input it must be changed to </...
0
2016-08-19T11:07:51Z
[ "python", "json", "python-3.x" ]
Python 3 get value by index from json
39,036,801
<p>I need to get a value from json file <strong><em>by index</em></strong> (not by key)</p> <p>Here is my json file</p> <pre><code>{ "db": { "vendor": { "product": { "fruits": { "price": { "dollars": [ 10,...
0
2016-08-19T10:32:13Z
39,039,595
<p>Here's a version that should work (depending on what you expect it to do):</p> <ul> <li><p>I changed the dict() to an OrderedDict() to preserve the original ordering</p></li> <li><p>I added <code>.values()</code> to the dictionary which is being indexed into. This method returns a list of all dictionaries which can...
1
2016-08-19T12:54:31Z
[ "python", "json", "python-3.x" ]
Graphviz: give color to lines with rainbow effect
39,036,808
<p>I have dataframe and I build graph using <code>graphviz</code></p> <pre><code>for id_key, group in df.groupby('ID'): f = Digraph('finite_state_machine', filename='fsm.gv', encoding='utf-8') f.body.extend(['rankdir=LR', 'size="5,5"']) f.attr('node', shape='box') for i in range(len(group)-1): f.edge(str(group['ca...
0
2016-08-19T10:32:27Z
39,039,139
<p>You can use one of the <a href="http://graphviz.org/doc/info/colors.html#brewer" rel="nofollow">brewer color schemes</a>. For example:</p> <pre><code>g = graphviz.Digraph(format='png') g.body.extend(["rankdir=LR"]) for i in range(9): g.edge(str(i),str(i+1),color="/spectral9/"+str(i+1)) g.render(filename="exampl...
2
2016-08-19T12:31:59Z
[ "python", "pandas", "graphviz" ]
How to embed a bokeh plot in web2py
39,036,835
<p>I have wasted quite some time and am unable to embed a bokeh plot in my web2py app.</p> <p>My current code:</p> <pre><code>def plot(): from bokeh.plotting import figure from bokeh.resources import CDN from bokeh.embed import file_html plot = figure() plot.circle([1,2], [3,4]) html = file_...
0
2016-08-19T10:33:44Z
39,083,164
<p>In your code, <code>html</code> is a string (of HTML markup). When a web2py action returns a string, that string is returned directly to the browser. If you are attempting to load that HTML as a complete web page, it will not work, as the Bokeh <code>file_html</code> function simply produces a <code>&lt;script&gt;</...
0
2016-08-22T15:14:59Z
[ "python", "web2py", "bokeh" ]
Is it possible to make all modules import a module implicitly?
39,036,874
<p>I love the type hinting from Python 3, but I'm really tired of writing <code>from typing import *</code> in all the modules that I write.</p> <p>Is it possible to wrap my app in a module, or anything, and implicitly import the module in all of my app modules?</p>
1
2016-08-19T10:35:54Z
39,037,270
<p>You could hijack the <code>builtins</code> module and put what you need there. That would make the code harder to maintain, as it would be harder to figure where these globals are coming from, or if they are accidentally clobbered. To be clear, it's possible, but I recommend <em>not</em> doing this.</p> <p>The main...
0
2016-08-19T10:54:58Z
[ "python", "python-3.x" ]
Running Popen under WSGI with Python 2.7.11, ModWSGI 4.4.6 and Apache 2.4.20 returns empty
39,036,880
<p>I have a WSGI application that does this:</p> <pre><code>p = Popen(["which", "java"], stdout=PIPE).stdout.readlines() </code></pre> <p>However it returns empty. My WSGI configuration is:</p> <pre><code>&lt;VirtualHost *:80&gt; ServerAdmin my@myserver.com WSGIPassAuthorization On # Deplo...
0
2016-08-19T10:36:08Z
39,037,457
<p>The problem here was that I was starting Apache with su (I use slackware) and under su java is not available. If I loggin with root and start apache then all works fine. </p>
0
2016-08-19T11:04:41Z
[ "python", "subprocess", "mod-wsgi" ]
python list as index for a nested list
39,036,925
<p>I have the following two lists:</p> <pre><code>l1 = [2, 3, 2] l2 = [0, [0, 1], [0, 1, 0, [0, 1, [0, 0]]]] </code></pre> <p>How can I use the first list as a tree index, in order to append an item to the second list, like doing</p> <pre><code>l2[2][3][2].append(0) </code></pre>
1
2016-08-19T10:38:25Z
39,037,067
<p>You could use <a href="https://docs.python.org/3/library/functools.html#functools.reduce" rel="nofollow"><code>reduce</code></a> function:</p> <pre><code>In [1]: l1 = [2, 3, 2] In [2]: l2 = [0, [0, 1], [0, 1, 0, [0, 1, [0, 0]]]] In [3]: from functools import reduce In [4]: reduce(lambda l, i: l[i], l1, l2) Out[4...
1
2016-08-19T10:44:56Z
[ "python", "list", "tree", "nested", "append" ]
python list as index for a nested list
39,036,925
<p>I have the following two lists:</p> <pre><code>l1 = [2, 3, 2] l2 = [0, [0, 1], [0, 1, 0, [0, 1, [0, 0]]]] </code></pre> <p>How can I use the first list as a tree index, in order to append an item to the second list, like doing</p> <pre><code>l2[2][3][2].append(0) </code></pre>
1
2016-08-19T10:38:25Z
39,037,086
<p>There is no standard way to do that, but this will work:</p> <pre><code>from functools import reduce from operator import getitem def tree_index(tree, index): return reduce(getitem, index, tree) tree_index(l2, l1).append(0) </code></pre> <p>As a bonus, the <code>tree_index</code> function also works for dict...
3
2016-08-19T10:45:26Z
[ "python", "list", "tree", "nested", "append" ]
python list as index for a nested list
39,036,925
<p>I have the following two lists:</p> <pre><code>l1 = [2, 3, 2] l2 = [0, [0, 1], [0, 1, 0, [0, 1, [0, 0]]]] </code></pre> <p>How can I use the first list as a tree index, in order to append an item to the second list, like doing</p> <pre><code>l2[2][3][2].append(0) </code></pre>
1
2016-08-19T10:38:25Z
39,037,269
<p>This should work</p> <pre><code>def tree_append(tree, index_list', val=None): for index in index_list: tree = tree[index] tree.append(val) l1 = [2, 3, 2] l2 = [0, [0, 1], [0, 1, 0, [0, 1, [0, 0]]]] tree_append(l2, l1, val=0) &gt;&gt; l2 [0, [0, 1], [0, 1, 0, [0, 1, [0, 0. 0]]]] </code></pre>
1
2016-08-19T10:54:58Z
[ "python", "list", "tree", "nested", "append" ]
python list as index for a nested list
39,036,925
<p>I have the following two lists:</p> <pre><code>l1 = [2, 3, 2] l2 = [0, [0, 1], [0, 1, 0, [0, 1, [0, 0]]]] </code></pre> <p>How can I use the first list as a tree index, in order to append an item to the second list, like doing</p> <pre><code>l2[2][3][2].append(0) </code></pre>
1
2016-08-19T10:38:25Z
39,037,430
<p>Do this only if you know what you're doing:</p> <pre><code>l1 = [2, 3, 2] l2 = [0, [0, 1], [0, 1, 0, [0, 1, [0, 0]]]] str1=repr(l1) str1=str1.replace(', ','][') # str1=[2][3][2] eval(repr(l2)+str1) # or var=exec(repr(l2)+str1) </code></pre>
0
2016-08-19T11:02:59Z
[ "python", "list", "tree", "nested", "append" ]
python list as index for a nested list
39,036,925
<p>I have the following two lists:</p> <pre><code>l1 = [2, 3, 2] l2 = [0, [0, 1], [0, 1, 0, [0, 1, [0, 0]]]] </code></pre> <p>How can I use the first list as a tree index, in order to append an item to the second list, like doing</p> <pre><code>l2[2][3][2].append(0) </code></pre>
1
2016-08-19T10:38:25Z
39,042,336
<p>For some strange reason, I immediately thought of a recursive routine, but essentially it does does what Kostas is doing, I just find it easier to follow :</p> <pre><code>def tree_appender(tree, location, thing): sub_tree_index = location.pop(0) if len(location) &gt; 0: tree_appender(tree[sub_tree_i...
0
2016-08-19T15:06:35Z
[ "python", "list", "tree", "nested", "append" ]
How do I add user data to url in Django?
39,037,021
<p>I've got a function based view in Django called <code>userView</code></p> <pre><code>@login_required(login_url='/login/') def userView(request): user = None if request.user.is_authenticated(): user = request.user user_id = user.pk return render(request, "user_view.html", {'user': user}...
0
2016-08-19T10:43:03Z
39,037,675
<p>I am not a Django expert but my guess is you want to redirect the user to his 'home page' after he is logged in. That can be done using the <a href="https://docs.djangoproject.com/en/1.10/topics/http/shortcuts/#redirect" rel="nofollow"><code>redirect()</code></a> method </p> <pre><code>@login_required(login_url='/l...
2
2016-08-19T11:14:56Z
[ "python", "django" ]
In Python: imports shenanigans (import subfolder.module in folder, use in subfolder/module2.py)
39,037,069
<h1> Ok, this is not very clear at all. Allow me to rephrase.</h1> <p><strong>Quick note</strong>: <em>"Solved" while writing this question. Will accept <strong>answer</strong> with inputs <strong>regarding best practices</strong>.</em></p> <p><strong>Original quick note</strong>: <em>This is probably a duplicate. I...
0
2016-08-19T10:44:57Z
39,037,070
<p>As noted in the question, here is what is needed to fix the issue of the unavailable module B in module A.</p> <p>Simply replace the imports section in <code>A.py</code> with the following:</p> <pre><code>## Imports if __name__ == "__main__": from B import ClassB as clB from C import ClassC as clC el...
0
2016-08-19T10:44:57Z
[ "python", "python-import" ]
Django migration can't find GDALRaster
39,037,351
<p>I took over a project with Django, Django REST framework and Leaflet to store drawn path in a database. Installing Django in an <code>virtualenv</code> and trying to migrate it raises:</p> <blockquote> <p>File "D:\SHK\ElektroClean\venv\lib\site-packages\django\contrib\gis\db\backends\postgis\operations.py", line ...
0
2016-08-19T10:58:32Z
39,276,546
<p>solved did mistakes on installing GDAL -.-</p>
0
2016-09-01T16:25:19Z
[ "python", "django", "gdal" ]
ansible "the directory /usr/lib/ is not empty, refusing to convert it"
39,037,353
<p>I'm trying to create symlinks with ansible:</p> <p><code>file: src=/usr/lib/x86_64-linux-gnu/{{ item.src }} dest=/usr/lib/ state=link force=yes with_items: - { src: 'libz.so'} - { src: 'libfreetype.so'} - { src: 'libjpeg.so'}</code></p> <p>and...
0
2016-08-19T10:58:35Z
39,037,684
<p>You are trying to link the whole <code>/usr/lib</code> directory to the file. </p> <p>Append <code>{{ item.src }}</code> to your dest</p> <pre><code>file: src=/usr/lib/x86_64-linux-gnu/{{ item.src }} dest=/usr/lib/{{ item.src }} state=link force=yes with_items: - { src: 'libz.so'} - { src: 'libfreetype.so'} ...
5
2016-08-19T11:15:13Z
[ "python", "debian", "ansible" ]
What is wrong with my Neo4j query for Py2neo?
39,037,427
<p>This is my query for Py2neo for Neo4j database</p> <pre><code>MATCH (u:User),(p:Prize),(ca:Category) CREATE (ch:Challenge {chid:'dassdshhhhasdasda',challenge_title:'Exm 2015', total_question_per_user:200,challenge_status:1,timestamp:'1471516538.4643',date:'2016-08-18'}), (p)-[:BELONG {rank:3}]-&gt;(ch),(ca)-[:BELON...
0
2016-08-19T11:02:52Z
39,040,041
<p>You are using the <code>WHERE</code> clause in the wrong spot. The where clause needs to be used in conjunction with the <code>MATCH</code> statement and not the <code>CREATE</code>.</p> <p>Something like this...</p> <pre><code>MATCH (u:User),(p:Prize),(ca:Category) WHERE u.username = 'xyz@gmail.com' AND p.pid ...
1
2016-08-19T13:15:26Z
[ "python", "neo4j", "py2neo" ]
Gzip compression and decompression without any encoding
39,037,445
<p>I want to decompress a string in java which was gzip compressed in python.</p> <p>Normally, I use base64 encoding on compressed string in python and then decode that compressed string before performing decompression in java. This works fine while using base64 encoding.</p> <p>But is there a way to decompress a str...
2
2016-08-19T11:03:57Z
39,038,117
<blockquote> <p>Not every byte[] can be converted to a string, and the conversion back could give other bytes.</p> </blockquote> <p>Please define encoding explicitly when compress and do the same when decompress. Otherwise your <code>OS</code>, <code>JVM</code> etc... will do it for you. And probably will mess it ...
0
2016-08-19T11:37:31Z
[ "java", "python", "base64", "gzip", "decompression" ]
Bar plot width inconsistency
39,037,446
<p>please don't be too harsh. Could someone explain me why the colors of bars in these two plots are so different?</p> <pre><code>import numpy as np import datetime as dt import matplotlib.pyplot as plt from matplotlib import rcParams rcParams.update({'figure.autolayout': True}) plt.style.use('ggplot') def plot3(): ...
0
2016-08-19T11:04:04Z
39,038,770
<p>Bars have both <code>facecolor</code> and <code>edgecolor</code>, see the docs <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.bar" rel="nofollow">here</a>.</p> <p>It seems that <code>set_color()</code> sets <em>both</em> edge and face colour of the bar, so in your first chart the bars are wide...
0
2016-08-19T12:10:44Z
[ "python", "matplotlib" ]
Alternative of ST_DWithin of PostGIS in python shapely
39,037,571
<p>I've two linestrings Line1,Line2.</p> <pre><code>line1 = "LINESTRING(72.863221 18.782499,72.863736 18.770147,72.882275 18.756169,72.881417 18.750805,72.878842 18.736987,72.874379 18.709512,72.860989 18.679593,72.864422 18.653897)" line2 = "LINESTRING(72.883133 18.780793,72.882103 18.760314,72.862534 18.716422,72.86...
1
2016-08-19T11:09:49Z
39,408,449
<p>As far as I know, shapely only supports operations in planar coordinates (no geography types). However, for LineStrings which are not too large so that the curvature of the globe can be neglected, one could partially "circumvent" this by:</p> <ul> <li><p>working in some planar projection (for example directly in th...
0
2016-09-09T09:37:31Z
[ "python", "postgresql", "postgis", "shapely" ]
How to prevent nose to check imported modules like matplotlib?
39,037,603
<p>I am using nose to my test python code. Each time I execute nosetests, nose test also all imported modules like matplotlib, pandas, etc. .</p> <p>This may take a while.</p> <p>So how to skip imported modules explicitly?</p> <p>Thanks in advance.</p> <p>Example:</p> <p>Code that should be tested:</p> <pre><code...
0
2016-08-19T11:11:04Z
39,038,267
<p>The option you need is:</p> <p><code>--cover-package=your_python_package_name</code></p> <p>When you run your nose tests, you can supply either just one, or a list of these parameters to restrict nose to the listed packages of yours:</p> <p><code>nose --cover-package=one_package --cover-package=other_package</cod...
1
2016-08-19T11:44:27Z
[ "python", "nose" ]
Upload raw JSON data on Google Cloud Storage using Python code
39,037,616
<p>I am trying to upload raw JSON data on Google Cloud Platform. But I am getting this error: </p> <pre><code>TypeError: must be string or buffer, not dict </code></pre> <p>Code:</p> <pre><code>def upload_data(destination_path): credentials = GoogleCredentials.get_application_default() service = discovery.bu...
0
2016-08-19T11:11:31Z
39,037,759
<p>in your example, <code>content</code> is a dict. Perhaps you want to use json?</p> <pre><code>content = json.dumps({'name': 'test'}) </code></pre>
3
2016-08-19T11:19:31Z
[ "python", "json", "google-app-engine", "cloud", "google-cloud-storage" ]
Python - Basic vs extended slicing
39,037,663
<p>When experimenting with slicing I noticed a strange behavior in Python 2.7:</p> <pre><code>class A: def __getitem__(self, i): print repr(i) a=A() a[:] #Prints slice(0, 9223372036854775807, None) a[::] #prints slice(None, None, None) a[:,:] #prints (slice(None, None, None), slice(None, None, None)) </cod...
8
2016-08-19T11:14:23Z
39,037,810
<p>For Python 2 <code>[:]</code> still calls <a href="https://docs.python.org/2/reference/datamodel.html#object.__getslice__" rel="nofollow"><code>__getslice__(self, i, j)</code></a> (deprecated) and this is documented to return a slice <code>slice(0, sys.maxsize, None)</code> when called with default parameters:</p> ...
9
2016-08-19T11:22:02Z
[ "python", "python-2.7" ]
RegEx Ignore a commented line.
39,037,782
<p>I am trying to parse the following text</p> <pre><code># ---------------------------------------------------------------------------- # # Packages # ---------------------------------------------------------------------------- # set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_1_test_1_qi...
1
2016-08-19T11:20:28Z
39,037,895
<p>To ignore commented lines, you have to start matching at the start of the line and match anything but <code>#</code>:</p> <pre><code>^[^#\n]*(?:(?&lt;=_FILE).+"(.+)") </code></pre> <p>Or just</p> <pre><code>^[^#\n]*_FILE.+"(.+)" </code></pre> <p>Both patterns need the multiline flag <code>m</code>.</p>
1
2016-08-19T11:26:25Z
[ "python", "regex", "python-3.x" ]
RegEx Ignore a commented line.
39,037,782
<p>I am trying to parse the following text</p> <pre><code># ---------------------------------------------------------------------------- # # Packages # ---------------------------------------------------------------------------- # set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_1_test_1_qi...
1
2016-08-19T11:20:28Z
39,038,208
<p>It seems that the lines you target have always the same format, you can avoid the regex with a field approach:</p> <pre><code>def notcomm(fh): for line in fh: line = line.lstrip() if line.startswith('#') or line == "": continue yield(line) with open('yourfile.txt', 'r') as f...
0
2016-08-19T11:41:32Z
[ "python", "regex", "python-3.x" ]
RegEx Ignore a commented line.
39,037,782
<p>I am trying to parse the following text</p> <pre><code># ---------------------------------------------------------------------------- # # Packages # ---------------------------------------------------------------------------- # set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_1_test_1_qi...
1
2016-08-19T11:20:28Z
39,039,697
<p>If you want to stick with regular expressions, just add <a href="https://regex101.com/r/rA7mK9/1" rel="nofollow"><strong>another lookahead</strong></a>:</p> <pre><code>(?=.*_FILE)(?!^#)[^"]*"([^"]*)" </code></pre> <p><hr> In <code>Python</code>, this is rather simple:</p> <pre><code>import re rx = re.compile(r'(?...
2
2016-08-19T12:58:58Z
[ "python", "regex", "python-3.x" ]
Tuple compare in python
39,037,838
<p>I have I have simple code looking like:</p> <pre><code>&gt;&gt;&gt; a = ('1', '2', '3', '4', '5') &gt;&gt;&gt; b = ('2', '6') &gt;&gt;&gt; &gt;&gt;&gt; def comp(list1, list2): ... for val in list1: ... if val in list2: ... return True ... return False ... &gt;&gt;&gt; print comp(a, b) ...
-2
2016-08-19T11:23:39Z
39,038,410
<p>The statement return statement exits a function, optionally passing back an expression to the caller. </p> <p>so if you write :</p> <pre><code>a = ('1', '2', '3', '4', '5') b = ('6', '2') def comp(list1, list2): for val in list1: if val in list2: return True return False print comp(a, ...
1
2016-08-19T11:50:46Z
[ "python", "compare", "tuples" ]
Tuple compare in python
39,037,838
<p>I have I have simple code looking like:</p> <pre><code>&gt;&gt;&gt; a = ('1', '2', '3', '4', '5') &gt;&gt;&gt; b = ('2', '6') &gt;&gt;&gt; &gt;&gt;&gt; def comp(list1, list2): ... for val in list1: ... if val in list2: ... return True ... return False ... &gt;&gt;&gt; print comp(a, b) ...
-2
2016-08-19T11:23:39Z
39,038,417
<p>You should Change your code a little bit. May this will be of some help.</p> <pre><code>def comp(list1, list2): for val in list1: if val not in list2: return False return True </code></pre>
0
2016-08-19T11:50:55Z
[ "python", "compare", "tuples" ]
Python and SQL - inserting and reading values
39,037,893
<p>I have a problem with my code. I'm making a windowed application. Right now, I need to insert data to table in database and then show it to me (with SELECT). I have 2 fields to input the Name and Password for user (ID is calculated based on number of entries in the table) and a button to trigger the input. Then I ha...
1
2016-08-19T11:26:19Z
39,038,070
<p><code>__call__</code> is an internal method used to call objects and functions. You can probably ignore that.</p> <p>A cursor's <code>execute</code> method normally returns some innocuous value like the number of rows affected, and the results are returned by a separate call to one of its <code>fetch*</code> method...
0
2016-08-19T11:35:08Z
[ "python", "sql", "sqlite3", "window" ]
Convert list of strings into integers with Regular Expression
39,037,919
<p>I am currently trying to understand Regular Expressions. I have a hard time understanding how I should solve this:</p> <pre><code>import re fhand = open("assign11.txt") lst = list() for line in fhand: line = line.rstrip() x = re.findall("([\d]+)", line) if not len(x) &gt; 0: continue numlist = int...
-2
2016-08-19T11:27:29Z
39,037,976
<p>Use a list comprehension to convert each item in the list to an integer in a new list:</p> <pre><code>list_of_strings = ['1', '11', '123', '-12'] list_of_ints = [int(x) for x in list_of_strings] &gt;&gt;&gt; list_of_ints [1, 11, 123, -12] </code></pre> <p>That's the basic idea. Applying that to sum all of the inte...
0
2016-08-19T11:30:46Z
[ "python", "regex" ]
Convert list of strings into integers with Regular Expression
39,037,919
<p>I am currently trying to understand Regular Expressions. I have a hard time understanding how I should solve this:</p> <pre><code>import re fhand = open("assign11.txt") lst = list() for line in fhand: line = line.rstrip() x = re.findall("([\d]+)", line) if not len(x) &gt; 0: continue numlist = int...
-2
2016-08-19T11:27:29Z
39,038,043
<p>Converting a list of strings to a list of integers is done with the <code>map</code> function. <code>map</code> takes two arguments: the list as well as a function which you wish to apply to each element in the list. </p> <pre><code>map(int, ['1','2']) &gt; [1,2] </code></pre> <p>An example of your full process:</...
1
2016-08-19T11:34:12Z
[ "python", "regex" ]
HBase and Spark - NullPointerException while trying to write to table
39,038,139
<p>I'm using HDP with Ambari on 3 nodes cluster. I tried to save data to Hbase table from Spark using example code (<a href="https://github.com/apache/spark/blob/v1.5.1/examples/src/main/python/hbase_outputformat.py" rel="nofollow">link</a>) but my job failed.</p> <p>Command I used: </p> <pre><code>spark-submit --ma...
0
2016-08-19T11:39:11Z
39,040,884
<p>Is the HBase config on your classpath or are you hitting zookeeper by luck since you are on a zookeeper node (localhost)?</p> <p>We have some examples of Spark Streaming with HBase on our example code site if you are interested.</p> <p><a href="https://github.com/splicemachine/splice-community-sample-code" rel="no...
1
2016-08-19T13:56:52Z
[ "python", "apache-spark", "hbase", "pyspark" ]
How to set the size of the "pure" figure (without axis ticks or title) in matplotlib
39,038,228
<p>I want to draw a figure with width:height=1:1, and set the size as</p> <pre><code>plt.figure(figsize=(10,10)) </code></pre> <p>However, it sets the size of the complete figure, including title and x-,y- ticks. I hope the size of the "pure" figure without any title, x-,y- ticks is 1:1. How can I do? Thanks!</p>
1
2016-08-19T11:42:19Z
39,058,705
<p>Using this setting should work:</p> <pre><code>plt.gca().set_aspect('equal') </code></pre> <p>For example:</p> <p><a href="http://i.stack.imgur.com/RHMsd.png" rel="nofollow"><img src="http://i.stack.imgur.com/RHMsd.png" alt="enter image description here"></a></p> <p>It might not look square but it is!</p> <pre>...
0
2016-08-20T21:05:40Z
[ "python", "matplotlib" ]
Function chaining in Python
39,038,358
<p>On codewars.com I encountered the following task:</p> <blockquote> <p>Create a function <code>add</code> that adds numbers together when called in succession. So <code>add(1)</code> should return <code>1</code>, <code>add(1)(2)</code> should return <code>1+2</code>, ...</p> </blockquote> <p>While I'm familiar wi...
64
2016-08-19T11:48:30Z
39,038,455
<p>I don't know whether this is <em>function</em> chaining as much as it's <em>callable</em> chaining, but, since functions <em>are</em> callables I guess there's no harm done. Either way, there's two ways I can think of doing this:</p> <h3>Sub-classing <code>int</code> and defining <code>__call__</code>:</h3> <p>The...
75
2016-08-19T11:53:03Z
[ "python", "function", "python-3.x" ]
Function chaining in Python
39,038,358
<p>On codewars.com I encountered the following task:</p> <blockquote> <p>Create a function <code>add</code> that adds numbers together when called in succession. So <code>add(1)</code> should return <code>1</code>, <code>add(1)(2)</code> should return <code>1+2</code>, ...</p> </blockquote> <p>While I'm familiar wi...
64
2016-08-19T11:48:30Z
39,038,540
<p>If you want to define a function to be called multiple times, first you need to return a callable object each time (for example a function) otherwise you have to create your own object by defining a <code>__call__</code> attribute, in order for it to be callable.</p> <p>The next point is that you need to preserve a...
13
2016-08-19T11:57:30Z
[ "python", "function", "python-3.x" ]
Function chaining in Python
39,038,358
<p>On codewars.com I encountered the following task:</p> <blockquote> <p>Create a function <code>add</code> that adds numbers together when called in succession. So <code>add(1)</code> should return <code>1</code>, <code>add(1)(2)</code> should return <code>1+2</code>, ...</p> </blockquote> <p>While I'm familiar wi...
64
2016-08-19T11:48:30Z
39,039,586
<p>You can hate me, but here is a one-liner :)</p> <pre><code>add = lambda v: type("", (int,), {"__call__": lambda self, v: self.__class__(self + v)})(v) </code></pre> <p>Edit: Ok, how this works? The code is identical to answer of @Jim, but everything happens on a single line.</p> <ol> <li><code>type</code> can be ...
16
2016-08-19T12:54:13Z
[ "python", "function", "python-3.x" ]
Function chaining in Python
39,038,358
<p>On codewars.com I encountered the following task:</p> <blockquote> <p>Create a function <code>add</code> that adds numbers together when called in succession. So <code>add(1)</code> should return <code>1</code>, <code>add(1)(2)</code> should return <code>1+2</code>, ...</p> </blockquote> <p>While I'm familiar wi...
64
2016-08-19T11:48:30Z
39,139,256
<p>The pythonic way to do this would be to use dynamic arguments:</p> <pre><code>def add(*args): return sum(args) </code></pre> <p>This is not the answer you're looking for, and you may know this, but I thought I would give it anyway because if someone was wondering about doing this not out of curiosity but for w...
3
2016-08-25T07:33:30Z
[ "python", "function", "python-3.x" ]
Regular Expression to capture strings between given string anchors
39,038,371
<p>I have a log file I'm trying to parse with regex (python). Each line contains tags "BEGIN" and "END" somewhere on the line. In addition, a line may contain one or more "VALUE" tags somewhere between the "BEGIN" and "END" tags. If there is no "VALUE" tag on a given line, I would like to capture the string between "BE...
2
2016-08-19T11:49:15Z
39,038,896
<p>An easy approach without full use of regex, catch everything between BEGIN and END and then split it with VALUE.</p> <pre><code>&gt;&gt;&gt;test_cases = ['words we can ignoreBEGINvalue1VALUEvalue with spaceVALUEvalue_with_@VALUElastvalueENDwords we can ignore', 'BEGINvalue1VALUEVALUEVALUElastvalueENDwords we can ig...
1
2016-08-19T12:18:00Z
[ "python", "regex" ]
Replace whole word Python (only variable)
39,038,468
<p>I am trying to do a code which replace only whole word in string variable.First of all I found <code>re.sub</code> solution but there was no mentioned about variable inside. Now my solution looks (it does not replace whole word): </p> <pre><code>for index in (range(len(lista)): query=query.replace(lista[index]...
0
2016-08-19T11:53:48Z
39,038,717
<blockquote> <p>I want to replace value in lista[index] with value from VAR -> variable.</p> </blockquote> <p>From this, I <em>think</em> you're looking for something along these lines:</p> <pre><code>for index in (range(len(lista))): lista[index] = var </code></pre> <p>This changes all the items in the list...
0
2016-08-19T12:07:27Z
[ "python", "replace" ]
Replace whole word Python (only variable)
39,038,468
<p>I am trying to do a code which replace only whole word in string variable.First of all I found <code>re.sub</code> solution but there was no mentioned about variable inside. Now my solution looks (it does not replace whole word): </p> <pre><code>for index in (range(len(lista)): query=query.replace(lista[index]...
0
2016-08-19T11:53:48Z
39,038,895
<p>I think this should work:</p> <pre><code>for word in alist: query = re.sub(r'\b'+word+r'\b',var,query) </code></pre>
1
2016-08-19T12:17:58Z
[ "python", "replace" ]
Replace whole word Python (only variable)
39,038,468
<p>I am trying to do a code which replace only whole word in string variable.First of all I found <code>re.sub</code> solution but there was no mentioned about variable inside. Now my solution looks (it does not replace whole word): </p> <pre><code>for index in (range(len(lista)): query=query.replace(lista[index]...
0
2016-08-19T11:53:48Z
39,038,937
<p>You can compile a regex that matches any of the words in <code>lista</code>. </p> <pre><code>import re query = "Select Information,AdditionalInformation,Price from Table" lista = ["Information", "Price"] var = "hide" pat = re.compile(r'\b' + '|'.join(lista) + r'\b') query = pat.sub(var, query) print(query) </code...
2
2016-08-19T12:20:52Z
[ "python", "replace" ]
Replace whole word Python (only variable)
39,038,468
<p>I am trying to do a code which replace only whole word in string variable.First of all I found <code>re.sub</code> solution but there was no mentioned about variable inside. Now my solution looks (it does not replace whole word): </p> <pre><code>for index in (range(len(lista)): query=query.replace(lista[index]...
0
2016-08-19T11:53:48Z
39,039,116
<p>As kaasias wrote, just change the the elements of the list with this code:</p> <pre><code>for index in (range(len(lista))): lista[index] = var </code></pre> <p>and make sure you create your query with the new elements of the list.</p> <pre><code>query = "SELECT " + lista[0] + ", " + AdditionalInformation + ",...
0
2016-08-19T12:30:57Z
[ "python", "replace" ]
How to run code in another AppDomain? I need to sandbox my IronPython code
39,038,499
<p>I have some IronPython code, and im passing variables to it and want to receive a result from python. I managed to get the result from IronPython when i create an engine in the current domain:</p> <pre><code>ScriptEngine pyEngine = IronPython.Hosting.Python.CreateEngine() </code></pre> <p>then i just take the resu...
0
2016-08-19T11:55:37Z
39,039,471
<p>Yes - cross domain variables are serialized between domains unless they inherit from MarshallByRefObject as explained here <a href="http://stackoverflow.com/questions/2206961/sharing-data-between-appdomains">Sharing data between AppDomains</a></p> <p>Your second question is "can I ... do some C# stuff" - yes; you c...
1
2016-08-19T12:48:57Z
[ "c#", "python", "ironpython", "sandbox" ]
Receive messages from Telegram Bot to Google App Engine via Cloud Endpoint
39,038,516
<p>I have a python Google App Engine application that receive incoming message from Telegram Bot via webhook. I'm using Cloud Endpoint to receive request, so I use the Google Protocol RPC to manage the request and the response. </p> <p>The json incoming update from Telegram that contain the message have a field called...
1
2016-08-19T11:56:23Z
39,106,635
<p>I would suggest to use a python library like <a href="https://pypi.python.org/pypi/python-telegram-bot" rel="nofollow">python-telegram-bot</a>. The author of the library <a href="https://github.com/python-telegram-bot/python-telegram-bot/blob/master/telegram/message.py#L33" rel="nofollow">renamed</a> the Python-inco...
1
2016-08-23T16:43:13Z
[ "python", "google-app-engine", "telegram-bot" ]
Using a single replacement operation replace all leading tabs with spaces
39,038,569
<p>In my text I want to replace all leading tabs with two spaces but leave the non-leading tabs alone.</p> <p>For example:</p> <pre><code>a \tb \t\tc \td\te f\t\tg </code></pre> <p>(<code>"a\n\tb\n\t\tc\n\td\te\nf\t\tg"</code>)</p> <p>should turn into:</p> <pre><code>a b c d\te f\t\tg </code></pre> <p>(<c...
4
2016-08-19T11:58:44Z
39,038,654
<p>You may match the tabs at the start of the lines, and use a lambda inside <code>re.sub</code> to replace with the double spaces multiplied by the length of the match:</p> <pre><code>import re s = "a\n\tb\n\t\tc\n\td\te\nf\t\tg"; print(re.sub(r"^\t+", lambda m: " "*len(m.group()), s, flags=re.M)) </code></pre> <p>...
8
2016-08-19T12:03:33Z
[ "python", "regex" ]
Using a single replacement operation replace all leading tabs with spaces
39,038,569
<p>In my text I want to replace all leading tabs with two spaces but leave the non-leading tabs alone.</p> <p>For example:</p> <pre><code>a \tb \t\tc \td\te f\t\tg </code></pre> <p>(<code>"a\n\tb\n\t\tc\n\td\te\nf\t\tg"</code>)</p> <p>should turn into:</p> <pre><code>a b c d\te f\t\tg </code></pre> <p>(<c...
4
2016-08-19T11:58:44Z
39,039,515
<p>It is also possible to do this without regex using <code>replace()</code> in a one liner:</p> <pre><code>&gt;&gt;&gt; s = "a\n\tb\n\t\tc\n\td\te\nf\t\tg" &gt;&gt;&gt; "\n".join(x.replace("\t"," ",len(x)-len(x.lstrip("\t"))) for x in s.split("\n")) 'a\n b\n c\n d\te\nf\t\tg' </code></pre>
1
2016-08-19T12:50:57Z
[ "python", "regex" ]
Using a single replacement operation replace all leading tabs with spaces
39,038,569
<p>In my text I want to replace all leading tabs with two spaces but leave the non-leading tabs alone.</p> <p>For example:</p> <pre><code>a \tb \t\tc \td\te f\t\tg </code></pre> <p>(<code>"a\n\tb\n\t\tc\n\td\te\nf\t\tg"</code>)</p> <p>should turn into:</p> <pre><code>a b c d\te f\t\tg </code></pre> <p>(<c...
4
2016-08-19T11:58:44Z
39,592,690
<p>This here is kinda crazy, but it works:</p> <pre><code>"\n".join([ re.sub(r"^(\t+)"," "*(2*len(re.sub(r"^(\t+).*","\1",x))),x) for x in "a\n\tb\n\t\tc\n\td\te\nf\t\tg".splitlines() ]) </code></pre>
1
2016-09-20T11:18:40Z
[ "python", "regex" ]
Deep learning: how can I save the computed model for prediction and how to load it later
39,038,594
<p>I am studying the main concepts of deep learning using the theano library. I am trying to run this code that appears in the tutorial. This piece of code runs for hours. How should I save the computed model for later use and how exactly I should load it back? </p> <pre><code>import cPickle import gzip import os impo...
0
2016-08-19T11:59:43Z
39,046,014
<p>Generally, you want to find everywhere that a shared variable is created (<code>theano.shared</code>), and pickle the values. If you've got a shared variable <code>a</code>, you can use <code>a.get_value</code> to get the value of the variable, then pickle this (or use <code>numpy.save</code> or <code>numpy.savez</c...
0
2016-08-19T18:56:15Z
[ "python", "deep-learning", "theano" ]
Deep learning: how can I save the computed model for prediction and how to load it later
39,038,594
<p>I am studying the main concepts of deep learning using the theano library. I am trying to run this code that appears in the tutorial. This piece of code runs for hours. How should I save the computed model for later use and how exactly I should load it back? </p> <pre><code>import cPickle import gzip import os impo...
0
2016-08-19T11:59:43Z
39,106,645
<pre><code># in evaluate_lenet5 block, save your model after training finish open('layer0_model.pkl', 'wb') as f0: pickle.dump(layer0,f0) open('layer1_model.pkl', 'wb') as f1: pickle.dump(layer1,f1) open('layer2_model.pkl', 'wb') as f2: pickle.dump(layer0,f2) open('layer3_model.pkl', 'wb') as f3: pickle.dump(layer0,f3)...
0
2016-08-23T16:43:39Z
[ "python", "deep-learning", "theano" ]
Python socket server for multiple connection handling
39,038,719
<p>Can some one suggest a good example for socket server which can handle multiple connections with threading from python. (Live connection (like server-client ping-pong) that will handle from threads)</p>
-1
2016-08-19T12:07:39Z
39,040,235
<p>Using the <code>SocketServer</code> module you can create a server that handles multiple connections. Using <a href="https://docs.python.org/3/library/socketserver.html#asynchronous-mixins" rel="nofollow">Asynchronous mixins</a> you can start new threads for each connection. There is a very good example in the Pytho...
0
2016-08-19T13:24:41Z
[ "python", "socketserver", "python-sockets" ]
Data not displaying correctly in my template for django
39,038,761
<p>I need help figuring out how to set up my html table in a way that is giving me issues if anyone can help me figure out how to fix it and make it look like the second picture would be awesome. </p> <p>*Side note I am using Django </p> <p>So first off I have three models that I will be using in this view/template. ...
1
2016-08-19T12:09:57Z
39,042,178
<p>Ok so knowing that I think this is your problem here:</p> <pre><code>&lt;tbody&gt; {% for desc in dim_description.all %} &lt;tr&gt; &lt;td&gt; {{ desc }}&lt;/td&gt; {% for r_c in complete_data %} &lt;td&gt; {{ r_c.reading }} &lt;/td&gt; {% endfor %} {% endfor %} &lt;/tr...
1
2016-08-19T14:59:37Z
[ "python", "html", "django" ]
How to access one2many fields values on Kanban view odoo 0.8?
39,038,862
<p>I need to loop over the records of o2m filed in kanban to show what I need from the other model.</p> <p>all i need in kanban view to do this </p> <pre><code>&lt;t t-foreach="o2m_field" t-as"record"&gt; &lt;t t-esc="record.name"/&gt; &lt;/t&gt; </code></pre> <p>Is that possible to do it?</p>
-2
2016-08-19T12:15:58Z
39,049,502
<p>Yes you can. </p> <p>This question is a duplicate to <a href="http://stackoverflow.com/questions/30805475/is-it-possible-to-show-an-one2many-field-in-a-kanban-view-in-odoo">Is it possible to show an One2many field in a kanban view in Odoo?</a> but here is a link to a module from Serpent Consulting which will be abl...
1
2016-08-20T00:57:17Z
[ "python", "xml", "odoo-8", "kanban" ]
How to change font size of the annotation in seaborn jointplot?
39,039,000
<p>I am making a jointplot with a regression line using -</p> <pre><code>sns.jointplot(xdata,ydata,kind='reg', order=2,ylim=[-1,1],xlim=[-1,1],annot_kws={"loc": 4}) </code></pre> <p>I can change the location using <code>annot_kws</code>, but cannot change the font size. How do I change the font size? </p>
1
2016-08-19T12:24:50Z
39,039,124
<p>I was able to change the font size by changing default legend fontsize for <code>matplotlib</code> before making the plot.</p> <pre><code>matplotlib.rc("legend", fontsize=20) sns.jointplot(xdata,ydata,kind='reg', order=2,ylim=[-1,1],xlim=[-1,1],annot_kws={"loc": 4}) </code></pre>
0
2016-08-19T12:31:20Z
[ "python", "annotations", "font-size", "seaborn" ]
How to split sentence into words which fit given space?
39,039,037
<p>I have a dictionary where key is the number and value is a string. I would like it to print those strings in lines. BUT the lines has length let's say 15, so there can be 15 chars in line. If adding current word to line makes it longer than 15 , the current word is moved to the next line. I think it can be done with...
-1
2016-08-19T12:27:15Z
39,039,255
<p>Use the <a href="https://docs.python.org/2/library/textwrap.html#textwrap.fill" rel="nofollow"><code>textwrap.fill()</code> function</a>; this takes care of splitting your string, figuring out how many words fit per line, and rejoining the lines with newlines:</p> <pre><code>import textwrap for elem, string in dic...
3
2016-08-19T12:37:43Z
[ "python" ]
I can't seem to open two windows with python, tkinter
39,039,123
<p>I am getting an error trying to open a window in python<br /> I am using <code>tkinter</code> so the code looks a bit like this</p> <pre><code>from tkinter import * Window = Tk() Window2 = Tk() Window.create_rectangle(0, 0, 100, 100) # border Window2.create_rectangle(0, 0, 100, 100) </code></pre>
-4
2016-08-19T12:31:19Z
39,039,381
<p>You should use: import tkinter</p>
-4
2016-08-19T12:44:20Z
[ "python", "tkinter" ]
I can't seem to open two windows with python, tkinter
39,039,123
<p>I am getting an error trying to open a window in python<br /> I am using <code>tkinter</code> so the code looks a bit like this</p> <pre><code>from tkinter import * Window = Tk() Window2 = Tk() Window.create_rectangle(0, 0, 100, 100) # border Window2.create_rectangle(0, 0, 100, 100) </code></pre>
-4
2016-08-19T12:31:19Z
39,039,650
<p>You have some basic typos / syntax errors in your code. But anyway...</p> <p>A Tkinter window doesn't have <code>create_rectangle</code> method. However, the Canvas widget <em>does</em> have that method; you can use it like this.</p> <pre><code>import tkinter as tk window = tk.Tk() canvas = tk.Canvas(window, widt...
2
2016-08-19T12:56:57Z
[ "python", "tkinter" ]
I can't seem to open two windows with python, tkinter
39,039,123
<p>I am getting an error trying to open a window in python<br /> I am using <code>tkinter</code> so the code looks a bit like this</p> <pre><code>from tkinter import * Window = Tk() Window2 = Tk() Window.create_rectangle(0, 0, 100, 100) # border Window2.create_rectangle(0, 0, 100, 100) </code></pre>
-4
2016-08-19T12:31:19Z
39,044,139
<p>Although the question already has an accepted answer. It doesn't actually answer the question on creating another window.</p> <p>You should always avoid having multiple instances of <code>Tk()</code> if you need another window the <code>Toplevel</code> widget is what you should look towards.</p> <pre><code>import ...
0
2016-08-19T16:48:00Z
[ "python", "tkinter" ]
How to pass context in odoo9?
39,039,222
<p>I want to pass the partner_id which is selected in sale order to pricelist via context how to do that ?</p> <pre><code>@api.multi @api.onchange('product_id') def product_id_change(self): if not self.product_id: return {'domain': {'product_uom': []}} vals = {} domain = {'product_uom': [('categor...
1
2016-08-19T12:36:16Z
39,039,347
<p>Since new API context is encapsulated in an environment object, which often can be called like <code>self.env</code>. To manipulate the context just use the method <code>with_context</code>. An simple example:</p> <pre class="lang-py prettyprint-override"><code>vals['price_unit'] = self.env['account.tax']\ .wit...
1
2016-08-19T12:42:45Z
[ "python", "openerp", "odoo-9" ]
Get path in svg using Selenium (Python)
39,039,232
<p>I have the following code which find all g's in svg, yet how could I get those path elements inside g's and their path value?</p> <p>I am testing with this website: <a href="http://www.totalcorner.com/match/live_stats/57565755" rel="nofollow">http://www.totalcorner.com/match/live_stats/57565755</a></p> <p>related ...
3
2016-08-19T12:36:49Z
39,039,578
<p>You are getting a list, so try:</p> <pre><code>for node in nodes: print(node.text) </code></pre> <p>if a you are looking for a value of an attribute then use the following (<code>href</code> here as an example):</p> <pre><code>print(node.get_attribute('href')) </code></pre>
2
2016-08-19T12:53:48Z
[ "python", "selenium", "svg" ]
Get path in svg using Selenium (Python)
39,039,232
<p>I have the following code which find all g's in svg, yet how could I get those path elements inside g's and their path value?</p> <p>I am testing with this website: <a href="http://www.totalcorner.com/match/live_stats/57565755" rel="nofollow">http://www.totalcorner.com/match/live_stats/57565755</a></p> <p>related ...
3
2016-08-19T12:36:49Z
39,039,897
<p><a href="https://seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webelement.html" rel="nofollow">find_elements_by_tag_name</a> can be used to find path children.</p> <p>Once you have those, get_attribute("d") will get you the path value.</p> <p>E.g.</p> <pre><code>for node in ...
1
2016-08-19T13:08:44Z
[ "python", "selenium", "svg" ]
Appending a pair of numpy arrays in a specific format to a 3rd array
39,039,429
<p>I'm extracting data points in pairs from a data set. A pair consists of 2 numpy arrays, each shaped <code>(3, 30, 30)</code>. Let's call them <code>X1</code> and <code>Y1</code>. The next pair will then be <code>X2</code> and <code>Y2</code>, followed by <code>X3</code> and <code>Y3</code>, etc. I don't know how m...
0
2016-08-19T12:46:41Z
39,043,696
<p>With list append</p> <pre><code>list_of_pairs = [] # real list for data in database: X1, Y1 = extract_X_and_Y_from_data(data) pair1 = np.array([X1, Y1]) list_of_pairs.some_append_function(pair1) array5d = np.array(list_of_pairs) &gt;&gt; array5d.shape (50, 2, 3, 30, 30) </code></pre> <p><code>appendi...
1
2016-08-19T16:21:29Z
[ "python", "arrays", "numpy" ]
Is there a good way to visualize large number of subplots (> 500)?
39,039,435
<p>I am still working on my New York Subway data. I cleaned and wrangled the data in such a fashion that I now have 'Average Entries' and 'Average Exits' per Station per hour (ranging from 0 to 23) separated for weekend and weekday (category variable with two possible values: weekend/weekday).</p> <p>What I was trying...
1
2016-08-19T12:47:08Z
39,040,175
<p>You're going to have problems displaying them all on a screen no matter what you do unless you have a whole wall of monitors, however to get around the memory constraint, you could rasterize them and save to image files (I would suggest .png for compressability with images of few distinct colors)</p> <p>What you wa...
1
2016-08-19T13:22:03Z
[ "python", "pandas", "matplotlib", "visualization", "subplot" ]
Is there a good way to visualize large number of subplots (> 500)?
39,039,435
<p>I am still working on my New York Subway data. I cleaned and wrangled the data in such a fashion that I now have 'Average Entries' and 'Average Exits' per Station per hour (ranging from 0 to 23) separated for weekend and weekday (category variable with two possible values: weekend/weekday).</p> <p>What I was trying...
1
2016-08-19T12:47:08Z
39,040,395
<p>rather than making 550+ subplots see if you can make two big numpy arrays and then use 2 <code>imview</code> subplots, one for weekdays and one for weekends</p> <p>for the y-values, first find the min (0) and max (10,000?) for your average values, scale these to fit each fake row of, for example, 10px then offset e...
2
2016-08-19T13:32:15Z
[ "python", "pandas", "matplotlib", "visualization", "subplot" ]
Is there a good way to visualize large number of subplots (> 500)?
39,039,435
<p>I am still working on my New York Subway data. I cleaned and wrangled the data in such a fashion that I now have 'Average Entries' and 'Average Exits' per Station per hour (ranging from 0 to 23) separated for weekend and weekday (category variable with two possible values: weekend/weekday).</p> <p>What I was trying...
1
2016-08-19T12:47:08Z
39,040,705
<p>A possible way you could do it is to use the ratio of entries to exits per station. Each day/hour could form a column on an image and each row would be a station. As en example:</p> <pre class="lang-python prettyprint-override"><code>from matplotlib import pyplot as plt import random import numpy as np all_statio...
1
2016-08-19T13:48:35Z
[ "python", "pandas", "matplotlib", "visualization", "subplot" ]
How to merge two images using second as a transparent binary mask in Python?
39,039,474
<p>For example I have a image of a cat, and second image with a mask of cat. And I want to add transparent red mask for pixels of a cat in first image. Both images are numpy arrays...So how to do it?</p>
0
2016-08-19T12:49:09Z
39,040,178
<p>IIUC you could do something like this -</p> <pre><code>img[:,:,2] = np.where(mask,255,img[:,:,2]) </code></pre> <p>Results -</p> <p><a href="http://i.stack.imgur.com/Dn3of.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/Dn3of.jpg" alt="enter image description here"></a></p> <p><a href="http://i.stack.imgu...
1
2016-08-19T13:22:16Z
[ "python", "opencv", "numpy", "image-processing" ]
How to deal with iteration/looping in Python behave or BDD Scenarios in general?
39,039,706
<p>I am trying to use Python's <a href="https://pythonhosted.org/behave/index.html" rel="nofollow">behave library</a> for writing some BDD/Gherkin style tests on a bunch of delimited textfiles.</p> <p>A typical scenario would look like this:</p> <pre><code>Scenario: Check delivery files for illegal values Given a...
1
2016-08-19T12:59:25Z
39,299,346
<p>Dirk, you could consider writing a script to generate the scenario outline (given the csv file). That way you can rely on standard behave/gherkin features. Keep it as simple as possible as it introduces another place where things can go wrong. It however simplifies your step file so you can focus on the actual func...
0
2016-09-02T19:15:26Z
[ "python", "loops", "iteration", "gherkin", "python-behave" ]
How to pre-fill a modelform field DJango
39,039,805
<p>ive been searching for a while for information on how to do this. here is my situation. i have a ContactForm(form.ModelForm): and it excludes the ID field</p> <p>which i want to be auto generated based on the last entry to the Contact table</p> <p>but im not finding any examples on how to do this the help im looki...
1
2016-08-19T13:04:18Z
39,039,891
<p>If you define a field of a model as an <a href="https://docs.djangoproject.com/en/1.10/topics/db/models/#automatic-primary-key-fields" rel="nofollow"><code>AutoField</code></a> it will do this exact thing</p> <p>EDIT:</p> <p>If you want to define a custom auto incrementing ID you can do it like: from django.db imp...
1
2016-08-19T13:08:26Z
[ "python", "django", "modelform" ]
python install module manually raspberry pi
39,040,083
<p>I have to install a module insteon.py manually.</p> <p>So I copied the module in /usr/lib/python2.7/dist-packages and usr/local/lib/python2.7/dist-packages.</p> <p>When I try to import the module insteon.py, it gives me this error:</p> <pre><code>Traceback (most recent call last): File "main.py", line 15, in &lt;...
0
2016-08-19T13:18:05Z
39,043,245
<p>if you would you can download the script here</p> <p><a href="https://github.com/bynds/makevoicedemo" rel="nofollow">https://github.com/bynds/makevoicedemo</a></p>
0
2016-08-19T15:53:50Z
[ "python", "module", "raspberry-pi" ]
Unable to export DataFrame values into SQL table
39,040,146
<p>I am trying to write a python code to perform regression on some data out of the table from SQL and then export some parameters of the cleaned data back to a new SQL table. My code:</p> <pre><code>import pandas as pd import numpy as np import pandas.io.sql as psql import pypyodbc from pandas.stats.api import ols im...
0
2016-08-19T13:20:17Z
39,042,782
<pre><code>const_Coef = Data_Params.iat[0,0] Cohort_2_Coef = Data_Params.iat[0,1] Cohort_3_Coef = Data_Params.iat[0,2] const_Pvalue = Data_Pvalues.iat[0,0] Cohort_2_Pvalue = Data_Pvalues.iat[0,1] Cohort_3_Pvalue = Data_Pvalues.iat[0,2] Current_Date_Time = datetime.datetime.now() #Extracting Current Time db = conn.c...
0
2016-08-19T15:28:41Z
[ "python", "sql", "sql-server", "pandas" ]
How to implement the functionality of lockfile command
39,040,174
<p>I'm trying to implement a filesystem-based lock for a software, which runs on a cluster. The underlying shared filesystem is implemented using <a href="https://en.wikipedia.org/wiki/Distributed_Replicated_Block_Device" rel="nofollow">DRBD</a>, so synchronicity can be considered guaranteed. My current implementation ...
2
2016-08-19T13:21:59Z
39,097,188
<p>A solution can be achieved by using os.open, which wraps the <code>open</code> system call:</p> <pre><code>import os,errno def lockfile(filename): try: os.close(os.open(filename, os.O_CREAT | os.O_EXCL | os.O_WRONLY)); except OSError as e: if e.errno == errno.EEXIST: # System is already loc...
0
2016-08-23T09:18:45Z
[ "python", "cluster-computing" ]