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
Interpolate Matplotlib Array to an Arbitrary Length
38,724,866
<p>I am looking for a method of interpolating and simultaneously extending a 2D numpy array to an arbitrary length. For example say my array is </p> <pre><code>array = [0,0,0] [1,1,1] [2,2,2] </code></pre> <p>After calling the function say I want an array of length 5:</p> <pre><code>new_array = [0, 0...
1
2016-08-02T15:36:52Z
38,725,352
<p>You can try:</p> <pre><code>from scipy import interpolate n = 5 np.column_stack([interpolate.interp1d(c,c)(np.linspace(c[:1,], c[-1:], n)) for c in arr.T]) Out[45]: array([[ 0. , 0. , 0. ], [ 0.5, 0.5, 0.5], [ 1. , 1. , 1. ], [ 1.5, 1.5, 1.5], [ 2. , 2. , 2. ]]) </code></pre>...
0
2016-08-02T15:58:50Z
[ "python", "arrays", "numpy", "scipy" ]
web crawling a table of links
38,724,877
<p>I'm creating a script in python that goes through a table with three columns. I created a list where every link in the first column is inserted into the list. And then I loop through. When looping, I click into the link, print a statement to make sure it actually clicked into the link, and then go to the previous pa...
0
2016-08-02T15:37:14Z
38,725,225
<p>I am not sure you already saw the official Selenium documentation:</p> <blockquote> <p>A stale element reference exception is thrown in one of two cases, the first being more common than the second: The element has been deleted entirely. The element is no longer attached to the DOM.</p> </blockquote> <p>In y...
1
2016-08-02T15:53:43Z
[ "python", "selenium", "web-crawler" ]
Iterating over multiindex dataframe (Python) and assigning dicts to index-value pairs
38,725,011
<p>I am at my wit's end with this... I have a dataframe of three columns (aff_id, mkt and bkgs) I grouped by two of them (aff_id and mkt) :</p> <pre><code>df_gb_aff = df.groupby(["affiliate_id", 'mkt']).sum() df_gb_aff.sort('bkgs', ascending=False, inplace=True) </code></pre> <p>to give me a multiindex dataframe that...
2
2016-08-02T15:43:22Z
38,725,212
<p>Another solution with dict comprehension:</p> <pre><code>d = {idx[1]: df_gb_aff.ix[idx][0] for idx in df_gb_aff.index} print (d) {'446bb566f202': 1206.589522, 'bcab9d6ec630': 1910.7071239999998, '0e9013464c4c': 1203.5323100000001, 'dbe759c691eb': 1203.979908, 'b7d0dbd38376': 1374.9246840000001} print (d['bcab...
1
2016-08-02T15:53:20Z
[ "python", "pandas", "group-by" ]
Is it possible to use regular expressions (or more general templates) to define variables?
38,725,013
<p>Let us consider the following template:</p> <pre><code>*aaa*bbb* </code></pre> <p>It should return all strings that contain <code>aaa</code> as well as <code>bbb</code> as sub-strings (with the restriction that <code>bbb</code> comes after <code>aaa</code>).</p> <p>What I want to have is a possibility to use sub-...
0
2016-08-02T15:43:27Z
38,772,348
<p>Sounds like you want references, which are part of most regular expression libraries, including Python's. </p> <pre><code>ccc_str = re.sub("(.*)aaa(.*)bbb(.*)", r"\2ccc\1", "XXXaaaYYYbbbZZZ") </code></pre>
1
2016-08-04T16:06:20Z
[ "python", "regex", "templates", "pattern-matching" ]
Scanning a list - IndexError: list index out of range
38,725,014
<p>I have created a Hangman game that has one bug: if you guess the same letter twice it will break. I have created a list of every alphabet letter and when the player guesses that letter it will be removed from the list, which displays the remaining characters available to guess. This is accomplished through the .rem...
0
2016-08-02T15:43:32Z
38,725,471
<p>Your issue is using indexes to loop through the list, and changing the size of the list at the same time. You can either loop through the items directly:</p> <pre><code>for letter in alphabet: if letter == guess: alphabet.remove(guess) </code></pre> <p>Or you can break when you've removed the letter:</...
1
2016-08-02T16:04:20Z
[ "python", "indexoutofboundsexception" ]
Scanning a list - IndexError: list index out of range
38,725,014
<p>I have created a Hangman game that has one bug: if you guess the same letter twice it will break. I have created a list of every alphabet letter and when the player guesses that letter it will be removed from the list, which displays the remaining characters available to guess. This is accomplished through the .rem...
0
2016-08-02T15:43:32Z
38,725,485
<p>There is no need to loop over the alphabet, you could check if the letter is still in the alphabet with: </p> <pre><code>if guess in alphabet: #And do the function here: alphabet.remove(guess) </code></pre> <p>Your for-loop contains a flaw. You are removing the guessed letter for the alphabet, but then you...
2
2016-08-02T16:04:59Z
[ "python", "indexoutofboundsexception" ]
Scanning a list - IndexError: list index out of range
38,725,014
<p>I have created a Hangman game that has one bug: if you guess the same letter twice it will break. I have created a list of every alphabet letter and when the player guesses that letter it will be removed from the list, which displays the remaining characters available to guess. This is accomplished through the .rem...
0
2016-08-02T15:43:32Z
38,725,500
<p>Your problem is that after you remove an item from the array, it now has one less item, meaning that you can't go to the former end of the array. If your array of letters is 26 long, and you remove one letter, you can't access the 26th element anymore, because the array now only has 25 elements. After you guess corr...
0
2016-08-02T16:05:41Z
[ "python", "indexoutofboundsexception" ]
Scanning a list - IndexError: list index out of range
38,725,014
<p>I have created a Hangman game that has one bug: if you guess the same letter twice it will break. I have created a list of every alphabet letter and when the player guesses that letter it will be removed from the list, which displays the remaining characters available to guess. This is accomplished through the .rem...
0
2016-08-02T15:43:32Z
38,725,548
<p>It's a really bad thing remove element from an iterable when you are looping on it or on its length! Better do something like this</p> <pre><code>alphabet = ['a','b','c'] print 'You have 10 guesses left' for count in range(10): guess = raw_input(str('Guess a letter: ')) if guess in alphabet: alpha...
0
2016-08-02T16:07:57Z
[ "python", "indexoutofboundsexception" ]
Scanning a list - IndexError: list index out of range
38,725,014
<p>I have created a Hangman game that has one bug: if you guess the same letter twice it will break. I have created a list of every alphabet letter and when the player guesses that letter it will be removed from the list, which displays the remaining characters available to guess. This is accomplished through the .rem...
0
2016-08-02T15:43:32Z
38,913,364
<p>I am running to an similar issue and i am pretty new to python . Can anyone help with below code . What i am trying to is to find if a particular tag is present in AWS Autoscaling group and if that tag present i need to update that particular autoscaling group . Autoscaling group describe api can go thro max of 100 ...
0
2016-08-12T08:29:09Z
[ "python", "indexoutofboundsexception" ]
`ValueError: too many values to unpack (expected 4)` with `scipy.stats.linregress`
38,725,018
<p>I know that this error message (<code>ValueError: too many values to unpack (expected 4)</code>) appears when more variables are set to values than a function returns. </p> <p><code>scipy.stats.linregress</code> returns 5 values according to the scipy documentation (<a href="http://docs.scipy.org/doc/scipy/referenc...
-1
2016-08-02T15:43:41Z
38,725,283
<p>Your problem originates from slicing the <code>X</code> and <code>Y</code> arrays. Also you do not need the <code>for</code> loop. Use the following instead and it should work.</p> <pre><code>slope, intercept, r_value, p_value, std_err = stats.linregress(X[:,0], Y[:,0]) </code></pre>
1
2016-08-02T15:56:05Z
[ "python", "scipy", "linear-regression" ]
`ValueError: too many values to unpack (expected 4)` with `scipy.stats.linregress`
38,725,018
<p>I know that this error message (<code>ValueError: too many values to unpack (expected 4)</code>) appears when more variables are set to values than a function returns. </p> <p><code>scipy.stats.linregress</code> returns 5 values according to the scipy documentation (<a href="http://docs.scipy.org/doc/scipy/referenc...
-1
2016-08-02T15:43:41Z
38,729,710
<p>The issue stems from the fact that your input to <code>np.asarray</code> are lists of single elements lists.</p> <p>Thus, <code>X</code> and <code>Y</code> both have shape of (12,1):</p> <pre><code>print(X.shape) # (12, 1) [or (12L, 1L), depending on version] print(Y.shape) # (12, 1) </code></pre> <p>Note tha...
0
2016-08-02T20:18:15Z
[ "python", "scipy", "linear-regression" ]
HDF5: Is there a way to rename the column names in an existing HDF5 table?
38,725,032
<p>I used Pandas to create a large, indexed HDF5 table. I'd like to rename 2 of the columns out of the 12 columns in my table. I would prefer not to rebuild/reindex the table.</p> <p>Can this be done without copying all the data (140GB)? I'm hoping there are just a couple pieces of metadata in the file that could be e...
1
2016-08-02T15:44:12Z
38,736,154
<p>I'm afraid currently there is no way to rename indexed (belonging to <code>data_columns</code>) column as this would require making changes in <code>storer.table.colindexes</code> and in <code>storer.table.description</code> objects and both of them are of the specific types: </p> <pre><code>In [29]: store.get_stor...
1
2016-08-03T06:40:34Z
[ "python", "pandas", "hdf5", "pytables", "hdfstore" ]
Deploy Blender to Azure App
38,725,037
<p>I have copied <code>Blender.exe</code> and all associated files into <code>Azure API App</code> then try to run it with my custom Python script like this (using <code>System.Dianostics.Process</code>()):</p> <blockquote> <p>blender.exe --background --python myscript.py</p> </blockquote> <p>But can not get it run...
1
2016-08-02T15:44:38Z
38,791,411
<p>@MinhNguyen, According to the wiki <a href="https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#win32ksys-user32gdi32-restrictions" rel="nofollow">page</a> of Kudu, Azure App Services which include Api App are not support scenarios using GDI+ because of Win32k.sys (User32/GDI32) Restrictions, but blender ...
1
2016-08-05T14:14:11Z
[ "python", "azure", "blender", "azure-api-apps" ]
No values for varchar in cx_Oracle
38,725,187
<p> <p>I have a column inside my orace database with type varchar2(256Byte). And now I wrote a webserver with web.py and cx_Oracle to do a query and fetch the result. The problem is I get no values for this column. But curiously it works for another column with the same type.</p> <p>code:</p> <pre><code>import cx_Or...
0
2016-08-02T15:52:09Z
38,841,858
<p>Are you using the so-far unreleased version of cx_Oracle which has Oracle object support? See <a href="http://stackoverflow.com/questions/38350314/how-to-convert-sdo-geomtry-in-geojson">How to convert SDO_GEOMTRY in GeoJSON</a></p>
0
2016-08-09T04:06:10Z
[ "python", "web.py", "cx-oracle" ]
Regular expression matching for IP range in Ansible Playbooks for grouping
38,725,204
<p>I am trying to write a regular expression for a dynamic group in ansible-playbook for an sample ip range. if the address range is 172.30.0.(0 to 254).(0 to 254). My regex is like 172.30.[0-254].[0-254]. Is this correct ? Even though I have the hosts in the range, the tasks are being skipped and no groups are bein...
1
2016-08-02T15:52:59Z
38,725,494
<p><code>[0-225]</code> is an incorrect regex. [] Define a range of character from one to another character in the ACII table and 255 is not an ASCII character.</p> <p>replace it by <code>(?:25[0-4]|2[0-4][0-9]|[01]?[0-9][0-9]?)</code></p> <p>So the complete regex is :</p> <p><code>173\.30\.(?:25[0-4]|2[0-4][0-9]|[0...
1
2016-08-02T16:05:29Z
[ "python", "regex", "ansible", "ansible-playbook" ]
Regular expression matching for IP range in Ansible Playbooks for grouping
38,725,204
<p>I am trying to write a regular expression for a dynamic group in ansible-playbook for an sample ip range. if the address range is 172.30.0.(0 to 254).(0 to 254). My regex is like 172.30.[0-254].[0-254]. Is this correct ? Even though I have the hosts in the range, the tasks are being skipped and no groups are bein...
1
2016-08-02T15:52:59Z
38,725,523
<p>You probably want to use <a href="http://docs.ansible.com/ansible/playbooks_filters.html" rel="nofollow">Jinja2 match</a> filter to match regex:</p> <p>Something like this:</p> <pre><code>--- - hosts: localhost gather_facts: no connection: local vars: ip_not_ok: '172.31.0.1' ip_ok: '172.30.0.1' ta...
0
2016-08-02T16:06:47Z
[ "python", "regex", "ansible", "ansible-playbook" ]
Regular expression matching for IP range in Ansible Playbooks for grouping
38,725,204
<p>I am trying to write a regular expression for a dynamic group in ansible-playbook for an sample ip range. if the address range is 172.30.0.(0 to 254).(0 to 254). My regex is like 172.30.[0-254].[0-254]. Is this correct ? Even though I have the hosts in the range, the tasks are being skipped and no groups are bein...
1
2016-08-02T15:52:59Z
38,725,810
<p>Regex isn't good tool for that.</p> <pre><code>from ipaddress import ip_address import operator def ip_check_range(ranges, s): return all(map(operator.contains, ranges, ip_address(s).packed )) print(ip_check_range([[172], [30], range(255), range(255)], '172.30.1.2')) # =&gt; True print(ip_...
0
2016-08-02T16:23:33Z
[ "python", "regex", "ansible", "ansible-playbook" ]
Regular expression matching for IP range in Ansible Playbooks for grouping
38,725,204
<p>I am trying to write a regular expression for a dynamic group in ansible-playbook for an sample ip range. if the address range is 172.30.0.(0 to 254).(0 to 254). My regex is like 172.30.[0-254].[0-254]. Is this correct ? Even though I have the hosts in the range, the tasks are being skipped and no groups are bein...
1
2016-08-02T15:52:59Z
38,725,832
<p>When using the operator '<strong>==</strong>' then in python you are trying to find a matched string with the name '172.30.[0-254[.[0-254]' </p> <p>In ansible you can use python expression like search or match.</p> <p>So you need to type something like this:</p> <pre><code>when: ansible_default_ipv4.address | mat...
1
2016-08-02T16:24:47Z
[ "python", "regex", "ansible", "ansible-playbook" ]
Regular expression matching for IP range in Ansible Playbooks for grouping
38,725,204
<p>I am trying to write a regular expression for a dynamic group in ansible-playbook for an sample ip range. if the address range is 172.30.0.(0 to 254).(0 to 254). My regex is like 172.30.[0-254].[0-254]. Is this correct ? Even though I have the hosts in the range, the tasks are being skipped and no groups are bein...
1
2016-08-02T15:52:59Z
38,726,303
<p>If you compare networks, you shouldn't care about ranges!</p> <pre><code>tasks: - group_by: key=adda when: ansible_default_ipv4.network == '172.30.0.0' </code></pre> <p>This will (generally) match all hosts with IPs 172.30.0.1 - 172.30.255.255.</p> <p>If you need to compare IP addresses, use <a href="http:/...
0
2016-08-02T16:50:50Z
[ "python", "regex", "ansible", "ansible-playbook" ]
Regular expression matching for IP range in Ansible Playbooks for grouping
38,725,204
<p>I am trying to write a regular expression for a dynamic group in ansible-playbook for an sample ip range. if the address range is 172.30.0.(0 to 254).(0 to 254). My regex is like 172.30.[0-254].[0-254]. Is this correct ? Even though I have the hosts in the range, the tasks are being skipped and no groups are bein...
1
2016-08-02T15:52:59Z
38,746,814
<p>I tried comparing networks it work out. So I tired what @ebel suggested and it worked the way I wanted. Thanks </p> <p><a href="http://i.stack.imgur.com/Z4dVM.png" rel="nofollow"><img src="http://i.stack.imgur.com/Z4dVM.png" alt="enter image description here"></a></p>
0
2016-08-03T14:42:56Z
[ "python", "regex", "ansible", "ansible-playbook" ]
How to change the code to find an approximation to the cube root of both negative and positive numbers?
38,725,215
<p>So I'm entirely new to coding and I'm taking the MIT Openwarecourse to get started (and I'm using the book Introducing to Computation and Programming using Python)</p> <p>Also since I'm new here I'm a bit afraid that my question is low quality so please point out if you think I should improve the manner on how I as...
0
2016-08-02T15:53:22Z
38,725,462
<p>Your algorithm is a numerical search through <a href="https://www.encyclopediaofmath.org/index.php/Dichotomy_method" rel="nofollow">dichotomy method</a> applied to X^2-x=0, it converges (quite fast actually) towards the solution X=sqrt(x) as long as low is lower than the solution, and high is higher than the solutio...
-1
2016-08-02T16:03:59Z
[ "python" ]
How to change the code to find an approximation to the cube root of both negative and positive numbers?
38,725,215
<p>So I'm entirely new to coding and I'm taking the MIT Openwarecourse to get started (and I'm using the book Introducing to Computation and Programming using Python)</p> <p>Also since I'm new here I'm a bit afraid that my question is low quality so please point out if you think I should improve the manner on how I as...
0
2016-08-02T15:53:22Z
38,725,489
<p>This:</p> <pre><code>low = 0.0 if low &lt; 0: low = -low </code></pre> <p>literally does nothing. You set <code>low = 0</code> and then check if it's less than 0 (which it isn't). Also, 0 is both positive and negative, so changing its sign does nothing.</p> <p>I'm afraid I don't understand the problem entirely, b...
-2
2016-08-02T16:05:14Z
[ "python" ]
Tensorflow DNNClassifier return wrong prediction
38,725,224
<p>I try to make a sentence classifier using tensorflow as in the example of the official site <a href="https://www.tensorflow.org/versions/r0.9/tutorials/tflearn/index.html" rel="nofollow">tf.contrib.learn Quickstart</a> but using my own data, first I convert all my data (which are strings of varying lengths) to ids t...
0
2016-08-02T15:53:42Z
38,796,537
<p>Estimator in tf.learn responsible to create session and graph. It gets the input tensors via input_fn. Every fit/evaluate/predict will create a new session and graph. Code should look similar to following:</p> <pre><code># Build 3 layer DNN with 10, 20, 10 units respectively. my_feature = tf.contrib.layers.real_val...
0
2016-08-05T19:27:51Z
[ "python", "machine-learning", "nlp", "tensorflow", "deep-learning" ]
Tensorflow DNNClassifier return wrong prediction
38,725,224
<p>I try to make a sentence classifier using tensorflow as in the example of the official site <a href="https://www.tensorflow.org/versions/r0.9/tutorials/tflearn/index.html" rel="nofollow">tf.contrib.learn Quickstart</a> but using my own data, first I convert all my data (which are strings of varying lengths) to ids t...
0
2016-08-02T15:53:42Z
38,963,313
<p>After all i made some changes in the code but there was no progress at all, so i change the parameters for the DNN Classifier and increase the size of my corpus and it works. </p> <p>At the end this was my parameters aprox:<br> -Steps = 25000+<br> -Layers = [n/2,n,n*2,n*4,n*8]<br> * n = number classes<br> -Corpus ...
0
2016-08-15T21:25:47Z
[ "python", "machine-learning", "nlp", "tensorflow", "deep-learning" ]
__reversed__ Magic method
38,725,269
<p>I have class Count which takes 3 parameters including self, mystart and myend. It should count from mystart until myend (also reversed) using magic methods <code>__iter__</code>, <code>__next__</code> and <code>__reversed__</code>. I have implemented all three magic methods. But I am still not sure whether it is t...
0
2016-08-02T15:55:33Z
38,750,543
<p>Now I have done it using yield statement. @jedwards thanks for your tipp.</p> <pre><code>class Count: def __init__(self, mystart,myend): self.mystart = mystart self.myend = myend self.current=None def __iter__(self): self.current = self.mystart while self.current &l...
1
2016-08-03T17:52:33Z
[ "python", "magic-methods" ]
__reversed__ Magic method
38,725,269
<p>I have class Count which takes 3 parameters including self, mystart and myend. It should count from mystart until myend (also reversed) using magic methods <code>__iter__</code>, <code>__next__</code> and <code>__reversed__</code>. I have implemented all three magic methods. But I am still not sure whether it is t...
0
2016-08-02T15:55:33Z
38,751,057
<p>You are mixing up Iterators and Iterables:</p> <p>Iterators:</p> <ol> <li>Keep a state associated with their current iteration progress</li> <li>Implement <code>__next__</code> to get the next state</li> <li>Implement <code>__iter__</code> to return themselves.</li> </ol> <p>Iterables:</p> <ol> <li>Contain (or d...
1
2016-08-03T18:24:11Z
[ "python", "magic-methods" ]
OnSerialData() Event in Python?
38,725,307
<p>I am using the <a href="https://pythonhosted.org/pyserial/" rel="nofollow">pyserial</a> python library to read serial data from an Arduino. Polling for new data would require me to implement an <code>update()</code> method that I must call several times a second. This would be slow and CPU intensive even when there ...
0
2016-08-02T15:56:54Z
38,732,911
<p>A standard approach is to use a thread for this.</p> <p>Something like this should work:</p> <pre><code>import threading import serial import io import sys exit_loop = False def reader_thread(ser): while not exit_loop: ch = ser.read(1) do_something(ch) def do_something(ch): print "got a character:",...
1
2016-08-03T01:28:11Z
[ "python", "multithreading", "python-2.7", "events", "serial-port" ]
Django redirect URL with parameter, inside urls.py file?
38,725,314
<p>I'm using Django 1.9. Is there any way to redirect a URL with a parameter in my urls.py file?</p> <p>I want to permanently redirect a URL like <code>/org/123/</code> to the corresponding URL <code>/neworg/123</code>.</p> <p>I know <a href="http://stackoverflow.com/questions/3139973/django-return-httpresponseredire...
0
2016-08-02T15:57:15Z
38,725,574
<p>You can use <a href="https://docs.djangoproject.com/en/1.10/ref/class-based-views/base/#redirectview" rel="nofollow"><code>RedirectView</code></a>. As long as the old and new url patterns have the same args and kwargs, you can use <code>pattern_name</code> to specify the url pattern to redirect to.</p> <pre><code>f...
2
2016-08-02T16:09:16Z
[ "python", "django" ]
How to check if a specific field contains an error in Django
38,725,393
<p>How do you check if a specific form field contains an error in a Django view?</p> <p>I have a sign up form and when a username throws an error I would like to display a flash message at the top of the page with the error.</p> <p>Basically something along the lines of: </p> <pre><code>if username_field in form has...
0
2016-08-02T16:00:57Z
38,725,432
<p>To get form errors as python dict, just <code>your_form.errors</code></p> <pre><code>if username_field in your_form.errors: messages.warning(request, "...") </code></pre>
2
2016-08-02T16:02:44Z
[ "python", "django" ]
result when __all__ is not defined in __init__.py of package?
38,725,419
<p>I am just learning and practicing python,on the way,i am reading about python packages and how to import into other modules or package at <a href="https://docs.python.org/3/tutorial/modules.html" rel="nofollow">Modules</a> ,I assume the following scenario ,</p> <p>I have package as ,</p> <pre><code>Video/ __in...
0
2016-08-02T16:02:08Z
38,725,840
<p>When you do</p> <pre><code>from whatever_package import * </code></pre> <p>first, if the package's <code>__init__.py</code> hasn't been run yet, it will be run. (If you've already done <code>import whatever_package.something_specific</code>, the package's <code>__init__.py</code> will have already been run.)</p> ...
2
2016-08-02T16:25:09Z
[ "python", "mkv" ]
How to Use Tkinter Entry like raw_input
38,725,442
<p>I'm trying to create a GUI for a TCP socket, the main function asks for the server address and wait an answer to proceed. This is the code</p> <pre><code>print("Welcome to TCP Socket") address = raw_input("Insert server address: ") print("Connectiong to " + address) ... </code></pre> <p>Now I have a entry from Tki...
-1
2016-08-02T16:03:10Z
38,725,800
<p>You cannot completely emulate raw_input in tkInter, since tkInter is event-driven. When you use raw_input, program execution blocks until you provide input and press enter. When you use get (), you'll get input anyhow, even if your entry is still empty.</p> <p>The simplest way to get some kind of blocking behaviour...
-1
2016-08-02T16:22:55Z
[ "python", "tkinter", "raw-input" ]
How to Use Tkinter Entry like raw_input
38,725,442
<p>I'm trying to create a GUI for a TCP socket, the main function asks for the server address and wait an answer to proceed. This is the code</p> <pre><code>print("Welcome to TCP Socket") address = raw_input("Insert server address: ") print("Connectiong to " + address) ... </code></pre> <p>Now I have a entry from Tki...
-1
2016-08-02T16:03:10Z
38,726,361
<p>If this is running inside an existing GUI, you can create a modal dialog with a Toplevel, using the method <code>wait_window</code> to block until the window is destroyed. If you want to use a popup window in an otherwise non-GUI program, you can create a little self-contained tkinter program in a function which ret...
2
2016-08-02T16:53:16Z
[ "python", "tkinter", "raw-input" ]
Groupby With Multi Index
38,725,456
<p>I'm trying to build a data frame like the one below using pandas where Asum only gets a value if there are intervals 1 and 3 on that day. The closest I've gotten to something working is using this:</p> <pre><code> df['ASum']=df.groupby(level=['DateTime'])['A'].sum() </code></pre> <p>But when I run it, it returns ...
2
2016-08-02T16:03:40Z
38,726,325
<pre><code>df['ASum'] = 0 # the new column MUST be defined ahead for idx,data in df.groupby(level=['DateTime']): if all(x in data.index.get_level_values('INT') for x in [1,3]): df.loc[idx,'ASum'].iloc[-1] = data['A'].sum() # adds the sum to the last row in the group only </code></pre> <p>Which results:...
0
2016-08-02T16:51:41Z
[ "python", "pandas", "multi-index" ]
Groupby With Multi Index
38,725,456
<p>I'm trying to build a data frame like the one below using pandas where Asum only gets a value if there are intervals 1 and 3 on that day. The closest I've gotten to something working is using this:</p> <pre><code> df['ASum']=df.groupby(level=['DateTime'])['A'].sum() </code></pre> <p>But when I run it, it returns ...
2
2016-08-02T16:03:40Z
38,729,389
<p>Here is a solution based on unstacking the <code>INT</code> level, taking the sum and stacking it back.</p> <pre><code>import pandas as pd midx = pd.MultiIndex(levels=[['2016-07-05', '2016-07-06', '2016-07-07', '2016-07-08', '2016-07-11'], [1, 3]], labels=[[0, 1, ...
3
2016-08-02T19:57:30Z
[ "python", "pandas", "multi-index" ]
Add the count value of occurrences of different values in a table as a new column to the table using pandas
38,725,483
<p>In the following table, how can I count the number of occurrences of different User IDs and make a new table that has the User IDs and the count values only.</p> <p><a href="http://i.stack.imgur.com/DRN6z.png" rel="nofollow"><img src="http://i.stack.imgur.com/DRN6z.png" alt="enter image description here"></a></p> ...
1
2016-08-02T16:04:58Z
38,725,559
<p>you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.value_counts.html" rel="nofollow">value_counts()</a> method:</p> <pre><code>df.User.value_counts().to_frame('count').reset_index().rename(columns=dict(index='User')) </code></pre> <p>or if you want to keep <code>User</code> co...
2
2016-08-02T16:08:38Z
[ "python", "pandas", "dataframe" ]
Unable to download nltk data
38,725,583
<pre><code>import nltk nltk.download() </code></pre> <p>It shows SSL:Certificate Verify Failed.In case of requests I use verify=False ,but what to do here.</p>
0
2016-08-02T16:09:50Z
38,755,535
<p>If you want to download manually, for example you need tokenizer/punkt data, you can download directly to :</p> <p>raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/tokenizers/punkt.zip</p> <p>and place the punkt extracted folder in C:\nltk_data\tokenizers.</p>
0
2016-08-04T00:05:56Z
[ "python", "python-2.7", "ssl", "nltk" ]
Python XML element found but evaluates to False - how to check existence pythonically?
38,725,683
<p>I am using <code>xml.etree</code> in Python to parse a SOAP response (don't ask...). The response contains a <code>&lt;Success /&gt;</code> element.</p> <p>I go and search it, find it and get an <code>xml.etree.ElementTree.Element</code> instance, let's call it <code>my_element</code>.</p> <p>Yet said instance eva...
0
2016-08-02T16:16:48Z
38,726,353
<p>No, <code>isinstance</code> is not the recommend way to check for non-existence of an <code>Element</code>.</p> <p>From <a href="https://docs.python.org/2/library/xml.etree.elementtree.html#element-objects" rel="nofollow">the docs</a>: </p> <blockquote> <p>Caution: Elements with no subelements will test as False...
0
2016-08-02T16:52:57Z
[ "python", "xml", "python-2.7" ]
Are there any examples of anomaly detection algorithms implemented with TensorFlow?
38,725,851
<p>I'm fairly new to this subject and I am working on a project that deals with detecting anomalies in time series data. I want to use TensorFlow so that I could potentially deploy the model onto a mobile device. I'm having a difficult time finding relevant material and examples of anomaly detection algorithms implemen...
3
2016-08-02T16:25:48Z
40,004,981
<p>Here is an example of sequential filtering using Holt-Winters. The same pattern should work for other types of sequential modeling such as the Kalman filter.</p> <pre><code>from matplotlib import pyplot import numpy as np import tensorflow as tf tf.logging.set_verbosity(tf.logging.INFO) seasonality = 10 def mode...
1
2016-10-12T17:38:56Z
[ "python", "algorithm", "machine-learning", "tensorflow" ]
How can I extract the text outside the <em> tag in BeautifulSoup
38,725,870
<p>Can someone help me extract the test that is after the <em>From</em>, I want to extract the sender name. It is situated right outside the em tag. I'm using the python BeautifulSoup package. </p> <p>Here is a link to the webpage: <a href="http://seclists.org/fulldisclosure/2016/Jan/0" rel="nofollow">http://seclists....
2
2016-08-02T16:27:00Z
38,726,025
<p>You want the next sibling and if you want the specific em's From and Date you can combine with a regex:</p> <pre><code>import re def title_spider(max_pages): for page in range(max_pages + 1): url = 'http://seclists.org/fulldisclosure/2016/Jan/{}'.format(page) source_code = requests.get(url) ...
1
2016-08-02T16:35:23Z
[ "python", "beautifulsoup", "web-crawler" ]
Why does create() in PayPal's batch payments via API return False?
38,725,877
<p><a href="https://developer.paypal.com/docs/api/payments.payouts-batch/#payouts_create">https://developer.paypal.com/docs/api/payments.payouts-batch/#payouts_create</a></p> <p>Sample code: <a href="https://github.com/paypal/PayPal-Python-SDK/blob/master/samples/payout/create.py">https://github.com/paypal/PayPal-Pyth...
8
2016-08-02T16:27:21Z
39,030,774
<p>The error message pretty clearly says that an authorization error occurred. Without any further information the only thing I can assume is that you either did not include an OAuth bearer token in the request, or the token was invalid (although I believe an invalid or expired token will return HTTP 401, not 403).</p...
1
2016-08-19T03:44:08Z
[ "python", "paypal", "paypal-rest-sdk" ]
Why does create() in PayPal's batch payments via API return False?
38,725,877
<p><a href="https://developer.paypal.com/docs/api/payments.payouts-batch/#payouts_create">https://developer.paypal.com/docs/api/payments.payouts-batch/#payouts_create</a></p> <p>Sample code: <a href="https://github.com/paypal/PayPal-Python-SDK/blob/master/samples/payout/create.py">https://github.com/paypal/PayPal-Pyth...
8
2016-08-02T16:27:21Z
39,066,929
<p>PayPal tech/dev support told me the debug ID said I didn't have Mass Pay enabled on my account, so I had to call them and talk to general support. I did, and they said they cannot enable it on Canadian accounts. I'm going to have to change payment processors to someone who offers the Mass Pay feature. I need to send...
7
2016-08-21T17:28:08Z
[ "python", "paypal", "paypal-rest-sdk" ]
How to use django-channels
38,725,955
<p>I need to use websocket in django, so I read docs of channels. Now I know the basic concepts but still confused because there's few code in detail. <br> <br>Here are my questions: <br>How can I make ASGI align with the WSGI in code? In other words, how to configure <code>WSGI Server to ASGI</code> or <code>ASGI to ...
0
2016-08-02T16:31:59Z
38,729,993
<p>If you want to use new ASGI spec then define <code>CHANNEL_LAYERS</code> in <code>settings.py</code>. If you are not set then this just run and work like a normal WSGI app.</p> <p>When you set above ( <code>to ASGI</code> ) you have two options, either route all traffic through ( in this case <code>HTTP/Websocket</...
1
2016-08-02T20:36:07Z
[ "python", "django", "django-channels" ]
Issue with saving checkbox value from form
38,725,967
<p>I have looked at the other solutions on Stackoverflow but nothing seems to help with the problem I have.</p> <p>I have an form for filling out information which needs to be saved. I give the user three options which they can tick. However, it won't save the form because it says the value isn't valid.</p> <p>Here...
0
2016-08-02T16:32:34Z
38,726,814
<p>In your models you have the <code>STATUS_CHOICES</code>'s values(first value in each tuple) <code>Critical</code>, <code>Medium</code>, <code>Low</code> with first letter as upper case, but you did all lower cases in the form. You should modify the choices in models to use the same <code>STATUS_CHOICES</code> as the...
1
2016-08-02T17:20:51Z
[ "python", "django" ]
Scraping all comments from specific site
38,726,062
<p>I would like to scrape all comments from all pages of a specific article. For example this article: <a href="http://www.spiegel.de/politik/ausland/syrien-die-islamisten-sind-aleppos-letzte-hoffnung-a-1105806.html" rel="nofollow">Link</a></p> <p>I think the comments are in javascript, could anyone help me figure out...
-1
2016-08-02T16:37:31Z
38,726,314
<p>All the text is available after each <em>div.article-comment-title</em> under the divs with the class <em>js-article-post-full-text</em>:</p> <pre><code>import requests soup = BeautifulSoup(requests.get("http://www.spiegel.de/politik/ausland/syrien-die-islamisten-sind-aleppos-letzte-hoffnung-a-1105806.html").conte...
3
2016-08-02T16:51:13Z
[ "python", "beautifulsoup" ]
Scraping all comments from specific site
38,726,062
<p>I would like to scrape all comments from all pages of a specific article. For example this article: <a href="http://www.spiegel.de/politik/ausland/syrien-die-islamisten-sind-aleppos-letzte-hoffnung-a-1105806.html" rel="nofollow">Link</a></p> <p>I think the comments are in javascript, could anyone help me figure out...
-1
2016-08-02T16:37:31Z
38,731,364
<p>You should be scraping from <a href="http://www.spiegel.de/forum/politik/belagerte-stadt-syrien-die-islamisten-sind-aleppos-letzte-hoffnung-thread-495132-1.html" rel="nofollow">this link</a> instead of the one you provided because its where the actual comments are coming from and this way it allows you to escape the...
0
2016-08-02T22:17:24Z
[ "python", "beautifulsoup" ]
Python : Plot heatmap for large matrix
38,726,087
<p>I have a large matrix of size 500 X 18904. </p> <p><strong>Since most of the values are zeros, I'm not able to visualise the pattern clearly as the zeroes dominate in the colorbar.</strong></p> <p>To look at the data more closely, I need to zoom in for different segments of image. Is there any reliable way to visu...
0
2016-08-02T16:38:44Z
39,507,431
<p>I can think of two options by using numpy arrays.</p> <ol> <li><p>Assuming your data is mostly higher than zero but there are a lot of zeros.:</p> <pre><code>vmin = some_value_higher_than_zero plt.mathow(k,aspect='auto',vmin=vmin) </code></pre></li> <li><p>Setting all zeros to NaNs. they are automatically left out...
1
2016-09-15T09:23:19Z
[ "python", "python-3.x", "matplotlib", "heatmap", "colorbar" ]
passing list argument to be iterated on -int not iterable
38,726,091
<p>I have a python function that needs to write an arbirary number of bytes to a bus:</p> <pre><code>def Writebytes(self,values): for byte in values: self.writebyte(byte) </code></pre> <p>The idea is you pass it a list of bytes and it writes them all out to the bus, e.g.</p> <pre><code>data=[0x10,0x33,0x...
0
2016-08-02T16:38:56Z
38,726,198
<p>I think the easiest way to go about this would be:</p> <pre><code>def Writebytes(self,values): if(not isinstance(values, list)): values = [values] for byte in values: self.writebyte(byte) </code></pre>
1
2016-08-02T16:45:16Z
[ "python", "list", "int", "iterable" ]
passing list argument to be iterated on -int not iterable
38,726,091
<p>I have a python function that needs to write an arbirary number of bytes to a bus:</p> <pre><code>def Writebytes(self,values): for byte in values: self.writebyte(byte) </code></pre> <p>The idea is you pass it a list of bytes and it writes them all out to the bus, e.g.</p> <pre><code>data=[0x10,0x33,0x...
0
2016-08-02T16:38:56Z
38,726,266
<p>You can always use a <code>try except</code> statement</p> <pre><code>def Writebytes(self,values): try: for byte in values: self.writebyte(byte) except TypeError: self.writebyte(values) </code></pre>
1
2016-08-02T16:48:51Z
[ "python", "list", "int", "iterable" ]
Determining whether a request came via socket or URL with Tornado
38,726,118
<p>I have a Tornado server that listens on both an address/port, and on a socket. I create the server roughly like so (stripped down heavily):</p> <pre><code>from tornado import httpserver from tornado.netutil import bind_unix_socket server = httpserver.HTTPserver( request_callback=some_callback, io_loop=some...
0
2016-08-02T16:40:28Z
38,726,675
<p><code>localhost</code> is an internet-domain interface with a well-known IP address. It's not the same as a unix-domain socket, which has no IP address. </p> <p>A brief look at the source suggests that the <code>remote_ip</code> attribute will contain <code>'0.0.0.0'</code> for a connection received on the unix soc...
1
2016-08-02T17:13:16Z
[ "python", "sockets", "tornado" ]
pandas transpose select - do analysis along transposed Series
38,726,120
<p><code>transpose</code> works well if just transposing <code>rows</code> and <code>columns</code>, but how does one do a <code>transpose with selection</code>?</p> <pre><code>df = pd.DataFrame({'year': [2012,2013,2014, 2012,2013,2014], 'barber': ['Sue', 'Sue', 'Sue', 'Mike', 'Mike', 'Mike'], 'num_haircuts': [3,3,1,0...
-1
2016-08-02T16:40:30Z
38,726,150
<p>Use pivot:</p> <pre><code>df.pivot(index='barber', columns='year', values='num_haircuts') Out: year 2012 2013 2014 barber Mike 0 0 6 Sue 3 3 1 </code></pre>
2
2016-08-02T16:42:22Z
[ "python", "pandas" ]
Slicing a python variable removes the whole string
38,726,202
<p>I'm a python newbie, using the <code>cx_Oracle</code> python package to execute a sql query:</p> <pre><code>cursor.execute("select tablespace_name from user_tablespaces") </code></pre> <p>to retrieve a list from an oracle 11g database. The results look like this: </p> <pre><code>('SYSTEM',) ('SYSAUX',) ('UNDOTBS...
0
2016-08-02T16:45:26Z
38,726,262
<pre><code>tableNameSpaces = [item [0][2:-3] for item in cursor] </code></pre> <p>The quotes will be in, though, since you're dealing with string literals. Once you print them, however, the quotes will be gone.</p> <p>As nicarus pointed out to me, probably you don't want to truncate your string literals at all, thoug...
2
2016-08-02T16:48:41Z
[ "python", "substring", "slice", "cx-oracle" ]
Slicing a python variable removes the whole string
38,726,202
<p>I'm a python newbie, using the <code>cx_Oracle</code> python package to execute a sql query:</p> <pre><code>cursor.execute("select tablespace_name from user_tablespaces") </code></pre> <p>to retrieve a list from an oracle 11g database. The results look like this: </p> <pre><code>('SYSTEM',) ('SYSAUX',) ('UNDOTBS...
0
2016-08-02T16:45:26Z
38,726,406
<p>You are slicing the tuples that represent each retrieved row rather than the strings that are the first (and only) elements of those rows. Further, you don't need to "get rid of the quotes" - that's just the interpreter doing its best to represent the data structure.</p> <p>Your database returns the equivalent of t...
2
2016-08-02T16:56:44Z
[ "python", "substring", "slice", "cx-oracle" ]
showing TypeError: sequence item 0: expected string, int found ; when converting list to text
38,726,250
<p>Iam trying to solve the babynames problem in google python class and executed the following script. </p> <pre><code>def extract_names(filename): year=0 f=open(filename,'rU') contents=f.read() match = re.search(r'(/w+/s/w+/s)(/d/d/d/d)',contents) if match: year=match.group() names=[] names.append(...
-1
2016-08-02T16:47:56Z
38,726,273
<p>It's because the first element of <code>names</code> is an integer and it should be a string if you want to join them together. Try this:</p> <pre><code>t = '\n'.join(str(n) for n in names) </code></pre>
1
2016-08-02T16:49:09Z
[ "python" ]
Multiple error messages trying to send file to server using Requests and Django
38,726,293
<p>I'm currently using the Requests library to send a file to a remote server from a form(InMemoryUploadedFile). I initially sent the 'file'(<code>file = self.request.FILES.get('file')</code>) as part of my payload, and when I ran the code I received a JSON error response from the server that says: </p> <blockquote> ...
0
2016-08-02T16:50:16Z
38,726,645
<p>I figured it out, it had to do with me sending the file as part of the payload, which doesn't multipart encode the upload. So what I had to do was send the file as the correct 'file' parameter which does properly multipart encode the upload.</p> <pre><code>class AddDocumentView(LoginRequiredMixin, SuccessMessageMix...
0
2016-08-02T17:11:28Z
[ "python", "django", "django-views", "python-requests" ]
Converting Python to Scala in Spark ML?
38,726,333
<p>The question is about <a href="http://stackoverflow.com/questions/37278999/logistic-regression-with-spark-ml-data-frames">Logistic regression with spark ml (data frames)</a></p> <p>When I want to change the code Python to Scala</p> <p>Python:</p> <pre><code>[stage.coefficients for stage in model.stages if isi...
1
2016-08-02T16:52:16Z
38,726,749
<blockquote> <p>Why the type is different when the isInstanceOf returns true?</p> </blockquote> <p>Well, Scala is a statically typed language and <code>stages</code> is an <code>Array[Transformer]</code> so each element you access is a <code>Transformer</code>. <code>Transformers</code> in general have no <code>coef...
2
2016-08-02T17:17:16Z
[ "python", "scala", "apache-spark", "apache-spark-ml" ]
Swapping values in assignemnt
38,726,411
<p>I'm a newbie taking Udacity's Intro to Computer Science course. We had a fairly simple question on our quiz about swapping values and I don't quite understand it. Here is the question:</p> <p>Which of the following sequence of statements leaves the value of variable X the same as it was before the statements. Assum...
-1
2016-08-02T16:56:50Z
38,726,458
<p>It's simply swapping, then swapping again.</p> <pre><code>&gt;&gt;&gt; a = 2 &gt;&gt;&gt; x = 1 &gt;&gt;&gt; a,x = x,a # We swapped them, so a = 1 and x = 2 now # During evaluation, this statement will be equivalent to "a,x = 1,2" &gt;&gt;&gt; a,x = x,a # And now we swap them again, so they're back to...
0
2016-08-02T16:59:47Z
[ "python", "computer-science" ]
Swapping values in assignemnt
38,726,411
<p>I'm a newbie taking Udacity's Intro to Computer Science course. We had a fairly simple question on our quiz about swapping values and I don't quite understand it. Here is the question:</p> <p>Which of the following sequence of statements leaves the value of variable X the same as it was before the statements. Assum...
-1
2016-08-02T16:56:50Z
38,726,500
<p>This happens because of the way Python's so-called unpacking assignments_ work. In essence the interpreter creates a list of destinations from the left-hand side and a list of values from the right-hand side of the assignment statement, then assigns the values to the destinations.</p> <p>So in</p> <pre><code>a, b ...
0
2016-08-02T17:02:27Z
[ "python", "computer-science" ]
I have a text file that is one long line of text that I want to break up into a dictionary, how would I do that?
38,726,533
<p>I have a text file that looks like this, where the line that starts "Distance IQC/E: Distance XY" and the rest the follows is one long line until :END:</p> <pre><code>:BEGIN "Distance IQC/E: Distance XY",0.09066,0.09060,0.00040,0.00040,0.00006,,"Distance IQC/F: Distance XY",0.14603,0.14590,0.00080,0.00080,0.00013,,...
-1
2016-08-02T17:03:55Z
38,726,866
<p>Considering this is your input data:</p> <pre><code>line = ':BEGIN\n"Distance IQC/E: Distance XY",0.09066,0.09060,0.00040,0.00040,0.00006,,"Distance IQC/F: Distance XY",0.14603,0.14590,0.00080,0.00080,0.00013,,"Distance IQC/G: Distance XY",0.12074,0.12070,0.00080,0.00080,0.00004,,"Distance IQC/I: Distance XY",0.214...
0
2016-08-02T17:24:01Z
[ "python", "python-3.x" ]
I have a text file that is one long line of text that I want to break up into a dictionary, how would I do that?
38,726,533
<p>I have a text file that looks like this, where the line that starts "Distance IQC/E: Distance XY" and the rest the follows is one long line until :END:</p> <pre><code>:BEGIN "Distance IQC/E: Distance XY",0.09066,0.09060,0.00040,0.00040,0.00006,,"Distance IQC/F: Distance XY",0.14603,0.14590,0.00080,0.00080,0.00013,,...
-1
2016-08-02T17:03:55Z
38,727,211
<pre><code>str = 'Distance IQC/E: Distance XY",0.09066,0.09060,0.00040,0.00040,0.00006,,"Distance IQC/F: Distance XY",0.14603,0.14590,0.00080,0.00080,0.00013,,"Distance IQC/G: Distance XY",0.12074,0.12070,0.00080,0.00080,0.00004,,"Distance IQC/I: Distance XY",0.21476,0.21600,0.00200,0.00200,-0.00124,,"Distance IQC/H: D...
0
2016-08-02T17:46:11Z
[ "python", "python-3.x" ]
What framework to use for a java web app
38,726,542
<p>I need to develop a single page Web app. The app is currently programmed in java and displays a graph based on the users preferences. But it needs porting to a website. So I need to display it on a page, but not as a java applet. The java app accepts arguments that can be used to make new calculations based on the u...
-5
2016-08-02T17:04:48Z
38,726,608
<p>U can use Node.Js for singal page web application.</p>
0
2016-08-02T17:09:15Z
[ "javascript", "java", "python", "node.js", "web-applications" ]
What framework to use for a java web app
38,726,542
<p>I need to develop a single page Web app. The app is currently programmed in java and displays a graph based on the users preferences. But it needs porting to a website. So I need to display it on a page, but not as a java applet. The java app accepts arguments that can be used to make new calculations based on the u...
-5
2016-08-02T17:04:48Z
38,726,833
<p>I did not read your full description of the question prior to submit an equivocated answer. But now I got what you want.</p> <p>So what I would suggest to you is split the Frontend from Backend. </p> <p>About the frontend you want to build a page with HTML + CSS + Javascript. If your app is complex (eg. more than ...
0
2016-08-02T17:21:47Z
[ "javascript", "java", "python", "node.js", "web-applications" ]
What framework to use for a java web app
38,726,542
<p>I need to develop a single page Web app. The app is currently programmed in java and displays a graph based on the users preferences. But it needs porting to a website. So I need to display it on a page, but not as a java applet. The java app accepts arguments that can be used to make new calculations based on the u...
-5
2016-08-02T17:04:48Z
38,726,843
<p>Node.js and other scripting languages has their own advantage in terms of performance and scalabilty.If you have single page application and there are future chances it could be extended,then you should MVC frameworks like Struts and Spring. According to me spring is really very advanced and has some really good int...
0
2016-08-02T17:22:29Z
[ "javascript", "java", "python", "node.js", "web-applications" ]
NATIVE_APP context are showing on a hybrid Android app which is using Cordova , when trying to automate using Appium
38,726,570
<pre><code> def test_list_content(self): self.driver.implicitly_wait(600) time.sleep(10) allContexts = self.driver.contexts print allContexts current = self.driver.current_context print current </code></pre> <p>Appium version is 1.4.16.1, Windows 7, Android device with OS 4.4.2.<...
1
2016-08-02T17:06:39Z
38,761,780
<p>This is an issue with Crosswalk webviews. They are a little different. This hasn't been fixed in the appium yet. Issue is here <a href="https://github.com/appium/appium/issues/4597" rel="nofollow">Appium issue with Crosswalk webviews. </a></p> <p>But there is a workaround for the issue here. Follow the instructions...
0
2016-08-04T08:05:26Z
[ "android", "python", "automation", "appium" ]
Generate custom xml with django
38,726,602
<p>As a heads up i am completely new to Python and Django.</p> <p>I am trying to move from PHP to Python. And i came to a problem of how to generate a custom xml file with all of the entries form database. I need to create something like this:</p> <p></p> <pre><code>&lt;inv&gt; &lt;invID&gt;1&lt;/invID&gt; ...
0
2016-08-02T17:09:06Z
40,051,563
<pre><code>def xml(request): #Getting all of the items in the Database products = Product.objects.all() #Putting all of it in to Context to pass to template context = { 'products': products } #calling template with all of the information content = render_to_string('catalog/xml_template.xml', context) #Saving templa...
0
2016-10-14T20:33:27Z
[ "php", "python", "xml", "django" ]
Python 3.4 Pygame My sprite does not appear
38,726,603
<p>I have written simple code to get a green block which is my sprite to scroll across the screen. When the game starts the sprite is meant to appear in the centre of the screen, however when I run my code the screen is just black and the green block does not appear unless I click on the x cross on the window to exit t...
0
2016-08-02T17:09:08Z
38,726,909
<p>All your code to updat the sprites, fill the screens and draw the sprites is outside your main loop (<code>while running</code>) </p> <p>You must have in mind that identation Python's syntax: your commands are just outside your mainloop.</p> <p>Moreover, I'd strongly advise to put that mainloop inside a proper fun...
0
2016-08-02T17:25:55Z
[ "python", "pygame", "sprite" ]
python json print empty value
38,726,629
<p>When I print <code>banner["STATUS"]["Description"]</code>, I get an empty value?</p> <pre><code>banner = { "STATUS":[ { "STATUS": "S", "When": 1470157636, "Code": 11, "Msg": "Summary", "Description": "nsgminer 0.9.2" } ], "SUMMARY": [ { "Elapsed":1502, "MH...
1
2016-08-02T17:10:32Z
38,726,741
<pre><code>print banner['STATUS'][0]['Description'] # 0 will tell its the 0th index of the list </code></pre> <p>'Status' key holds a list. Since 'Description' is placed in the 1st dictionary in that list, [0] is needed to access the 1st dictionary.</p>
2
2016-08-02T17:16:59Z
[ "python", "json" ]
Recenter Text After Input Tkinter (Python)
38,726,769
<p>I am using Tkinter for Python right now, and I'm trying to figure out if it's possible to recenter text after a user inputs something into a Text widget.</p> <p>Currently, my code outputs like this:</p> <p><a href="http://i.stack.imgur.com/HjubY.png" rel="nofollow"><img src="http://i.stack.imgur.com/HjubY.png" alt...
0
2016-08-02T17:18:11Z
38,727,577
<p>Assuming you can't use an <code>Entry</code> widget which has a built-in <code>justify</code> attribute, perhaps the simplest solution is to add a binding on any key release which re-tags the data in the widget:</p> <pre><code>def retag(event): event.widget.tag_add("tag-center", "1.0", "end") ... bdFileNameEntr...
0
2016-08-02T18:05:28Z
[ "python", "tkinter" ]
Unable to kill Python subprocess using process.kill() or process.terminate() or os.kill() or using psutil
38,726,804
<p>Using python, I am starting two subprocesses in parallel. One is an HTTP Server, while other is an execution of another program(CustomSimpleHTTPServer.py, which is a python script generated by selenium IDE plugin to open firefox, navigate to a website and do some interactions). On the other hand, I want to stop exec...
0
2016-08-02T17:20:13Z
38,727,527
<p>You should just use <code>os.kill()</code> to signal processes:</p> <pre><code>import os import signal ... os.kill(the_pid, signal.SIGTERM) # usually kills processes os.kill(the_pid, signal.SIGKILL) # should always kill a process </code></pre> <p>Also, if you kill the parent process it also usually kills the c...
1
2016-08-02T18:01:49Z
[ "python", "multithreading", "selenium" ]
Using PhotoImage with threading tkinter and matplotlib
38,726,827
<p>I relatively new user of python and the world of programming in general, so please keep it very very simple. I have been trying to do a program in python in order to keep track of the number of pages i read each day for a specific book using matplotlib...Everything have been working good in general, but when i tried...
0
2016-08-02T17:21:34Z
38,728,842
<p>I ran this code on my python and got no errors (I commented out a line that you will need, i didn't need it cos i was working with a gif). Obviously since i had no idea what was in the text file, i didn't get a suitable result, but the main thing was there were no code errors.</p> <pre><code>import matplotlib #adde...
0
2016-08-02T19:22:05Z
[ "python", "multithreading", "matplotlib", "photoimage" ]
Python "Expected an indented block" IndentationError?
38,726,845
<p>I am running into this error with some code I am writing using Scrapy, and I have no clue why it is happening. I have searched for answers on here and elsewhere, and every example I see is someone who didn't indent after an if statement or something like that. That's not the problem I'm having; I get the error for t...
-2
2016-08-02T17:22:32Z
38,726,912
<p>Few ideas that could help:</p> <p>Double check your tabs and spaces. Delete from <code>f.seek(</code> backwards until it appears right after the <code>:</code>, press return once and let your IDE take care of the indentation for you.</p>
1
2016-08-02T17:26:04Z
[ "python", "file", "io" ]
Pandas count the number of times an event has occurred in last n days by group
38,726,855
<p>I have table of events occurring by id. How would I count the number of times in the last n days that each event type has occurred prior to the current row?</p> <p>For example with a list of events like:</p> <pre><code>df = pd.DataFrame([{'id': 1, 'event_day': '2016-01-01', 'event_type': 'type1'}, {'id': 1, 'event...
3
2016-08-02T17:23:15Z
38,727,983
<pre><code>res = ((((df['event_day'].values &gt;= df['event_day'].values[:, None] - pd.to_timedelta('30 days')) &amp; (df['event_day'].values &lt; df['event_day'].values[:, None])) &amp; (df['id'].values == df['id'].values[:, None])) .dot(pd.get_dummies(df['event_type']))) res Out: array([[ 0....
2
2016-08-02T18:30:33Z
[ "python", "pandas" ]
Pandas count the number of times an event has occurred in last n days by group
38,726,855
<p>I have table of events occurring by id. How would I count the number of times in the last n days that each event type has occurred prior to the current row?</p> <p>For example with a list of events like:</p> <pre><code>df = pd.DataFrame([{'id': 1, 'event_day': '2016-01-01', 'event_type': 'type1'}, {'id': 1, 'event...
3
2016-08-02T17:23:15Z
38,730,063
<p>Ok, I really enjoyed ayhan's approach. But I have another which is probably slower (just my assumption that <code>apply</code> is usually slow), although I think the logic is more straightforward. If anyone wants to try to compare the two, especially how they scale, I'd be very interested:</p> <pre><code>In [1]: im...
2
2016-08-02T20:40:34Z
[ "python", "pandas" ]
How to use `annot` method of `sns.heatmap` to give custom labels? (Python | Seaborn)
38,726,886
<p><strong>How can I use the <code>annot</code> method of <code>sns.heatmap</code> to give it a custom naming scheme?</strong> </p> <p>Essentially, I want to drop all the labels that are lower than my threshold (0 in this case). I tried doing what @ojy said in <a href="http://stackoverflow.com/questions/33158075/cust...
0
2016-08-02T17:24:57Z
38,778,453
<p>That's easy, boi! </p> <p>Update to 0.7.1 and restart Jupyter kernel.</p> <p><a href="https://github.com/mwaskom/seaborn/issues/981" rel="nofollow">https://github.com/mwaskom/seaborn/issues/981</a></p>
1
2016-08-04T22:35:27Z
[ "python", "matplotlib", "heatmap", "seaborn", "data-science" ]
uint32 vs uint64: What bases do I need for the 'int()' function to work properly
38,726,956
<p>If I have two hex-strings and want to convert one to an 32-bit unsigned integer and the other to a 64-bit unsigned integer, what bases would I provide the <code>int()</code> function?</p>
2
2016-08-02T17:29:03Z
38,727,097
<p>Well, python usually decides how much memory to allocate itself. See the following example:</p> <pre><code>&gt;&gt;&gt; type(int('0x7fffffff', 16)) &lt;type 'int'&gt; &gt;&gt;&gt; type(int('0x80000000', 16)) &lt;type 'long'&gt; </code></pre> <p>Based on the size of the number, Python allocates the right amount of ...
1
2016-08-02T17:39:48Z
[ "python", "int", "hex" ]
uint32 vs uint64: What bases do I need for the 'int()' function to work properly
38,726,956
<p>If I have two hex-strings and want to convert one to an 32-bit unsigned integer and the other to a 64-bit unsigned integer, what bases would I provide the <code>int()</code> function?</p>
2
2016-08-02T17:29:03Z
38,857,013
<p>So I goofed up and int() does not determine the size or sign of your hex string. </p> <p>By definition, hex is 16. So you would put in your string with the hex base of 16</p> <pre><code>int('A1S31231', 16) </code></pre> <p>The issue between 32 bit and 64 bit was simply the size of the string put in as an argument...
-1
2016-08-09T17:26:05Z
[ "python", "int", "hex" ]
(Long) Removing Single Quotes From Strings in a List
38,726,986
<p>This is all a bit vague because the program is rather in-depth, but stick with me as I will try to explain it as best I can. I wrote a program that takes a <code>.csv</code> file and turns it into <code>INSERT INTO</code> statements for a MySQL database. For example:</p> <pre><code>ID Number Letter Decimal ...
2
2016-08-02T17:31:29Z
38,727,076
<p>instead of </p> <pre><code>values = map((lambda x: "'" + x.strip() + "'"), tempMaster) </code></pre> <p>put this</p> <pre><code> values = map((lambda x: "'" + x.strip() + "'" if x!='NULL' else x), tempMaster) </code></pre> <p><H3>Edit</H3> Thanks for accepting/upvoting my simple trick but I'm not sure this is op...
2
2016-08-02T17:38:00Z
[ "python", "mysql", "python-3.x", "csv" ]
(Long) Removing Single Quotes From Strings in a List
38,726,986
<p>This is all a bit vague because the program is rather in-depth, but stick with me as I will try to explain it as best I can. I wrote a program that takes a <code>.csv</code> file and turns it into <code>INSERT INTO</code> statements for a MySQL database. For example:</p> <pre><code>ID Number Letter Decimal ...
2
2016-08-02T17:31:29Z
38,727,505
<p>I checked your requirement i found that you have multiple CSV in your directory. These csv have dynamic column. My approach is create a static list of all columns</p> <p><code>staticColumnList = ["ID","TableID","Number","Decimal","Letter","Random"]</code> </p> <p>Now when reading your file take header row and make...
0
2016-08-02T18:01:07Z
[ "python", "mysql", "python-3.x", "csv" ]
How to turn off matplotlib inline function and install pygtk?
38,727,035
<p>I got two questions when I was plotting graph in ipython.</p> <ol> <li><p>once, i implement <code>%matplotlib inline</code>, I don't know how to switch back to use floating windows. </p></li> <li><p>when I search for the method to switch back, people told me to implement <code>%matplotlib</code> osx or <code>%matp...
0
2016-08-02T17:35:34Z
38,729,045
<p>You need to install pyGTK. How to do so depends on what you're using to run Python. You could also not use '%matplotlib inline' and then it'll default to whatever is installed on your system. </p>
0
2016-08-02T19:34:16Z
[ "python", "matplotlib", "ipython" ]
Read a JSON file containing unicode data
38,727,049
<p>Here is the content of my JSON file</p> <pre><code>cat ./myfile.json {u'Records': [{u'eventVersion': u'2.0', }]} </code></pre> <p>How do I read this JSON file?</p> <p>I tried reading the file with the following code,</p> <pre><code>def Read_json_file(jsonFile): jsonDy = {} if os.path.exists(jsonFile): ...
0
2016-08-02T17:36:36Z
38,727,156
<p>Try this,</p> <pre><code>import simplejson as json w = json.dumps({u'Records': [{u'eventVersion': u'2.0', }]}) print json.loads(w) </code></pre> <p>or use:</p> <pre><code>import json w = json.dumps({u'Records': [{u'eventVersion': u'2.0', }]}) print json.loads(w) </code></pre> <p>I have dumped to json to recreate...
1
2016-08-02T17:43:11Z
[ "python", "json", "python-2.7", "unicode", "python-unicode" ]
Read a JSON file containing unicode data
38,727,049
<p>Here is the content of my JSON file</p> <pre><code>cat ./myfile.json {u'Records': [{u'eventVersion': u'2.0', }]} </code></pre> <p>How do I read this JSON file?</p> <p>I tried reading the file with the following code,</p> <pre><code>def Read_json_file(jsonFile): jsonDy = {} if os.path.exists(jsonFile): ...
0
2016-08-02T17:36:36Z
38,727,199
<p>That's not a valid JSON structure. It's a string representation of Python data structure. The appropriate JSON structure would be:</p> <pre><code>{"Records": [{"eventVersion": "2.0"}]} </code></pre> <p>It looks like something is writing the JSON with the output of <code>json.loads</code> instead of <code>json.du...
3
2016-08-02T17:45:17Z
[ "python", "json", "python-2.7", "unicode", "python-unicode" ]
Core Reporting API - How to use multiple dimensionFilterClauses filters?
38,727,095
<p>I'm trying to use multiple dimensionFilterClauses into a Core Reporting API V4 query. If I use just a filter on the <code>ga:adwordsCustomerID</code> dimension everything goes fine, but when I add a second filter on the <code>ga:adTargetingType</code> dimension it throws a "Status 400: Bad request" error.</p> <p>Th...
0
2016-08-02T17:39:46Z
38,755,771
<h2>Analytics Reporting API V4 <a href="https://developers.google.com/analytics/devguides/reporting/core/v4/basics#filtering_1" rel="nofollow">Filtering</a></h2> <p>The <a href="https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet#ReportRequest" rel="nofollow">ReportRequest</a> ...
0
2016-08-04T00:40:22Z
[ "python", "python-3.x", "google-analytics", "google-analytics-api", "google-analytics-v4" ]
ImportError: No module named log
38,727,132
<p>Isn't log a built in package in python?</p> <pre><code># /usr/bin/python Python 2.7.5 (default, Oct 11 2015, 17:47:16) [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2 Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; import log as logging Traceback (most recent call last): File...
-1
2016-08-02T17:42:01Z
38,727,148
<p><code>logging</code> is a <a href="https://docs.python.org/2/library/logging.html" rel="nofollow">built-in package</a>, not <code>log</code>:</p> <pre><code>import logging as log </code></pre>
1
2016-08-02T17:42:47Z
[ "python" ]
What is the best way sort 2-D list and transform it to dictionary
38,727,181
<p>I have a 2-D <code>[2xn]</code> array with keys in the first column (which repeat) and values in the second. I need to make a dictionary, where keys are unique, and there values are collected from the values. </p> <p>What is the smartest way to do it? Should I first preprocess (sort keys-values in groups or somethi...
0
2016-08-02T17:44:42Z
38,730,213
<pre><code>output = {} for i in input: key = i[0] value = i[1] if not key in output: output[key] = [] output[key].append(value) </code></pre>
1
2016-08-02T20:51:19Z
[ "python", "dictionary" ]
What is the best way sort 2-D list and transform it to dictionary
38,727,181
<p>I have a 2-D <code>[2xn]</code> array with keys in the first column (which repeat) and values in the second. I need to make a dictionary, where keys are unique, and there values are collected from the values. </p> <p>What is the smartest way to do it? Should I first preprocess (sort keys-values in groups or somethi...
0
2016-08-02T17:44:42Z
38,730,322
<p>Use a <code>defaultdict</code>:</p> <pre><code>from collections import defaultdict output = defaultdict(list) for k,v in input: output[k].append(v) </code></pre>
3
2016-08-02T20:58:45Z
[ "python", "dictionary" ]
How would I iterate over a list of files and plot them as subplots on a single figure?
38,727,364
<p>I'm trying to plot files onto 8 subplots for 2 figures. I am using a for loop and enumerate operator, along with axarray to do this. I am almost there with the last step (with axarray) but need guidance as to how to finish it. Here's my code:</p> <pre><code>'import matplotlib.pyplot as plt import parse_gctoo impor...
1
2016-08-02T17:54:28Z
38,727,518
<p>First, it's suffice to call <code>plt.figure()</code> once at the beginning of the loop.</p> <p>Second, you need to use <code>subplot</code> correctly. Here is the doc of the <code>subplot</code> function:</p> <blockquote> <p>Typical call signature:</p> <p>subplot(nrows, ncols, plot_number) Where nrows and ...
1
2016-08-02T18:01:34Z
[ "python", "for-loop", "matplotlib", "plot" ]
How would I iterate over a list of files and plot them as subplots on a single figure?
38,727,364
<p>I'm trying to plot files onto 8 subplots for 2 figures. I am using a for loop and enumerate operator, along with axarray to do this. I am almost there with the last step (with axarray) but need guidance as to how to finish it. Here's my code:</p> <pre><code>'import matplotlib.pyplot as plt import parse_gctoo impor...
1
2016-08-02T17:54:28Z
38,729,716
<p>You can try this:</p> <pre><code>import matplotlib.pyplot as plt plt.figure() for n, single_q in enumerate(q_list): ax = plt.subplot(len(q_list), 1, n+1) GCT_object = parse_gctoo.parse(single_q) gene_medians = GCT_object.data_df.median(axis=1) plt.hist(gene_medians) # tweak title, labels, etc....
1
2016-08-02T20:18:23Z
[ "python", "for-loop", "matplotlib", "plot" ]
How can I decode a utf-8 byte array to a string in Python2?
38,727,390
<p>I have an array of bytes representing a utf-8 encoded string. I want to decode these bytes back into the string in Pyton2. I am relying on Python2 for my overall program, so I can not switch to Python3. </p> <pre><code>array = [67, 97, 102, **-61, -87**, 32, 70, 108, 111, 114, 97] </code></pre> <p>-> Caf<strong>Ã...
1
2016-08-02T17:55:45Z
38,727,464
<p>Use the little-used <a href="https://docs.python.org/2/library/array.html" rel="nofollow"><code>array</code> module</a> to convert your input to a bytestring and then <code>decode</code> it with the UTF-8 codec:</p> <pre><code>import array decoded = array.array('b', your_input).tostring().decode('utf-8') </code></p...
2
2016-08-02T17:59:29Z
[ "python", "arrays", "python-2.7", "utf-8" ]
How can I decode a utf-8 byte array to a string in Python2?
38,727,390
<p>I have an array of bytes representing a utf-8 encoded string. I want to decode these bytes back into the string in Pyton2. I am relying on Python2 for my overall program, so I can not switch to Python3. </p> <pre><code>array = [67, 97, 102, **-61, -87**, 32, 70, 108, 111, 114, 97] </code></pre> <p>-> Caf<strong>Ã...
1
2016-08-02T17:55:45Z
38,727,472
<p>You have to have in mind that a "string" in Python2 is not proper text, just a sequence of bytes in memory, which happens to map to characters when you "print" them - if the mapping of the intend characters in the byte sequence matches the one in the terminal, you will see properly formatted text.</p> <p>If your te...
1
2016-08-02T17:59:38Z
[ "python", "arrays", "python-2.7", "utf-8" ]
How can I decode a utf-8 byte array to a string in Python2?
38,727,390
<p>I have an array of bytes representing a utf-8 encoded string. I want to decode these bytes back into the string in Pyton2. I am relying on Python2 for my overall program, so I can not switch to Python3. </p> <pre><code>array = [67, 97, 102, **-61, -87**, 32, 70, 108, 111, 114, 97] </code></pre> <p>-> Caf<strong>Ã...
1
2016-08-02T17:55:45Z
38,727,511
<p>you can use <code>struct.pack</code> for this</p> <pre><code>&gt;&gt;&gt; a = [67, 97, 102, -61, -87, 32, 70, 108, 111, 114, 97] &gt;&gt;&gt; struct.pack("b"*len(a),*a) 'Caf\xc3\xa9 Flora' &gt;&gt;&gt; print struct.pack("b"*len(a),*a).decode('utf8') Café Flora </code></pre>
1
2016-08-02T18:01:24Z
[ "python", "arrays", "python-2.7", "utf-8" ]
Tagging lists within lists for removal
38,727,418
<p>First off, I'm doing this in python, I've got a complex list that will consist of a varying number of lists, I've tagged each list with a number (occupying the third position of each entry), because I want to cull lists that contain this number beyond the first, essentially removing duplicates beyond the first, so I...
0
2016-08-02T17:57:30Z
38,727,803
<p>So here's a lazy solution (untested). I'm assuming that your original list is a "list of lists of lists" as per your example:</p> <pre><code>finalList = [] found = [] for i in list: miniList = [] for j in i: if not j[2] in found: miniList.append(j) found.append(j[2]) fin...
0
2016-08-02T18:19:24Z
[ "python", "list", "duplicates" ]
Edit G code Line by Line
38,727,438
<p>I want to read a g code file line by line, and based off of a comment at the end, do an action to it. The g code is coming out of Slic3r. Some example lines in no particular order look like this:</p> <pre><code>G1 Z0.242 F7800.000 ; move to next layer (0) G1 E-2.00000 F2400.00000 ; retract G1 X0.000 Y30.140 F7800.0...
2
2016-08-02T17:58:21Z
38,739,613
<p>I am not sure what you want to modify exactly, so I chose to add the word <code>'(up)'</code> in front of a comment that indicates retraction, and <code>'(down)'</code> in front of a comment that indicates unretraction.</p> <pre><code>file_name = "file.gcode" # put your filename here with open(file_name, 'r+') as...
1
2016-08-03T09:26:47Z
[ "python", "if-statement", "for-loop", "g-code" ]
Installing OpenCV for Python 3 on Fedora 24
38,727,447
<p>I followed very this carefully <a href="https://gist.github.com/wuerges/b3c32dfcc6302aa1c105" rel="nofollow">makefile</a> and well, it finishes well.</p> <p>On CMake output, there's this: <strong>python(for build): 2.7</strong> instead of <strong>3.5</strong></p> <p>But I read <a href="http://www.pyimagesearch.com...
0
2016-08-02T17:58:37Z
38,775,801
<p>After some comments, I think that your problem may be with setting the path of the library. So, after compiling OpenCV (see <a href="http://paste.fedoraproject.org/401387/" rel="nofollow">here</a>) I didn't install it on a default location on my system, I rather installed it in a local folder (it is easier to delete...
1
2016-08-04T19:26:32Z
[ "python", "opencv", "fedora" ]
Applying language filter to Entrez.esearch and Entrez.efetch
38,727,469
<p>I'm querying PubMed for some results using <code>Biopython</code>. This is a portion of the code:</p> <pre><code>def search(query): Entrez.email = 'gandalf@rivendell.lotr' handle = Entrez.esearch(db = 'pubmed', sort = 'relevance', ret...
1
2016-08-02T17:59:36Z
38,728,096
<p>You can modify the search term as shown below:</p> <pre><code>query = "{} AND English[Language]".format(query) handle = Entrez.esearch(db='pubmed', sort='relevance', retmax='30', retmode='xml', term=query) </code></pre>...
2
2016-08-02T18:37:09Z
[ "python", "filter", "biopython", "pubmed" ]
Redirecting C# Standard Output and Reading it with Python
38,727,491
<p>I'm trying to redirect that standard output from a Command Line Project I wrote in C# and reading through the data in a Python file. </p> <p>Currently, the C# application writes data that it reads from a sensor into a CSV file. I have to run the Python file later to get and process the data (has to be done in Pytho...
0
2016-08-02T18:00:25Z
38,728,687
<p>Thanks to @Quantic for providing some great resources. Using <code>subprocess.Popen</code>, I can run the built .exe of my C# project and redirect the output to my Python file. I am able now to <code>print()</code> to output to the Python console all the information being output to the C# console (<code>Console.Writ...
0
2016-08-02T19:11:38Z
[ "c#", "python", "stream", "stdout" ]
Adding default parameter value with type hint in Python
38,727,520
<p>If I have a function like this:</p> <pre><code>def foo(name, opts={}): pass </code></pre> <p>And I want to add type hints to the parameters, how do I do it? The way I assumed gives me a syntax error:</p> <pre><code>def foo(name: str, opts={}: dict) -&gt; str: pass </code></pre> <p>The following doesn't throw...
3
2016-08-02T18:01:36Z
38,727,786
<p>Your second way is correct. </p> <pre><code>def foo(opts: dict = {}): pass print(foo.__annotations__) </code></pre> <p>this outputs</p> <pre><code>{'opts': &lt;class 'dict'&gt;} </code></pre> <p>It's true that's it's not listed in <a href="https://www.python.org/dev/peps/pep-0484/" rel="nofollow">PEP 484</a...
3
2016-08-02T18:18:22Z
[ "python", "python-3.x", "type-hinting" ]
How to Loop through a CSV and use each Row String to Create a QR Code - PYTHON
38,727,579
<p>I am trying to write a code that will loop through a CSV file I have, combine the two pieces of data ( In this case "Rep" and "Entry") and then create a QR Code for each returned value... I have figured out how to make the QR code and how to Combine the data, but I cannot figure out the loop and how to put all of th...
0
2016-08-02T18:05:33Z
38,727,735
<p>You are going to want to create you label within the for loop:</p> <pre><code>for row in reader: labeldata = row[0] + row[1] qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=1, border=4) qr.add_data(labeldata) qr.make(fit=True) img = q...
0
2016-08-02T18:15:47Z
[ "python", "python-2.7", "loops", "csv", "qr-code" ]
How to Loop through a CSV and use each Row String to Create a QR Code - PYTHON
38,727,579
<p>I am trying to write a code that will loop through a CSV file I have, combine the two pieces of data ( In this case "Rep" and "Entry") and then create a QR Code for each returned value... I have figured out how to make the QR code and how to Combine the data, but I cannot figure out the loop and how to put all of th...
0
2016-08-02T18:05:33Z
38,727,767
<pre><code>import csv import qrcode with open('SLS_labels.csv') as csvfile: fieldnames= ["Rep", "Entry"] reader= csv.reader(csvfile) qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=1, border=4, ) for i, row in enumerate(re...
0
2016-08-02T18:17:21Z
[ "python", "python-2.7", "loops", "csv", "qr-code" ]
How does one set different learning rates for different layers or variables in TensorFlow?
38,727,612
<p>I know that one can simply do it for all of them using something as in the tutorials:</p> <pre><code>opt = tf.train.GradientDescentOptimizer(learning_rate) </code></pre> <p>however it would be nice it one could pass a dictionary that maps the variable name to its corresponding learning rate. Is that possible?</p> ...
1
2016-08-02T18:08:00Z
38,728,740
<p>As far as I can tell this is not possible. Mostly because this is not really a valid gradient descent then. There are plenty of optimizers which learn on their own variable specific scaling factors (like Adam or AdaGrad). Specyfing per-variable learning rate (constant one) would mean that you do not follow the gradi...
1
2016-08-02T19:15:22Z
[ "python", "machine-learning", "neural-network", "tensorflow", "conv-neural-network" ]
How do you plot a line with two slopes using python
38,727,734
<p>I am using the below codes to plot a line with two slopes as shown in the picture.The slope should should decline after certain limit [limit=5]. I am using vectorisation method to set the slope values.Is there any other method to set the slope values.Could anyone help me in this?</p> <pre><code> impo...
2
2016-08-02T18:15:45Z
38,728,070
<p>Following your code, you should modify the main part like this:</p> <pre><code>x=np.linspace(0,10,1000) m = np.empty(x.shape) c = np.empty(x.shape) m[(x&lt;L)] = 1.0 c[x&lt;L] = 0 m[(x&gt;L)] = 0.75 c[x&gt;L] = L*(1.0 - 0.75) y=m*x+c plt.plot(x,y) </code></pre> <p>Note that <code>c</code> needs to change as wel...
1
2016-08-02T18:35:45Z
[ "python", "numpy", "matplotlib" ]
How do you plot a line with two slopes using python
38,727,734
<p>I am using the below codes to plot a line with two slopes as shown in the picture.The slope should should decline after certain limit [limit=5]. I am using vectorisation method to set the slope values.Is there any other method to set the slope values.Could anyone help me in this?</p> <pre><code> impo...
2
2016-08-02T18:15:45Z
38,728,071
<p>You may be overthinking the problem. There are two line segments in the picture:</p> <ol> <li>From (0, 0) to (A, A')</li> <li>From (A, A') to (B, B')</li> </ol> <p>You know that <code>A = 5</code>, <code>m = 1</code>, so <code>A' = 5</code>. You also know that <code>B = 10</code>. Given that <code>(B' - A') / (B -...
1
2016-08-02T18:35:46Z
[ "python", "numpy", "matplotlib" ]