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
listlengths
1
5
How to merge Spark dataframes by id?
38,441,431
<p>Suppose I have a dataframe x containing: id, C.</p> <p>Suppose I have a dataframe y containing: A, B, id.</p> <p>How do I find the row in dataframe y where the id is the same and merge everything in y.</p> <p>The result should be: </p> <pre><code>DataFrame:[A,B,C,id] </code></pre>
0
2016-07-18T16:09:42Z
38,441,870
<pre><code>merged = x.join(y, y.id==x.id) </code></pre> <p>Use drop() to remove unnecessary columns.</p>
0
2016-07-18T16:34:53Z
[ "python", "apache-spark", "spark-dataframe" ]
How to merge Spark dataframes by id?
38,441,431
<p>Suppose I have a dataframe x containing: id, C.</p> <p>Suppose I have a dataframe y containing: A, B, id.</p> <p>How do I find the row in dataframe y where the id is the same and merge everything in y.</p> <p>The result should be: </p> <pre><code>DataFrame:[A,B,C,id] </code></pre>
0
2016-07-18T16:09:42Z
38,446,873
<p>Like this:</p> <pre><code>&gt;&gt;&gt; merged = x.join(y, "id") </code></pre>
0
2016-07-18T22:22:58Z
[ "python", "apache-spark", "spark-dataframe" ]
Writing instagram crawler with Scrapy. How can I go to the next page?
38,441,473
<p>As an exercise, I decided to write a python script that would get all the images of the specified user. I'm somewhat familiar with Scrapy, this is why I chose it as scraping tool. Currently the script is capable of downloading the images only from the first page (12 max).</p> <p>From what I can tell, instagram page...
1
2016-07-18T16:11:52Z
38,441,899
<p>according to <a href="https://www.instagram.com/robots.txt" rel="nofollow">robots.txt</a> policy you should avvoid crawling <code>/api/</code>, <code>/publicapi/</code> and <code>/query/</code> paths, so crawl carefully (and responsibly) on the user pagination.</p> <p>Also from what I see pagination starts with a "...
1
2016-07-18T16:36:56Z
[ "python", "scrapy", "instagram" ]
Writing instagram crawler with Scrapy. How can I go to the next page?
38,441,473
<p>As an exercise, I decided to write a python script that would get all the images of the specified user. I'm somewhat familiar with Scrapy, this is why I chose it as scraping tool. Currently the script is capable of downloading the images only from the first page (12 max).</p> <p>From what I can tell, instagram page...
1
2016-07-18T16:11:52Z
38,935,589
<p> You can also add the parameter <code>__a=1</code> (like in <code>https://www.instagram.com/instagram/?__a=1</code>) to only include the JSON in the <code>window._sharedData</code> object.</p> <p>I used a shell script like this to do something similar:</p> <pre class="lang-none prettyprint-override"><code>username...
0
2016-08-13T18:08:59Z
[ "python", "scrapy", "instagram" ]
Populating a list in a specific way
38,441,568
<p>I need to populate a list with 5 positions.</p> <pre><code>new_list = ___ ___ ___ ___ ___ </code></pre> <p>I receive 2 lists and I have one default value to populate the new list.</p> <p>Now start the problems:</p> <p>In the good way, I receive 2 values from listA and 2 values from listB and add the default val...
3
2016-07-18T16:17:18Z
38,441,609
<p>You could just add your lists:</p> <pre><code>new_list = listA + listB # add the default value new_list.append(DEFAULT) </code></pre>
0
2016-07-18T16:19:41Z
[ "python", "list", "populate" ]
Populating a list in a specific way
38,441,568
<p>I need to populate a list with 5 positions.</p> <pre><code>new_list = ___ ___ ___ ___ ___ </code></pre> <p>I receive 2 lists and I have one default value to populate the new list.</p> <p>Now start the problems:</p> <p>In the good way, I receive 2 values from listA and 2 values from listB and add the default val...
3
2016-07-18T16:17:18Z
38,442,529
<p>This will work in all cases, including if list B is less than 2 elements long while list A is 4 or greater.</p> <pre><code>avail_a = len(list_a) avail_b = min(len(list_b), 2) # assume that we are taking max 2 elements from B num_a = min(avail_a, 4 - avail_b) # take either all of A (if len &lt; 2), or remainder fr...
1
2016-07-18T17:17:51Z
[ "python", "list", "populate" ]
Populating a list in a specific way
38,441,568
<p>I need to populate a list with 5 positions.</p> <pre><code>new_list = ___ ___ ___ ___ ___ </code></pre> <p>I receive 2 lists and I have one default value to populate the new list.</p> <p>Now start the problems:</p> <p>In the good way, I receive 2 values from listA and 2 values from listB and add the default val...
3
2016-07-18T16:17:18Z
38,443,009
<p>You can solve this by recursively building the list with a and b, starting with the default user.</p> <pre><code>def build_list(listA,listB,default=None): if default is None: default = [DEFAULT_USER] if len(default) == 5 or len(listA) + len(listB) == 0: return default else: defau...
2
2016-07-18T17:49:16Z
[ "python", "list", "populate" ]
Populating a list in a specific way
38,441,568
<p>I need to populate a list with 5 positions.</p> <pre><code>new_list = ___ ___ ___ ___ ___ </code></pre> <p>I receive 2 lists and I have one default value to populate the new list.</p> <p>Now start the problems:</p> <p>In the good way, I receive 2 values from listA and 2 values from listB and add the default val...
3
2016-07-18T16:17:18Z
38,443,636
<p>I think you can do something like this:</p> <pre><code>new_list = [DEFAULT] # First append listB elements from start until you reach the end # or until you append enough elements according to the length of listA i = 0 b_limit = min(len(listB), max(2, 4 - len(listA))) while i &lt; b_limit: new_list.append(listB...
1
2016-07-18T18:26:30Z
[ "python", "list", "populate" ]
How to install pip without sudo or wget or brew or easy_install?
38,441,570
<p>I am trying to download pip but I don't have sudo access. I get this error: </p> <pre><code>Exception: Traceback (most recent call last): File "/var/folders/h3/mg0jxd6x7v9gmrg89kcwxbfcpm025t/T/tmp0PONb0/pip.zip/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/var/folders/h3/mg0jxd6...
0
2016-07-18T16:17:20Z
38,441,632
<p>Use <a href="https://virtualenv.pypa.io/en/stable/" rel="nofollow">virtualenv</a>. </p> <p>Create and activate virtualenv and install your packages in virualenv. You won't require sudo access.</p>
0
2016-07-18T16:20:59Z
[ "python", "osx", "installation", "pip", "sudo" ]
How to install pip without sudo or wget or brew or easy_install?
38,441,570
<p>I am trying to download pip but I don't have sudo access. I get this error: </p> <pre><code>Exception: Traceback (most recent call last): File "/var/folders/h3/mg0jxd6x7v9gmrg89kcwxbfcpm025t/T/tmp0PONb0/pip.zip/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/var/folders/h3/mg0jxd6...
0
2016-07-18T16:17:20Z
38,441,673
<p><a href="https://pip.pypa.io/en/stable/installing/" rel="nofollow">https://pip.pypa.io/en/stable/installing/</a></p> <p>You can download the .py file and run it to install pip.</p>
0
2016-07-18T16:23:16Z
[ "python", "osx", "installation", "pip", "sudo" ]
python - List only directories, insert absolute path
38,441,614
<p>I'm currently using <code>os.walk</code> to list only the directories in a given folder. However, I need the absolute path for each directory listed.</p> <p>My line of code:</p> <pre><code>folder_path = '/Users/username/Desktop/T' array2 = next(os.walk(folder_path))[1] print(array2) </code></pre> <p>It outputs:...
0
2016-07-18T16:19:57Z
38,441,655
<pre><code>for current,dirs,files in os.walk(...): for folder in dirs: print os.path.abspath(os.path.join(current,folder)) </code></pre> <p>if you just want the directories in <code>T</code></p> <pre><code>from os import listdir from os.path import isdir,join as pjoin root = "/Users/username/Desktop/T" pr...
2
2016-07-18T16:22:20Z
[ "python" ]
python - List only directories, insert absolute path
38,441,614
<p>I'm currently using <code>os.walk</code> to list only the directories in a given folder. However, I need the absolute path for each directory listed.</p> <p>My line of code:</p> <pre><code>folder_path = '/Users/username/Desktop/T' array2 = next(os.walk(folder_path))[1] print(array2) </code></pre> <p>It outputs:...
0
2016-07-18T16:19:57Z
38,441,731
<p>Try this:</p> <pre> <code> for o in array2: print os.path.abspath(o) </code> </pre>
0
2016-07-18T16:26:23Z
[ "python" ]
python - List only directories, insert absolute path
38,441,614
<p>I'm currently using <code>os.walk</code> to list only the directories in a given folder. However, I need the absolute path for each directory listed.</p> <p>My line of code:</p> <pre><code>folder_path = '/Users/username/Desktop/T' array2 = next(os.walk(folder_path))[1] print(array2) </code></pre> <p>It outputs:...
0
2016-07-18T16:19:57Z
38,442,169
<p>I combined <code>os.path.abspath</code> and <code>os.path.join</code>:</p> <pre><code>folder_path = '/Users/username/Desktop/T' array2 = next(os.walk(folder_path))[1] array3 = [] print(array2) # ['T1', 'T2', 'T3'] for local_folder in array2: array3.append( os.path.abspath(os.path.join(folder_path, local_fold...
0
2016-07-18T16:53:36Z
[ "python" ]
Can anyone explain why I am getting this error [ImportError: lxml not found, please install it]
38,441,639
<p>I am trying to use use the .read_html() function in the pandas library and keep getting this error when I run the code in the shell. I saw that you need to install the lxml so I did that using apt-get. But afterwards when I tried to run it again I was getting the same error. </p> <pre><code>(trusty)mdz5032@localhos...
0
2016-07-18T16:21:28Z
38,442,414
<pre><code>sudo apt-get install python3-lxml </code></pre> <p>You've installed lxml for python2, but your code is running under python3.</p>
1
2016-07-18T17:09:15Z
[ "python", "ubuntu", "pandas", "lxml", "html5lib" ]
Selenium Python Drop Down Not Controllable
38,441,660
<p>I'm trying to select and control a drop down menu on the www.ziprecruiter.com website using Selenium called radius. Since I'm a beginner I cant seem to figure out why I cant control this one drop down radius menu. I have tried using find by ID, name, Xpath, and select but nothing seems to be working. I want to selec...
0
2016-07-18T16:22:34Z
38,442,197
<p>Sometimes dropdowns are created using <code>SELECT</code> tags but this is becoming less frequent as sites want the dropdown feel with different styling than the typical <code>SELECT</code> will give them. What you have on this page is an instance of a dropdown that isn't a <code>SELECT</code> tag. If it were a Sele...
0
2016-07-18T16:55:22Z
[ "python", "selenium" ]
Simple example of a caffe python input layer (for images with labels)
38,441,688
<p>The requirement is that the python script be more illustrative than performant. </p> <ol> <li>Keep it simple (no multiprocessing, that can be a separate step)</li> <li>It should take-in images and corresponding labels in batches of 50.</li> <li>It should apply the <code>transformer</code> (resize, transpose, mean, ...
-1
2016-07-18T16:24:25Z
38,444,968
<p>Turns out, this is already available!</p> <p><a href="https://github.com/BVLC/caffe/blob/master/examples/pascal-multilabel-with-datalayer.ipynb" rel="nofollow">https://github.com/BVLC/caffe/blob/master/examples/pascal-multilabel-with-datalayer.ipynb</a></p> <p>with the pyhton input layer code here,</p> <p><a href...
0
2016-07-18T19:54:34Z
[ "python", "neural-network", "caffe", "pycaffe" ]
get everything after non numeric index not including the index in a pandas series
38,441,760
<p>Consider the series <code>s</code> below:</p> <pre><code>s = pd.Series(np.arange(18, 0, -3), list('ABCDEF')) s A 18 B 15 C 12 D 9 E 6 F 3 dtype: int32 </code></pre> <p>I want to be able to access all elements after index <code>'D'</code></p> <pre><code>E 6 F 3 dtype: int32 </code></p...
3
2016-07-18T16:27:55Z
38,441,776
<p><strong>UPDATE:</strong> thanks to @Alex he has reminded that indices are not always monotonically increasing:</p> <pre><code>In [85]: s Out[85]: F 18 B 15 D 12 A 9 C 6 E 3 dtype: int32 In [86]: s.iloc[s.index.get_loc('D') + 1:] Out[86]: A 9 C 6 E 3 dtype: int32 </code></pre> <p>try ...
3
2016-07-18T16:28:55Z
[ "python", "pandas" ]
get everything after non numeric index not including the index in a pandas series
38,441,760
<p>Consider the series <code>s</code> below:</p> <pre><code>s = pd.Series(np.arange(18, 0, -3), list('ABCDEF')) s A 18 B 15 C 12 D 9 E 6 F 3 dtype: int32 </code></pre> <p>I want to be able to access all elements after index <code>'D'</code></p> <pre><code>E 6 F 3 dtype: int32 </code></p...
3
2016-07-18T16:27:55Z
38,442,004
<p>See MaxU's answer if you know that index values are monotonically increasing. Otherwise...</p> <pre><code>m = s.index == 'D' idx = m.argmax() if m.any() else len(m) s.iloc[idx + 1:] = 0 </code></pre>
3
2016-07-18T16:43:24Z
[ "python", "pandas" ]
xlwt can't write to xls file?
38,441,774
<p>Been following a guide to write to xls files and the exmaple used was the following:</p> <pre><code>wb = xlwt.Workbook() newsheet=wb.add_sheet('sheet1') newsheet.write('0','0','testing') wb.save(testing.xls) </code></pre> <p>However I get an error saying: </p> <blockquote> <p>ValueError: row index was '0', not ...
0
2016-07-18T16:28:49Z
38,441,811
<p>The first two arguments of the <code>write()</code> method have to be row and column numbers, not strings:</p> <pre><code>newsheet.write(0, 0, 'testing') </code></pre> <p>FYI, here is the <a href="https://github.com/python-excel/xlwt/blob/master/xlwt/Worksheet.py#L1035" rel="nofollow"><code>write()</code> method d...
2
2016-07-18T16:30:50Z
[ "python", "excel", "xlwt" ]
Pandas dataframe, split data by last column in last position but keep other columns
38,441,831
<p>Very new to pandas so any explanation with a solution is appreciated.</p> <p>I have a dataframe such as </p> <pre><code> Company Zip State City 1 *CBRE San Diego, CA 92101 4 1908 Brands Boulder, CO 80301 7 1st Infantry Divis...
3
2016-07-18T16:32:15Z
38,442,043
<p>you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.extract.html" rel="nofollow">extract()</a> method:</p> <pre><code>In [110]: df Out[110]: Company Zip State City 1 *CBRE San Diego, CA ...
7
2016-07-18T16:46:02Z
[ "python", "pandas", "dataframe" ]
MICR Character Recognition Using Python OpenCV
38,441,844
<p>How can i read the characters for MICR (found in cheques) using python and opencv? I have been able to read the OCR, the special characters are the challenge.</p>
0
2016-07-18T16:33:10Z
38,462,228
<p><a href="https://groups.google.com/forum/#!topic/tesseract-ocr/eHJfutK6758" rel="nofollow">https://groups.google.com/forum/#!topic/tesseract-ocr/eHJfutK6758</a> go through this link may be you can get.</p>
0
2016-07-19T15:04:23Z
[ "python", "opencv3.0", "micr" ]
python cx_Oracle cursor returns no rows for valid query
38,441,869
<p>Beating my head against my desk on this one.</p> <p>My cx_Oracle cursor is returning no rows for a valid query and I cannot figure out why.</p> <p>The same connection returns expected results from other tables in same schema... for example if I simply change the referenced table name in the query from TABLE_A to T...
0
2016-07-18T16:34:49Z
38,442,739
<p>I figured out where I was being blind to the issue.</p> <p>The records were not COMMITED. I was able to query the records in the session in which I inserted them (SQL Developer), using the same user.</p> <p>Which led to "what the heck is going on" I should have known / better.</p>
0
2016-07-18T17:31:02Z
[ "python", "sql", "cursor", "cx-oracle", "fetchall" ]
call a function using a JSON key and value in Python
38,441,876
<p>I have run a websocket on Linux server to serve connected clients using a local network. my aim is to let the client to control some configurations.</p> <p>A Web Application (compounded of PHP and HTML pages) play a roll as an interface, when the home page is loaded it connects to the websocket using pure Javascrip...
0
2016-07-18T16:35:12Z
38,441,929
<p>Normally, you'd pack the functions into a dict:</p> <pre><code>def greeting(value): print "Hello " + str(value) FUNC_MAP = { 'Greeting': greeting, } </code></pre> <p>And then to call the function,</p> <pre><code>data = json.loads(stdin.readline()); for func_name, value in data.items(): FUNC_MAP[func_...
0
2016-07-18T16:38:43Z
[ "python", "websocket" ]
locate the numeric position of a non numeric index value
38,441,888
<p>Consider the series <code>s</code> below:</p> <pre><code>s = pd.Series(np.arange(18, 0, -3), list('ABCDEF')) s A 18 B 15 C 12 D 9 E 6 F 3 dtype: int32 </code></pre> <p>I want to get the numeric position of <code>'D'</code></p> <p>This will do it, but I think we can all agree this is gross:</...
4
2016-07-18T16:36:24Z
38,441,916
<p>Use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.searchsorted.html" rel="nofollow"><code>np.searchsorted</code></a> -</p> <pre><code>np.searchsorted(s.index.values,'D') </code></pre> <p>Or use the method, like so -</p> <pre><code>s.index.searchsorted('D') </code></pre>
4
2016-07-18T16:37:58Z
[ "python", "numpy", "pandas" ]
locate the numeric position of a non numeric index value
38,441,888
<p>Consider the series <code>s</code> below:</p> <pre><code>s = pd.Series(np.arange(18, 0, -3), list('ABCDEF')) s A 18 B 15 C 12 D 9 E 6 F 3 dtype: int32 </code></pre> <p>I want to get the numeric position of <code>'D'</code></p> <p>This will do it, but I think we can all agree this is gross:</...
4
2016-07-18T16:36:24Z
38,442,028
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.get_loc.html"><code>Index.get_loc</code></a>:</p> <pre><code>print(s.index.get_loc('D')) 3 </code></pre>
6
2016-07-18T16:45:02Z
[ "python", "numpy", "pandas" ]
locate the numeric position of a non numeric index value
38,441,888
<p>Consider the series <code>s</code> below:</p> <pre><code>s = pd.Series(np.arange(18, 0, -3), list('ABCDEF')) s A 18 B 15 C 12 D 9 E 6 F 3 dtype: int32 </code></pre> <p>I want to get the numeric position of <code>'D'</code></p> <p>This will do it, but I think we can all agree this is gross:</...
4
2016-07-18T16:36:24Z
38,442,034
<pre><code>m = s.index == 'D' idx = m.argmax() if m.any() else None </code></pre>
3
2016-07-18T16:45:32Z
[ "python", "numpy", "pandas" ]
Get "NameError: name 'IP' is not defined" error message
38,441,889
<p>I try to run a python code from online course to create a raw network packet and send to a network by scapy with python 3.4.2 on Debian 9 but I got the error message as show below:</p> <blockquote> <p>NameError: name 'IP' is not defined</p> </blockquote> <p>when I look into the code:</p> <pre><code>#!/usr/bin/p...
1
2016-07-18T16:36:24Z
38,557,341
<pre><code>#!/usr/bin/python #for python 3 , must install scapy for python3 first by type command "pip3 install scapy-python3" import scapy.all.Ether import scapy.all.IP import scapy.all.TCP frame = Ether(dst="15:16:89:fa:dd:09") / IP(dst="9.16.5.4") / TCP() / "This is my payload" </code></pre>
0
2016-07-24T22:11:47Z
[ "python", "python-3.x", "network-programming", "scapy" ]
Tensorflow Grid LSTM RNN TypeError
38,442,025
<p>I'm trying to build a LSTM RNN that handles 3D data in Tensorflow. From <a href="https://arxiv.org/abs/1507.01526" rel="nofollow">this</a> paper, Grid LSTM RNN's can be n-dimensional. The idea for my network is a have a 3D volume <code>[depth, x, y]</code> and the network should be <code>[depth, x, y, n_hidden]</cod...
1
2016-07-18T16:44:57Z
38,579,107
<p>I was unsure on some of the implementation decisions of the code, so I decided to roll my own. One thing to keep in mind is that this is an implementation of just the cell. It is up to you to build the actual machinery that handles the locations and interactions of the h and m vectors and isn't as simple as passing ...
2
2016-07-25T23:55:47Z
[ "python", "machine-learning", "neural-network", "artificial-intelligence", "tensorflow" ]
Tensorflow Grid LSTM RNN TypeError
38,442,025
<p>I'm trying to build a LSTM RNN that handles 3D data in Tensorflow. From <a href="https://arxiv.org/abs/1507.01526" rel="nofollow">this</a> paper, Grid LSTM RNN's can be n-dimensional. The idea for my network is a have a 3D volume <code>[depth, x, y]</code> and the network should be <code>[depth, x, y, n_hidden]</cod...
1
2016-07-18T16:44:57Z
38,617,692
<p>which version of Grid LSTM cells are you using?</p> <p>If you are using <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/rnn/python/ops/rnn_cell.py" rel="nofollow">https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/rnn/python/ops/rnn_cell.py</a></p> <p>I think y...
3
2016-07-27T15:44:24Z
[ "python", "machine-learning", "neural-network", "artificial-intelligence", "tensorflow" ]
Tensorflow Grid LSTM RNN TypeError
38,442,025
<p>I'm trying to build a LSTM RNN that handles 3D data in Tensorflow. From <a href="https://arxiv.org/abs/1507.01526" rel="nofollow">this</a> paper, Grid LSTM RNN's can be n-dimensional. The idea for my network is a have a 3D volume <code>[depth, x, y]</code> and the network should be <code>[depth, x, y, n_hidden]</cod...
1
2016-07-18T16:44:57Z
39,757,661
<p>Yes, dynamic shape was the cause. There is a PR to fix this: <a href="https://github.com/tensorflow/tensorflow/pull/4631" rel="nofollow">https://github.com/tensorflow/tensorflow/pull/4631</a></p> <p>@jstaker7: Thank you for trying it out. Re. problem 1, the above PR uses tuples for states and outputs, hopefully it ...
1
2016-09-28T21:06:18Z
[ "python", "machine-learning", "neural-network", "artificial-intelligence", "tensorflow" ]
pygame sorting list objects that are strings
38,442,067
<p>I am making a game were at the start you enter your name and then it is saved as a variable. Then, you perform specific tasks and your time is counted in seconds. At the end, I want to remove the worst time, the Scoreboard to save your time if you beat a record, sort that list that contains the Scoreboard and then s...
0
2016-07-18T16:47:55Z
38,487,324
<p>I would say you could make each element in the scoreboard list into a nested tuple in the list- I don't know what file type you're using, but I expect you could save it in this format. If it was a list of nested tuples, you could sort it using the [sorted] method. The [key] parameter will allow you to sort based on ...
0
2016-07-20T17:43:28Z
[ "python", "list", "pygame" ]
Remove old Python Installation in MAC OS
38,442,104
<p>I installed python using MacPort and I am satisfied with the result, but found that there are other versions of Python installed in other directories, and can not remember how they were instaldas, it's been five years that use this notebook and perhaps installed by other means a few years.</p> <p>I tried to remove ...
0
2016-07-18T16:50:04Z
38,442,289
<p>Don't remove the system Pythons. They may be used by other programs. (I don't know if anything on OS X actually uses them, but it's best to keep them.)</p> <p>Instead, just make sure that your MacPorts bin directory (at <code>/opt/local/bin</code>) is first on your <code>$PATH</code>.</p>
1
2016-07-18T17:01:08Z
[ "python", "osx" ]
Remove old Python Installation in MAC OS
38,442,104
<p>I installed python using MacPort and I am satisfied with the result, but found that there are other versions of Python installed in other directories, and can not remember how they were instaldas, it's been five years that use this notebook and perhaps installed by other means a few years.</p> <p>I tried to remove ...
0
2016-07-18T16:50:04Z
38,447,997
<p>Don't! The name /Library and /System suggest that they are OS-level directories. Nobody installed them. Instead, Mac and other linux-based systems use them by default for system-level services (and they should not be even manually upgraded or system stability may suffer).</p> <p>For all what matters, you should jus...
1
2016-07-19T00:54:18Z
[ "python", "osx" ]
How can a neural network architecture be visualized with Keras?
38,442,107
<p>I tried the following:</p> <pre><code>#!/usr/bin/env python import keras from keras.models import model_from_yaml model_file_path = 'model-301.yaml' weights_file_path = 'model-301.hdf5' # Load network with open(model_file_path) as f: yaml_string = f.read() model = model_from_yaml(yaml_string) model.load_weig...
3
2016-07-18T16:50:09Z
38,446,987
<p>If you have not already installed <code>pydot</code> python package - try to install it. If you have <code>pydot</code> reinstallation should help with your problem.</p>
1
2016-07-18T22:35:06Z
[ "python", "neural-network", "visualization", "keras" ]
How can a neural network architecture be visualized with Keras?
38,442,107
<p>I tried the following:</p> <pre><code>#!/usr/bin/env python import keras from keras.models import model_from_yaml model_file_path = 'model-301.yaml' weights_file_path = 'model-301.hdf5' # Load network with open(model_file_path) as f: yaml_string = f.read() model = model_from_yaml(yaml_string) model.load_weig...
3
2016-07-18T16:50:09Z
38,611,959
<p>The problem is also referenced on the <a href="https://github.com/fchollet/keras/issues/3210" rel="nofollow">issues page</a> of the keras project. You need to install a version of <code>pydot</code> &lt;= 1.1.0 because the function <code>find_graphviz</code> was <a href="https://github.com/erocarrera/pydot/commit/bc...
1
2016-07-27T11:41:26Z
[ "python", "neural-network", "visualization", "keras" ]
Scrapy request does not callback
38,442,110
<p>I am trying to create a spider that takes data from a csv (two links and a name per row), and scraps a simple element from each of those links, returning an item for each row, with the item's name being the name in the csv, and two scraped prices (one from each link).</p> <p>Everything works as expected except the ...
0
2016-07-18T16:50:24Z
38,442,345
<p>TL;DR: You are yielding an item with Request objects inside of it when you should yield either Item or Request.</p> <hr> <p>Long version:<br> Parse methods in your spider should either return a <code>scrapy.Item</code> - in which case the chain for that crawl will stop and scrapy will put out an item or a <code>sc...
3
2016-07-18T17:05:22Z
[ "python", "web-scraping", "request", "scrapy", "scrapy-spider" ]
How to print top ten topics using Gensim?
38,442,161
<p>In the official explanation, there is no natural ordering between the topics in LDA.</p> <p>As for the method show_topics(), if it returned num_topics &lt;= self.num_topics subset of all topics is therefore arbitrary and may change between two LDA training runs.</p> <p>But I tends to find the top ten frequent topi...
0
2016-07-18T16:53:23Z
38,469,723
<p>Like the documentation says, there is no natural ordering between topics in LDA. If you have your own criterion for ordering the topics, such as frequency of appearance, you can always retrieve the entire list of topics from your model and sort them yourself.</p> <p>However, even the notion of "top ten most freque...
0
2016-07-19T22:47:48Z
[ "python", "lda", "gensim", "topic-modeling" ]
Tell python to write something at every line
38,442,252
<p>Thanks the help of this forum, i'm finally arrived at this python3 code:</p> <pre><code>import urllib.request from bs4 import BeautifulSoup url= 'https://www.inforge.net/xi/forums/liste-proxy.1118/' soup = BeautifulSoup(urllib.request.urlopen(url), "lxml") for tag in soup.find_all('a', {'class':'PreviewTooltip'})...
2
2016-07-18T16:58:19Z
38,442,382
<p>You just have to <a href="http://stackoverflow.com/questions/12169839/which-is-the-preferred-way-to-concatenate-a-string-in-python">concatenate</a> the base url with each link.</p> <p>Try this code:</p> <pre><code>import urllib.request from bs4 import BeautifulSoup url= 'https://www.inforge.net/xi/forums/liste-pr...
3
2016-07-18T17:07:16Z
[ "python", "python-3.x", "line", "each", "add" ]
Tell python to write something at every line
38,442,252
<p>Thanks the help of this forum, i'm finally arrived at this python3 code:</p> <pre><code>import urllib.request from bs4 import BeautifulSoup url= 'https://www.inforge.net/xi/forums/liste-proxy.1118/' soup = BeautifulSoup(urllib.request.urlopen(url), "lxml") for tag in soup.find_all('a', {'class':'PreviewTooltip'})...
2
2016-07-18T16:58:19Z
38,483,526
<p>It looks like you are trying to get a list of socks4/5 proxies? The lists on inforge.net are very limited. Have you ever considered using the Proxicity APIs (<a href="https://www.proxicity.io/api/" rel="nofollow">https://www.proxicity.io/api/</a>)? Check them out! Their APIs support HTTP, HTTPS, SOCKS4, and SOCKS5 ...
1
2016-07-20T14:04:43Z
[ "python", "python-3.x", "line", "each", "add" ]
Error in pyspark with udf: You must build Spark with Hive. Export 'SPARK_HIVE=true' and run build/sbt assembly
38,442,278
<p>I'm trying to run this code in Pyspark 1.6.2 using Pre-built for Hadoop 2.6 in Windows 7 professional </p> <p>Everything works fine till the point where i define the udf. Can you give some pointers. Do I need to compile Spark with hive ? Then what is the use of the pre-built for Hadoop 2.6. I cannot change the C:\t...
1
2016-07-18T17:00:11Z
38,457,707
<p>you need to create <code>hive-site.xml</code> file in <code>$SPARK_HOME/conf</code> location. in this file you can override <code>scratch dir</code> path. These are the important configurations that you should include in <code>hive-site.xml</code> file but you can check this <a href="https://github.com/apache/hive/b...
1
2016-07-19T11:49:05Z
[ "python", "hive", "pyspark" ]
Error in pyspark with udf: You must build Spark with Hive. Export 'SPARK_HIVE=true' and run build/sbt assembly
38,442,278
<p>I'm trying to run this code in Pyspark 1.6.2 using Pre-built for Hadoop 2.6 in Windows 7 professional </p> <p>Everything works fine till the point where i define the udf. Can you give some pointers. Do I need to compile Spark with hive ? Then what is the use of the pre-built for Hadoop 2.6. I cannot change the C:\t...
1
2016-07-18T17:00:11Z
38,464,056
<p>In my hive-site.xml, I just had the following code:</p> <pre><code>&lt;configuration&gt; &lt;property&gt; &lt;name&gt;hive.exec.scratchdir&lt;/name&gt; &lt;value&gt;${/tmp1/hive}/scratchdir&lt;/value&gt; &lt;description&gt;Scratch space for Hive jobs&lt;/description&gt; &lt;/property&gt; &lt;property&gt; ...
0
2016-07-19T16:35:28Z
[ "python", "hive", "pyspark" ]
Determine which file system a file or directory is located in Linux
38,442,288
<p>I'm trying to find file or directory real path and which file system it is located in Linux. For example, I have a symbol link:</p> <pre><code>[felixc@apphost ~]$ df -k Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/vg_apphost-lv_root 15350768 3442620 11121716 ...
0
2016-07-18T17:01:08Z
38,442,316
<ul> <li><code>os.path.realpath</code> gives the terminus of a chain of symlink hops.</li> <li><code>os.path.abspath</code> makes relative paths absolute, but it may not name the terminus.</li> <li><code>os.readlink</code> finds the nearest symlink hop</li> </ul> <p>Therefore, use <code>os.path.realpath('/usr/local/ap...
1
2016-07-18T17:03:09Z
[ "python" ]
Maintain comments while writing config file in Python
38,442,296
<p>I have a Dictionary like this</p> <pre><code>dictvalues = {'NAME':'Zara', 'SUBJECT':'English', 'CLASS ':'First'} </code></pre> <p>I have a config.ini like this</p> <pre><code>[OPTIONS] ;the following specifies the name of student NAME = "Zara" ;The following specifies Subject SUBJECT = "MATHS" ;The Following sp...
0
2016-07-18T17:01:28Z
38,442,436
<p>If you will define your dictionary with <code>"</code> your output should be as expected:</p> <pre><code> data = {'NAME': '"Zara"', 'SUBJECT': '"English"', 'CLASS': '"First"'} </code></pre>
0
2016-07-18T17:11:01Z
[ "python", "parsing", "config" ]
return a series of numeric positions for the indices representing the max within each group
38,442,344
<p>Consider the series:</p> <pre><code>np.random.seed([3,1415]) s = pd.Series(np.random.rand(100), pd.MultiIndex.from_product([list('ABDCE'), list('abcde'), ['One', 'Two', 'Three', 'Four']])) </code></pre> <p>I can <code...
3
2016-07-18T17:05:18Z
38,442,459
<p>This is how I did it:</p> <pre><code>s.groupby(level=[0, 2]).apply(lambda x: x.index.get_loc(x.idxmax())) A Four 2 One 3 Three 2 Two 3 B Four 3 One 3 Three 2 Two 1 C Four 1 One 0 Three 0 Two 4 D Four 1 One 4 Three 1...
4
2016-07-18T17:12:59Z
[ "python", "pandas" ]
return a series of numeric positions for the indices representing the max within each group
38,442,344
<p>Consider the series:</p> <pre><code>np.random.seed([3,1415]) s = pd.Series(np.random.rand(100), pd.MultiIndex.from_product([list('ABDCE'), list('abcde'), ['One', 'Two', 'Three', 'Four']])) </code></pre> <p>I can <code...
3
2016-07-18T17:05:18Z
38,444,638
<p>Well I finally have a solution, which uses NumPy's reshaping method and then operates along one of the axes to give us <code>argmax</code>. I am not sure if this is elegant, but I am hoping would be good in terms of performance. Also, I am assuming that pandas Series for multi-index data has a regular format, i.e. e...
2
2016-07-18T19:34:17Z
[ "python", "pandas" ]
What would be the best way to save api data collected with python?
38,442,378
<p>Ive been using python to print live api data in terminal. new data refreshes every 1-2 seconds using while=True and repeating. It would be good to be able to save this data somehow. are there any packages that could store the outputs of the function or the print outs and save them? preferably something simple as Im ...
-3
2016-07-18T17:07:08Z
38,442,555
<p>You could simply write the output to a text file </p> <pre><code>file = open("newfile.txt", "a") for x in data: file.write(x) </code></pre> <p>The "a" option specifies that data will be appended to the bottom of the file.</p> <p>Ideally though, you should look into creating a database. MySQL is probably the b...
0
2016-07-18T17:19:39Z
[ "python", "package" ]
Passing session from template view to python requests api call
38,442,683
<p>I want to make multiple internal REST API call from my Django TemplateView, using requests library. Now I want to pass the session too from template view to api call. What is the recommended way to do that, keeping performance in mind.</p> <p>Right now, I'm extracting <code>cookie</code> from the current <code>requ...
7
2016-07-18T17:28:08Z
38,649,185
<p>If you want to avoid passing the <code>request</code> to <code>wrap_internal_api_call</code>, all you need to do is do a bit more work on the end of the TemplateView where you call the api wrapper. Note that your original wrapper is doing a lot of <code>cookies if cookies else request.COOKIES</code>. You can factor ...
0
2016-07-29T01:34:37Z
[ "python", "django" ]
Passing session from template view to python requests api call
38,442,683
<p>I want to make multiple internal REST API call from my Django TemplateView, using requests library. Now I want to pass the session too from template view to api call. What is the recommended way to do that, keeping performance in mind.</p> <p>Right now, I'm extracting <code>cookie</code> from the current <code>requ...
7
2016-07-18T17:28:08Z
38,658,358
<h2>REST vs Invoking the view directly</h2> <p>While it's possible for a web app to make a REST API call to itself. That's not what REST is designed for. Consider the following from: <a href="https://docs.djangoproject.com/ja/1.9/topics/http/middleware/" rel="nofollow">https://docs.djangoproject.com/ja/1.9/topics/http...
3
2016-07-29T12:02:36Z
[ "python", "django" ]
Passing session from template view to python requests api call
38,442,683
<p>I want to make multiple internal REST API call from my Django TemplateView, using requests library. Now I want to pass the session too from template view to api call. What is the recommended way to do that, keeping performance in mind.</p> <p>Right now, I'm extracting <code>cookie</code> from the current <code>requ...
7
2016-07-18T17:28:08Z
38,663,376
<blockquote> <p>Basically I want to get rid of that request parameter (1st param), because then to call it I've to keep passing request object from TemplateViews to internal services.</p> </blockquote> <p>To pass function args without explicitly passing them into function calls you can use decorators to wrap your fu...
-1
2016-07-29T16:20:14Z
[ "python", "django" ]
Copying sheet - Openpyxl: type object 'Workbook' has no attribute 'copy_worksheet'
38,442,734
<p>I am trying to create a copy of a worksheet using openpyxl.</p> <p>After researching I found this forum: <a href="http://stackoverflow.com/questions/27101024/copy-whole-worksheet-with-openpyxl">Copy whole worksheet with openpyxl</a></p> <p>Here is the documentation for copy_worksheet: <a href="http://openpyxl.read...
2
2016-07-18T17:30:51Z
38,445,015
<p>I believe I have figured out the answer. </p> <p>I was using version 2.4 but to be precise I was running version: openpyxl 2.4.0-a1.</p> <p>The copy_worksheet function was added as of version: openpyxl 2.4.0-b1</p> <p>Here is the documentation for 2.4.0-a1: <a href="http://openpyxl.readthedocs.io/en/default/" rel...
2
2016-07-18T19:57:44Z
[ "python", "excel", "openpyxl" ]
All Nodes shortest Paths
38,442,830
<p>I am a new user to Python. The following code is working for finding the shortest path from a source node, say B to all other nodes. I am interested to find shortest distance from every node.i.e, from A to all , from B to all, ..... from G to all. Can some body help me please how to do it. Thank you.</p> <pre><code...
0
2016-07-18T17:37:12Z
38,463,251
<p>If you are trying to loop over all the nodes, you can do a loop over the initial value of <code>current</code>. This will require minimal modification to your code:</p> <pre><code>nodes = ('A', 'B', 'C', 'D', 'E', 'F', 'G') distances = { 'B': {'A': 5, 'D': 1, 'G': 2}, 'A': {'B': 5, 'D': 3, 'E': 12, 'F' :5},...
0
2016-07-19T15:52:08Z
[ "python", "dijkstra" ]
Why does the tkinter QUIT2 widget require me to press it twice for it to activate?
38,442,853
<pre><code>from openpyxl import * from tkinter import * def inputGetter(str): print(str, end="") return input() class StartPage(Frame): global app def say_hi(self): test = SecondPage(master=root) app.destroy() test.mainloop() def createWidgets(self): self.QUIT = ...
0
2016-07-18T17:38:50Z
38,442,976
<p>You launch two mainloops, and thus require two call to 'quit' to leave your program.</p> <ol> <li>Either you launch your script from the interpreter (implicit mainloop) or you call <code>root</code> or <code>app</code> mainloop in you main program (not visible in your example, but required somehow to see the first ...
3
2016-07-18T17:47:31Z
[ "python", "tkinter" ]
python BankAccount program
38,442,867
<p>Create a class called BankAccount</p> <p>Create a constructor that takes in an integer and assigns this to a <code>balance</code> property.</p> <p>Create a method called <code>deposit</code> that takes in cash deposit amount and updates the balance accordingly.</p> <p>Create a method called <code>withdraw</code> ...
-6
2016-07-18T17:40:13Z
38,986,834
<p>It appears that there is an indentation issue with the module you are importing. The only way to fix this is by editing the file itself and checking the indentation, especially on line 2 <strong>as stated in the error message</strong>.</p>
0
2016-08-17T01:33:08Z
[ "python" ]
iterating through list of tuples in python and choosing certain elements
38,442,883
<p>I have a list </p> <pre><code>f_list = ["[('TTATGCTAAGTATC', 8)]", "[('TTATGCTAAGTATC', 8)]", "[('AGCTCCCCGTTTTC', 1)]", "[('AGCTCCCCGTTTTC', 35), ('TTCATTCCTCTCTC', 1)]", "[('TTATGCTAAGTATC', 4), ('TTACGCTACTCACC', 1)]"] </code></pre> <p>I want to make a new list with elements whose second element of a tuple is g...
-1
2016-07-18T17:40:49Z
38,443,233
<p>I'm not sure if this is the best way to go about it, but it works:</p> <pre><code>f_list = [ "[('TTATGCTAAGTATC', 8)]", "[('TTATGCTAAGTATC', 8)]", "[('AGCTCCCCGTTTTC', 1)]", "[('AGCTCCCCGTTTTC', 35)]", "[('TTCATTCCTCTCTC', 1)]", "[('TTATGCTAAGTATC', 4)]", "[('TTACGCTACTCACC', 1)]" ] f_n...
2
2016-07-18T18:04:06Z
[ "python" ]
iterating through list of tuples in python and choosing certain elements
38,442,883
<p>I have a list </p> <pre><code>f_list = ["[('TTATGCTAAGTATC', 8)]", "[('TTATGCTAAGTATC', 8)]", "[('AGCTCCCCGTTTTC', 1)]", "[('AGCTCCCCGTTTTC', 35), ('TTCATTCCTCTCTC', 1)]", "[('TTATGCTAAGTATC', 4), ('TTACGCTACTCACC', 1)]"] </code></pre> <p>I want to make a new list with elements whose second element of a tuple is g...
-1
2016-07-18T17:40:49Z
38,443,393
<p>As mentioned by Padraic, your list is a little strange. You have quotation marks where you don't need them, and put each tuple in a separate list with only one element. If you can clean up your original list, this should work the way you expect:</p> <pre><code>f_list = [('TTATGCTAAGTATC', 8), ('TTATGCTAAGTATC', 8),...
0
2016-07-18T18:12:53Z
[ "python" ]
How do I disable a test using py.test?
38,442,897
<p>Say I have a bunch of tests:</p> <pre><code>def test_func_one(): ... def test_func_two(): ... def test_func_three(): ... </code></pre> <p>Is there a decorator or something similar that I could add to the functions to prevent from py.test from running just that test? The result might look something li...
2
2016-07-18T17:41:44Z
38,442,940
<p>The <a href="http://doc.pytest.org/en/latest/skipping.html#marking-a-test-function-to-be-skipped" rel="nofollow"><code>skip</code> decorator</a> would do the job:</p> <pre><code>@pytest.mark.skip(reason="no way of currently testing this") def test_func_one(): # ... </code></pre> <p>(<code>reason</code> argumen...
3
2016-07-18T17:45:09Z
[ "python", "testing" ]
How do I disable a test using py.test?
38,442,897
<p>Say I have a bunch of tests:</p> <pre><code>def test_func_one(): ... def test_func_two(): ... def test_func_three(): ... </code></pre> <p>Is there a decorator or something similar that I could add to the functions to prevent from py.test from running just that test? The result might look something li...
2
2016-07-18T17:41:44Z
38,442,948
<p>Pytest has the skip and skipif decorators, similar to the Python unittest module (which uses <code>skip</code> and <code>skipIf</code>), which can be found in the documentation <a href="http://doc.pytest.org/en/latest/skipping.html" rel="nofollow">here</a>.</p> <p>Examples from the link can be found here:</p> <pre...
2
2016-07-18T17:45:30Z
[ "python", "testing" ]
How do I disable a test using py.test?
38,442,897
<p>Say I have a bunch of tests:</p> <pre><code>def test_func_one(): ... def test_func_two(): ... def test_func_three(): ... </code></pre> <p>Is there a decorator or something similar that I could add to the functions to prevent from py.test from running just that test? The result might look something li...
2
2016-07-18T17:41:44Z
38,443,078
<p>I'm not sure if it's depreciated, but you can also use the <code>pytest.skip</code> function inside of a test:</p> <pre><code>def test_valid_counting_number(): number = random.randint(1,5) if number == 5: pytest.skip('Five is right out') assert number &lt;= 3 </code></pre>
0
2016-07-18T17:54:16Z
[ "python", "testing" ]
Check if Python (3.4) Tkinter Entry is Full
38,442,910
<p>I am using a standard tkinter entry to input a directory path. When the user presses enter - if the physical length of the string exceeds that of the entry, I want the program to modify the displayed text to ...[end of directory]. I have the logistics of this figured out but as of yet <strong>I have no accurate way ...
0
2016-07-18T17:42:32Z
38,443,494
<p>You can use <a href="http://effbot.org/tkinterbook/entry.htm#Tkinter.Entry.xview-method" rel="nofollow"><code>xview</code></a> method of <code>Entry</code>. <code>xview</code> return the visible part of the text displayed in the entry. You can use it to interactively create a text that fit the entry.</p> <p>Here is...
1
2016-07-18T18:19:02Z
[ "python", "tkinter", "directory", "entry" ]
Python downloaded data in table form
38,442,935
<p>This is the code that is downloading data from table and output that on cmd. I want to know if the same data can be downloaded in the same structure of table like in rows and columns? This is what i have tried.</p> <p>code: </p> <pre><code>import urllib import re from urlparse import urlparse from bs4 import Beaut...
0
2016-07-18T17:44:31Z
38,443,175
<p>I think many people would recommend the use of the pandas library when working with tabular data. For well structured HTML, you can just blindly use pandas read_html.</p> <pre><code>import pandas as pd tables = pd.read_html("http://physics.iitd.ac.in/content/list-faculty-members") dataframe = tables[0] </code></pr...
1
2016-07-18T18:00:08Z
[ "python", "python-2.7" ]
How to convert a nested list for the use in sklearn?
38,443,049
<p>I have a long nested list in which each embedded list can have a different length or elements. I would like to flatten it in order to use each variable as a predictor in my model. The nested list looks like this:</p> <pre><code> [[u'Burgers',u'Bars'],[u'Local Services', u'Dry Cleaning &amp; Laundry'],[u'Shopping',...
1
2016-07-18T17:52:35Z
38,443,187
<p>You can first <em>flatten</em> the list then build the <em>scores</em> for the various <em>classes</em> from the <em>flattened</em> list, with a nested list comprehension by assigning <code>1</code> to values found in a given sublist (called <code>category</code>) and <code>0</code> if the <em>class</em> is not foun...
1
2016-07-18T18:00:59Z
[ "python", "list" ]
How to convert a nested list for the use in sklearn?
38,443,049
<p>I have a long nested list in which each embedded list can have a different length or elements. I would like to flatten it in order to use each variable as a predictor in my model. The nested list looks like this:</p> <pre><code> [[u'Burgers',u'Bars'],[u'Local Services', u'Dry Cleaning &amp; Laundry'],[u'Shopping',...
1
2016-07-18T17:52:35Z
38,443,364
<p>A pandas approach would be:</p> <pre><code>import pandas as pd L = [['Burgers', 'Bars'], ['Local Services', 'Dry Cleaning &amp; Laundry'], ['Shopping', 'Eyewear &amp; Opticians'], ['Restaurants']] ser = pd.Series([';'.join(i) for i in L]).str.get_dummies(';') </code></pre> <p><a href="http://i.stack.imgur.com/CQF...
1
2016-07-18T18:11:23Z
[ "python", "list" ]
How can I measure the distance between a raspberry pi and a moving/mobile beacon? Reducing noise in RSSI
38,443,092
<p>I would like to know the distance between a raspberry pi and a moving/mobile beacon.</p> <p>Has anyone implemented a kalman filter (preferably python) or determined a better algorithm for improving distance estimates, based on Radio Signal Strength measurements in a wireless Network environment?</p> <p>The algorit...
-1
2016-07-18T17:54:56Z
38,444,473
<p>In the <a href="https://github.com/AltBeacon/android-beacon-library/blob/master/src/main/java/org/altbeacon/beacon/service/ArmaRssiFilter.java" rel="nofollow">Android Beacon Library</a>, there is a ARMA filter that may be selected to choose RSSI samples for distance estimates. You can see the source code in Java he...
0
2016-07-18T19:24:17Z
[ "python", "bluetooth-lowenergy", "altbeacon", "kalman-filter", "rssi" ]
How I can assign value to variable using a button?
38,443,208
<p>I'm trying to write a graphic calculator using buttons. </p> <p>How I can assign value to variable using a button?</p> <p>I wrote the code:</p> <pre><code>from tkinter import * a=0 def button_0a(): a=0 return 0 button0= Button(kalkulator, text="0", command=przycisk_0a) button0.grid(row=1, column=0) </...
-4
2016-07-18T18:02:36Z
38,446,934
<p><code>przycisk_0a</code> is your callback function bind to the <code>button0</code> button, so you must define your function, but you have defined the <code>button0</code> button which is <b>nonsense</b>. <br> It must be like this:</p> <pre><code>def przycisk_0a(): </code></pre>
0
2016-07-18T22:29:09Z
[ "python", "python-3.x", "tkinter" ]
How to subset a very large HDF5 dataset from file and write to another file?
38,443,230
<p>I have a very large dense matrix (1M * 30K) stored in a hdf5 file. I was able to read the hdf5 file using <code>h5py</code> using the following script:</p> <pre><code>import numpy as np import h5py f = h5py.File('myFile.hdf5', 'r') mat = f['matrix'] # sub_mat = mat[:, :1000] # write sub_mat into another hdf5 file ...
1
2016-07-18T18:04:01Z
38,443,731
<p>After checking the docs of <code>h5py</code>, I found there's a classmethod for <a href="http://docs.h5py.org/en/latest/high/dataset.html" rel="nofollow"><code>h5py.Dataset</code></a> named <code>write_direct</code> that can directly write matrix to file. </p> <p>Therefore what I need to do is to create another h5 ...
1
2016-07-18T18:32:47Z
[ "python", "numpy", "matrix", "hdf5", "h5py" ]
SMOP bad conversion
38,443,292
<p>I'm using <a href="https://github.com/victorlei/smop" rel="nofollow">smop</a> python script to convert a matlab code in python.</p> <p>In my test matlab code, I've got this:</p> <pre><code>a=10^6*[355,355,373,373,373,373,373]' </code></pre> <p>and it generates me to </p> <pre><code>a = 10 ** 6 * [355,355,373,373...
0
2016-07-18T18:07:18Z
38,443,560
<p>The problem is that in Python the operator <code>*</code> is polymorphic. If the operands are numeric it returns the product of both numbers, but if one operand is an integer (say <code>n</code>) and the other is a sequence (namely a string, list or tuple) it concatenates the sequence <code>n</code> times and return...
1
2016-07-18T18:22:31Z
[ "python", "matlab" ]
Unitest for function that handles exception
38,443,299
<p>I have a function that parses a xml string if there are invalid characters, the etree.parse raises parse error and my function handles that by decoding the string and encoding the string back. How do it test the part that handles the exception? It returns normal output for invalid data as for valid data. </p> <pre>...
1
2016-07-18T18:07:53Z
38,443,345
<p>If you're using <code>unittest</code> and <code>TestCase</code>, you can use <a href="https://docs.python.org/2.7/library/unittest.html#unittest.TestCase.assertRaises" rel="nofollow"><code>assertRaises</code></a></p> <pre><code>class TestSuite(TestCase): def test_get_parse_tree(self): with self.assertR...
1
2016-07-18T18:10:09Z
[ "python", "unit-testing" ]
Unitest for function that handles exception
38,443,299
<p>I have a function that parses a xml string if there are invalid characters, the etree.parse raises parse error and my function handles that by decoding the string and encoding the string back. How do it test the part that handles the exception? It returns normal output for invalid data as for valid data. </p> <pre>...
1
2016-07-18T18:07:53Z
38,443,810
<p>Your unit test doesn't necessarily need to care which, if any, exception is raised by a bad input. Simply call the function with the bad input, and verify that either the expected "fixed" value is returned, or verify that an unrecoverable error occurs.</p> <pre><code>self.assertEqual(get_parse_tree("good input"), "...
1
2016-07-18T18:37:52Z
[ "python", "unit-testing" ]
Using get_inline_instances overwrites add permission?
38,443,317
<p>I currently have a bunch of inlines that all inherit from a base Inline Class set up like this:</p> <pre><code>class BaseInlineAdmin(admin.TabularInline): extra = 0 def has_delete_permission(self, request, obj=None): return False def has_add_permission(self, request): return False </c...
1
2016-07-18T18:08:46Z
38,445,298
<p><code>get_inline_instances</code> is the method that checks the permission. If you want to check for permissions, you either have to call <code>super().get_inline_instances()</code>, or you need to replicate the code from the <a href="https://github.com/django/django/blob/bc53af13cbf09b0cbac945426c2d51d0ca52fff3/dja...
1
2016-07-18T20:16:59Z
[ "python", "django", "django-admin" ]
raise ValueError("Expected "+item_name+" in",line,"at",line[p:]) ValueError: ('Expected version spec in', 'django~=1.9.0', 'at', '~=1.9.0')
38,443,339
<p>I am following <a href="http://tutorial.djangogirls.org/en/django_installation/" rel="nofollow">this tutorial</a> on Windows 7 with Python 3. However I get this error:</p> <pre><code>PS C:\Users\jalal&gt; C:/Python34/python -m pip install django~=1.9.0 Exception: Traceback (most recent call last): File "C:\Python...
0
2016-07-18T18:10:05Z
38,443,440
<p>Do away with <code>-r</code> unless you are reading from a file. Use:</p> <pre><code>C:/Python34/python -m pip install django~=1.9.0 </code></pre>
0
2016-07-18T18:15:41Z
[ "python", "django", "windows", "windows-7", "pip" ]
raise ValueError("Expected "+item_name+" in",line,"at",line[p:]) ValueError: ('Expected version spec in', 'django~=1.9.0', 'at', '~=1.9.0')
38,443,339
<p>I am following <a href="http://tutorial.djangogirls.org/en/django_installation/" rel="nofollow">this tutorial</a> on Windows 7 with Python 3. However I get this error:</p> <pre><code>PS C:\Users\jalal&gt; C:/Python34/python -m pip install django~=1.9.0 Exception: Traceback (most recent call last): File "C:\Python...
0
2016-07-18T18:10:05Z
38,443,894
<p>It appears that version (1.5.6) of <code>pip</code> does not recognize the <em>compatible release</em> specifier <code>~=</code>.</p> <p>You can try the following version specifications which are equivalent to <code>~=1.9.0</code>:</p> <pre><code>pip install django&gt;=1.9.0 </code></pre> <p>Or:</p> <pre><code>p...
1
2016-07-18T18:42:19Z
[ "python", "django", "windows", "windows-7", "pip" ]
Efficient way to look in list of lists?
38,443,398
<p>I am continuously creating a randomly generated list, <code>New_X</code> of size 10, based on 500 columns. </p> <p>Each time I create a new list, it must be unique, and my function <code>NewList</code> only returns <code>New_X</code> once it hasn't already been created and appended to a <code>List_Of_Xs</code></p> ...
3
2016-07-18T18:13:16Z
38,443,591
<p>So let me get this straight since the code doesn't appear complete: 1. You have an old list that is constantly growing with each iteration 2. You calculate a list 3. You compare it against each of the lists in the old list to see if you should break the loop?</p> <p>One option is to store the lists in a set instea...
1
2016-07-18T18:24:01Z
[ "python", "numpy" ]
Efficient way to look in list of lists?
38,443,398
<p>I am continuously creating a randomly generated list, <code>New_X</code> of size 10, based on 500 columns. </p> <p>Each time I create a new list, it must be unique, and my function <code>NewList</code> only returns <code>New_X</code> once it hasn't already been created and appended to a <code>List_Of_Xs</code></p> ...
3
2016-07-18T18:13:16Z
38,445,407
<p>As I observed in a comment, the array comparison is potentially quite slow, especially as the list gets large. It has to create arrays each time, which consumes time.</p> <p>Here's a set implementation</p> <p>Function to create a 10 element list:</p> <pre><code>def foo(N=10): return np.random.randint(0,10,N)...
1
2016-07-18T20:24:19Z
[ "python", "numpy" ]
how to shift value in dataframe using pandas?
38,443,402
<p>I have data like this, without z1, what i need is to add a column to DataFrame, so it will add column z1 and represent values as in the example, what it should do is to shift z value equally on 1 day before for the same Start date. </p> <p><a href="http://i.stack.imgur.com/DUqvI.png" rel="nofollow"><img src="http:...
3
2016-07-18T18:13:42Z
38,443,914
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.DataFrameGroupBy.shift.html" rel="nofollow"><code>DataFrameGroupBy.shift</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>merge</code></a>:</p> <pre><c...
3
2016-07-18T18:44:05Z
[ "python", "pandas", "dataframe" ]
In Python's urllib, how can we get a URL which is updated after the call?
38,443,509
<p>I am using BeautifulSoup to scrape a webpage. However, when I make the call (using urllib2 + Python 3.4) in a browser, the URL changes to a unique one based on GUID every time a fresh call is made. For eg. if I make the call <a href="http://www">http://www</a>..com, it changes to <strong><a href="http://www">http://...
0
2016-07-18T18:19:53Z
38,443,584
<p>The <a href="https://docs.python.org/2/library/urllib2.html#urllib2.urlopen" rel="nofollow"><code>.geturl()</code></a> method exists precisely for this purpose:</p> <pre><code>from urllib2 import urlopen print urlopen(url).geturl() </code></pre>
1
2016-07-18T18:23:44Z
[ "python", "beautifulsoup" ]
How to store text, and use for an element search, in Selenium and Python
38,443,522
<p>I've tried this a few different ways, but I am unable to accomplish what should be straight forward. Here's what I am trying to do as an example:</p> <pre><code>driver.find_element_by_class_name('foo').text driver.find_element_by_class_name('foo').click() if ('text') in driver.find_element_by_class_name('bar') ...
0
2016-07-18T18:20:52Z
38,443,767
<p>You are pretty close... I think this is what you are looking for. Assign the first element's text to a variable, <code>searchText</code>. See if <code>searchText</code> is in the text of the next element and then print the result.</p> <pre><code>searchText = driver.find_element_by_class_name('foo').text print "sear...
0
2016-07-18T18:34:38Z
[ "python", "python-2.7", "selenium", "selenium-webdriver" ]
Spawning child process with express end-point
38,443,542
<p>I am trying run my python programs in my express server using child processes. The method works if it is plain NodeJS, but it is not working on my API end point.</p> <pre><code>var spawn = require('child_process').spawn, a = spawn('python', ['test.py']); router.get('/test', function(req, res, next) { a.stdou...
0
2016-07-18T18:21:33Z
38,444,102
<p>Without seeing your <code>test.py</code> source code, I'm assuming that <code>test.py</code> exits after it outputs all of its data. If that is the case, you will need to move your call to <code>spawn()</code> <em>inside</em> the route handler.</p> <p>If this route handler gets called often, you may need to look in...
2
2016-07-18T18:58:08Z
[ "python", "node.js", "express", "child-process" ]
Convert a Python (3.5.2) File into an exe?
38,443,585
<p>is there any surefire way to convert a Python (3.5.2) File into an exe? I have seen Pyinstaller, py2exe and cx_Freeze. cx_Freeze does not have a Python 3.5 version, only 3.4 so it isnt compatible. Py2exe works only for Python 2 and while I had some success with Pyinstaller, it returned an error relating to 9130 WARN...
0
2016-07-18T18:23:44Z
38,446,660
<p>I used py2exe to convert python 3 files to exe files. I haven't tested with version 3.5 but this website says that this version of py2exe works with any python 3 versions.</p> <ol> <li>Download and install <a href="https://pypi.python.org/pypi/py2exe/0.9.2.2" rel="nofollow">py2exe</a> </li> <li>Navigate to your pyt...
-1
2016-07-18T22:00:32Z
[ "python", "pygame", "exe" ]
How to split merged cells in a CSV file using python
38,443,609
<p>Is there any way to split/unmerge cells in a CSV file using python? What I want is explained below -</p> <p><a href="http://i.stack.imgur.com/4GYMl.png" rel="nofollow"><img src="http://i.stack.imgur.com/4GYMl.png" alt="enter image description here"></a></p> <p>The result should a new CSV file with following entrie...
0
2016-07-18T18:24:53Z
38,443,822
<p>It can be done fairly simply with <a href="http://pandas.pydata.org/" rel="nofollow"><code>pandas</code></a>:</p> <pre><code>d = pandas.read_csv('your_file.csv') d.fillna(method='ffill', inplace=True) d.to_csv('new_file.csv', index=False) </code></pre> <p>Basically this just forward-fills empty cells in each colum...
1
2016-07-18T18:38:32Z
[ "python", "csv", "split" ]
How to split merged cells in a CSV file using python
38,443,609
<p>Is there any way to split/unmerge cells in a CSV file using python? What I want is explained below -</p> <p><a href="http://i.stack.imgur.com/4GYMl.png" rel="nofollow"><img src="http://i.stack.imgur.com/4GYMl.png" alt="enter image description here"></a></p> <p>The result should a new CSV file with following entrie...
0
2016-07-18T18:24:53Z
38,443,886
<p>Of course <code>pandas</code> is the right answer. Regardless, here is a non-Pandas solution:</p> <pre><code>import csv from itertools import izip_longest with open('input.csv') as input_file: input_file = csv.reader(input_file) with open('output.csv', 'w') as output_file: output_file = csv.writer(...
0
2016-07-18T18:42:05Z
[ "python", "csv", "split" ]
Import Error :cannot import name get_model
38,443,628
<pre><code>File "C:\Python27\Lib\site-packages\file_picker\forms.py,line 5 in &lt;module&gt; from django.db.models import Q,get_model ImportError:cannot import name get_model </code></pre> <p>I am using django 1.9.7 and file_picker 0.2.2 I don't seem to have any solution to this problem</p>
1
2016-07-18T18:26:15Z
38,444,546
<p>Try using <code>django.apps</code> instead:</p> <pre><code>from django.apps import apps apps.get_model('Model') </code></pre> <p><a href="https://docs.djangoproject.com/en/dev/ref/applications/#django.apps.AppConfig.get_model" rel="nofollow">https://docs.djangoproject.com/en/dev/ref/applications/#django.apps.AppC...
1
2016-07-18T19:28:42Z
[ "python", "django", "file", "picker" ]
Display of dictionary in django
38,443,631
<p>My List </p> <pre><code>book_details = [ {'author':'abc', 'book_name':'xyz', 's_no':1}, {'author':'efg', 'book_name':'ijk', 's_no':2} ] </code></pre> <p>My code:</p> <pre><code>{% for dict in details %} &lt;tr&gt; {% for key, value in dict.items %} &lt;td&gt;{{ value }}&lt;/td&gt; ...
-1
2016-07-18T18:26:21Z
38,444,784
<p>Right now you are iterating through each key-value pair in the dictionary, so your code is outputting dictionary values in the order in which they are stored in the dictionary, which happens to be:</p> <pre><code>Author Book_name S_no </code></pre> <p>So, you have two options.</p> <ol> <li><p><strong>Change the o...
0
2016-07-18T19:43:03Z
[ "python", "django", "dictionary" ]
Display of dictionary in django
38,443,631
<p>My List </p> <pre><code>book_details = [ {'author':'abc', 'book_name':'xyz', 's_no':1}, {'author':'efg', 'book_name':'ijk', 's_no':2} ] </code></pre> <p>My code:</p> <pre><code>{% for dict in details %} &lt;tr&gt; {% for key, value in dict.items %} &lt;td&gt;{{ value }}&lt;/td&gt; ...
-1
2016-07-18T18:26:21Z
38,587,879
<pre><code>{% for dict in details %} &lt;tr&gt; &lt;td&gt;{{dict.s_no}}&lt;/td&gt; &lt;td&gt;{{dict.book_name}}&lt;/td&gt; &lt;td&gt;{{dict.author}}&lt;/td&gt; &lt;/tr&gt; {% endfor%} </code></pre>
0
2016-07-26T10:51:45Z
[ "python", "django", "dictionary" ]
Common legend for all the pie charts using matplotlib
38,443,649
<p>I create the 7 plots using the below code. I would like to have a common legend for all the 7 plots, preferably in the top right corner. For green region, legend should be 'Sending data', for red region, it should be 'Not sending data'. I tried using figlegend but could not achieve it. Any help would be appreciated....
0
2016-07-18T18:27:11Z
38,445,382
<p>The legend needs only to be called once otherwise you would get 7 different legends showing. An example of which I have shown below. Note that you will have to substitute in your own data into <code>ax.pie()</code>:</p> <pre><code>data1 = (10,90) # some data to be plotted data2 = (40,50) data3 = (70,30) labels = ...
2
2016-07-18T20:22:50Z
[ "python", "matplotlib" ]
How to store the values of a set distinct subsets using dictionary in Python?
38,443,690
<p>How could I use a list or tuple as a key for a dictionary in Python? Let us suppose I have a set of subsets as <code>L = [[1, 2, 3], [4, 5], [6, 19]</code>. Now I want store a value for each subset. How could I handle this in Python?</p>
0
2016-07-18T18:30:24Z
38,443,795
<p>One way you can do it is, to convert the individual elements as the key. </p> <p>Example:</p> <pre><code>{"".join(map(str, x)): x for x in L} </code></pre> <p>This would give an output of</p> <pre><code>{'123': [1, 2, 3], '45': [4, 5], '619': [6, 19]} </code></pre> <p>for your example</p> <p>Note that it is no...
1
2016-07-18T18:36:35Z
[ "python" ]
Numpy: can I do tensor Hadamard multiplication without einsum?
38,443,703
<p>I've got a rank four tensor A (say indices (a, b, i, j)) and a rank two tensor B (say indices (i, j)) and I want to compute a kind of Hadamard multiplication of them. </p> <p>That is, if we call the product C, I want <code>C[a,b,i,j] == A[a,b,i,j] * B[i,j]</code>. There is a fairly straightforward way to do this w...
2
2016-07-18T18:31:27Z
38,443,724
<pre><code>C = A * B </code></pre> <p>Following the <a href="http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html" rel="nofollow">broadcasting rules</a>, NumPy will line up the shapes of <code>A</code> and <code>B</code> starting from the last axes:</p> <pre><code>A: (a, b, i, j) B: (i, j) </code></pre...
4
2016-07-18T18:32:21Z
[ "python", "numpy" ]
Check value of a 2d array for different column indices in each row of 2d array
38,443,808
<p>I have some a binary 2D numpy array (<code>prediction</code>) like:</p> <pre><code>[ [1 0 1 0 1 1], [0 0 1 0 0 1], [1 1 1 1 1 0], [1 1 0 0 1 1], ] </code></pre> <p>Each row in the 2D array is the classification of a sentence as being certain categories, and each column in the 2D array corresponds to the classifica...
1
2016-07-18T18:37:43Z
38,443,978
<p>Something along these lines should do it efficiently, though not in a position to test right now:</p> <pre><code>rows = len(prediction) p = prediction[np.arange(rows), catIndex.flatten()] catResult = np.empty(rows, 'S1').fill('n') catResult[p] = categories[catIndex.flatten()][p] </code></pre>
0
2016-07-18T18:48:07Z
[ "python", "arrays", "numpy", "multidimensional-array" ]
Check value of a 2d array for different column indices in each row of 2d array
38,443,808
<p>I have some a binary 2D numpy array (<code>prediction</code>) like:</p> <pre><code>[ [1 0 1 0 1 1], [0 0 1 0 0 1], [1 1 1 1 1 0], [1 1 0 0 1 1], ] </code></pre> <p>Each row in the 2D array is the classification of a sentence as being certain categories, and each column in the 2D array corresponds to the classifica...
1
2016-07-18T18:37:43Z
38,446,563
<p>Make the 2d array:</p> <pre><code>In [54]: M=[[1,0,1,0,1,1],[0,0,1,0,0,1],[1,1,1,1,1,0],[1,1,0,0,1,1]] In [55]: M=np.array(M) </code></pre> <p>Column index with <code>ind</code>, with [0,1,2,3] as the row index:</p> <pre><code>In [56]: ind=[0,4,5,2] In [57]: m=M[np.arange(len(ind)),ind] In [58]: m Out[58]: ar...
1
2016-07-18T21:51:07Z
[ "python", "arrays", "numpy", "multidimensional-array" ]
how to let python consider links in a list as a single item
38,443,816
<p>I have this script:</p> <pre><code>import urllib.request from bs4 import BeautifulSoup url= 'https://www.inforge.net/xi/forums/liste-proxy.1118/' soup = BeautifulSoup(urllib.request.urlopen(url), "lxml") base = ("https://www.inforge.net/xi/") for tag in soup.find_all('a', {'class':'PreviewTooltip'}): links =...
2
2016-07-18T18:38:19Z
38,443,864
<p><code>final</code> has a type of <code>str</code>, as such, indexing it in position <code>0</code> will result in the first character of the <code>url</code> getting printed, specifically <code>h</code>.</p> <p>You either need to print all of <code>final</code> if you're using it as a <code>str</code>:</p> <pre><c...
4
2016-07-18T18:41:03Z
[ "python", "list", "python-3.x" ]
regular expression pattern match excluding a list of cases
38,443,839
<p>I wanna match the street name pattern which consists of several capital case words excluding some cases but I do not know how to do it.</p> <p>The pattern is "([A-Z][a-z]+ {1,3})" (Let's assume the name of a street consists of 1-3 words) and a short version block list is ["Apt","West","East"] which denotes either d...
1
2016-07-18T18:39:54Z
38,445,474
<p>You may use</p> <pre><code>\b(?!(?:Apt|West|East)\b)[A-Z][a-z]+(?: (?!(?:Apt|West|East)\b)[A-Z][a-z]+){0,2} </code></pre> <p>See the <a href="https://regex101.com/r/wN4mS7/1" rel="nofollow">regex demo</a></p> <p>What I did:</p> <ul> <li>Fixed your regex to actually match 1 to 3 words: <code>[A-Z][a-z]+(?: [A-Z][...
0
2016-07-18T20:28:10Z
[ "python", "regex" ]
How does one set specific vim-bindings in Ipython 5.0.0
38,443,907
<p>I understand that because Ipython 5.0.0 uses a new input library (prompt_toolkit) it no longer defaults to the editor mode specified in .inputrc (*nix). This option has to be set in an Ipython profile configuration file (see <a href="http://stackoverflow.com/a/38329940/2915339">http://stackoverflow.com/a/38329940/29...
4
2016-07-18T18:43:30Z
38,810,821
<p>You're right. <code>prompt_toolkit</code> ignores <code>.inputrc</code>. There does not seem to be a way to define custom keybindings for the <code>vi</code> mode in the IPython 5.0.0 profile configuration file. </p> <p>Here's workaround I'm currently using. It's not pretty, but it works for now. </p> <p>According...
1
2016-08-07T04:12:15Z
[ "python", "linux", "vim", "ipython", "prompt-toolkit" ]
Access a Flask extension that is defined in the app factory
38,443,938
<p>I am using the app factory pattern to set up my Flask application. My app uses the Flask-Babel extension, and that is set up in the factory as well. However, I want to access the extension in a blueprint in order to use it, </p> <p>The factory is in <code>__init__.py</code>.</p> <pre><code>def create_app(object_...
1
2016-07-18T18:45:58Z
38,444,061
<p>Flask extensions are designed to be instantiated without an app instance for exactly this case. Outside the factory, define your extensions. Inside the factory, call <code>init_app</code> to associate the app with the extension.</p> <pre><code>babel = Babel() def create_app(): ... babel.init_app(app) ...
1
2016-07-18T18:54:26Z
[ "python", "flask", "babel" ]
string indices must be integers, not str - Python script
38,443,980
<p>Trying to write a small script to make my life easier as I interface with the warehouse. Wanting to make something that will let me export a simple csv file with all the different styles, sizes, colors, and UPC codes of the products I need to fulfill. Here is part of the code that deals with getting the UPC codes fr...
1
2016-07-18T18:48:09Z
38,444,032
<pre><code>UPC = UPCget(Style, Color, Size) </code></pre> <p>Here's the problem. <code>UPCget</code> works fine in the first iteration of your loop, but then <code>UPC</code> gets overwritten. It's no longer a dict, now it's a string. Then in the second iteration it fails because you can't index a string the way <code...
6
2016-07-18T18:52:15Z
[ "python", "string", "dictionary" ]
Writing a Boolean Expression using Python
38,444,010
<p>I am trying to write a boolean expression in Python, but it appears Python can only do XOR expressions with bit operations.</p> <p>What would be the best way to go about writing this expression in Python without the XOR operator.</p> <pre><code>(A ^ B ^ C ^ D) U ((B U C U D)' XOR A) </code></pre> <p>EDIT:</p> <p...
1
2016-07-18T18:50:10Z
38,444,293
<p>Just use the bitwise <code>^</code> operator. Python's booleans return a boolean when <code>^</code>-ed together:</p> <pre><code>&gt;&gt;&gt; True ^ True False &gt;&gt;&gt; True ^ False True </code></pre> <p>The <code>and</code> and <code>or</code> operators exist primarily to support short-circuiting, but XOR can...
3
2016-07-18T19:11:45Z
[ "python", "boolean-logic", "boolean-expression" ]
Writing a Boolean Expression using Python
38,444,010
<p>I am trying to write a boolean expression in Python, but it appears Python can only do XOR expressions with bit operations.</p> <p>What would be the best way to go about writing this expression in Python without the XOR operator.</p> <pre><code>(A ^ B ^ C ^ D) U ((B U C U D)' XOR A) </code></pre> <p>EDIT:</p> <p...
1
2016-07-18T18:50:10Z
38,444,854
<p><code>(A and B and C and D) or ((A and not (B or C or D)) or (not A and (B and C and D)))</code> will simplify to this: <code>(B and C and D) or (A and not (B or C or D))</code></p>
1
2016-07-18T19:47:43Z
[ "python", "boolean-logic", "boolean-expression" ]
Script Parse Exception with python elasticsearch API
38,444,048
<p>I wrote the following code to set a template for new indexes:</p> <pre><code>from elasticsearch import Elasticsearch doc = { "template": "te*", "settings": { "number_of_shards": 1 }, "mappings": { "type1": { "_source": { "enabled": "false" }, "properties": { "...
0
2016-07-18T18:53:34Z
38,444,773
<p>I took the put_template method as a query template but its meant to be a index template: Library usage should look like this:</p> <pre><code>es = Elasticsearch([{'host': "127.0.0.1", "port": 9200}]) IndicesClient(es).put_template(name="f_1", body=request_body) </code></pre>
0
2016-07-18T19:42:42Z
[ "python", "elasticsearch" ]
pandas: check whether an element is in dataframe or given column leads to strange results
38,444,180
<p>I am doing some data handling based on a DataFrame with the shape of <code>(135150, 12)</code> so double checking my results manually is not applicable anymore.</p> <p>I encountered some 'strange' behavior when I tried to check if an element is part of the dataframe or a given column.</p> <p>This behavior is repro...
2
2016-07-18T19:03:26Z
38,444,454
<p>The underlying issue, as Divakar suggested, is floating point precision. Because DataFrames/Series are built on top of numpy, there isn't really a penalty for using numpy methods though, so you can just do something like:</p> <pre><code>df['example_value'].apply(lambda x: np.isclose(x, val)).any() </code></pre> <p...
3
2016-07-18T19:23:12Z
[ "python", "numpy", "pandas", "element" ]
Connecting Matlab to Tensorflow
38,444,202
<p>I am using an open source Matlab toolbox for BCI (brain computer interface). I want to send the brain imaging data over to Tensorflow for classification and get the results back to Matlab. Is there any way to pass data structures from Matlab to Tensorflow and get the results back into Matlab?</p>
1
2016-07-18T19:05:35Z
38,751,824
<p>So far the best way I found is to run your python module in matlab through matlab's now built-in mechanism for connecting to python:</p> <p>I wrote my python script in a .py file and in there I imported tensorflow and used it in different functions. You can then return the results to matlab by calling</p> <pre><co...
0
2016-08-03T19:09:43Z
[ "python", "matlab", "classification", "tensorflow", "deep-learning" ]
Error converting GUI to standalone executable using Py2exe
38,444,230
<p>I am using <code>py2exe</code> to convert my program with multiple GUIs to a standalone executable. I used PyQt to create the GUIs. The main script I run instantiates the main UI, which contains buttons, tabs, etc. that can open sub-UIs. The main script is <code>main_ui.py</code>. </p> <p>I followed the tutorial on...
0
2016-07-18T19:07:40Z
38,457,894
<p>I have encountered the same problem. There is very probably a better way, but removing the folder "PyQt4\uic\port_v3" solves the issue.</p> <p>(see <a href="http://python.6.x6.nabble.com/PyQt-4-7-and-py2exe-error-td1922933.html" rel="nofollow">http://python.6.x6.nabble.com/PyQt-4-7-and-py2exe-error-td1922933.html<...
1
2016-07-19T11:57:27Z
[ "python", "user-interface", "pyqt4", "executable", "py2exe" ]
How can I check if a pixel is green in a RGB image?
38,444,243
<p>I'm using opencv and numpy to process some satellite images.</p> <p>I need to differentiate what is "land" from what is "green" (crops and vegetation).</p> <p>My question is: <strong>How can I decide which values are close to green in the RGB format?</strong></p> <p>What I'm doing so far is:</p> <pre><code>img =...
-1
2016-07-18T19:08:35Z
38,446,098
<p>You could use InRange function to find colors in specific range, because you will not be able to find green color from satelites just with one or few values of pixels. InRange function will help you to find a range of set colors (you should set the range of green colors) and return an image with the coordinates of t...
0
2016-07-18T21:14:25Z
[ "python", "opencv", "image-processing", "colors", "rgb" ]