title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Python matrix represented as (40000,)
37,669,714
<p>I have seen and executed a python program where a matrix has been sliced into a column vector using <code>a[:,j]</code> and passed into a function. The column vector has dimensions <code>40000x1</code>. While tracing the output, I printed the dimensions of <code>a</code> in the function and it printed <code>(40000,)...
3
2016-06-07T02:48:44Z
37,670,267
<p>So <code>wx</code> is (1,N), <code>X</code> is 2d; <code>S</code> is same but with 1 more column.</p> <p><code>X[:,k]</code> is <code>xk</code> is (N,) (1d), so is <code>sk</code></p> <p><code>xk * wx + sk * wRec</code> is the <code>(N,)*(1,N) + (N,)*?</code>;</p> <p><code>(N,)</code> is automatically expanded to...
0
2016-06-07T04:04:17Z
[ "python", "numpy", "matrix" ]
Whenever I run my code the screen goes blank with no error message
37,669,778
<pre><code> import pygame #setup pygame.init() screen = pygame.display.set_mode((800,600)) DISPLAYSURF = pygame.display.set_caption("Smley Pong") keepGoing = True pic = pygame.image.load("Crazysmile.bmp") colorkey = pic.get_at((0,0)) pic.set_colorkey(colorkey) picx = 0 picy = 0 BLACK = (0,...
-1
2016-06-07T02:54:58Z
37,687,709
<p>You will have to indent your code from the line <code>picx += speedx</code>, to the line before <code>pygame.quit()</code></p> <p>You will then have to add in <code>pygame.display.flip()</code> before the line <code>pygame.quit()</code>(and indent it!)</p> <p>Then the line <code>text.rect.y = 10</code> does not ma...
0
2016-06-07T19:25:40Z
[ "python", "pygame" ]
Python FileNotFoundError: [Errno 2] No such file or directory
37,669,782
<p>I have the following snippet from a script</p> <pre><code>credentials = ServiceAccountCredentials.from_json_keyfile_name('tok.json', ['https://www.googleapis.com/auth/analytics.readonly']) </code></pre> <p>This is for auth in google analytics But when I run the script on my site, the logs report the following erro...
0
2016-06-07T02:55:24Z
37,678,061
<p>For service accounts credential object must be of the form <code>credentials = ServiceAccountCredentials.from_p12_keyfile(service_account_email, key_file_location, scopes=scope)</code> and for installed apps it must be of the form <code>credentials = tools.run_flow(flow, storage, flags)</code> Go through the follow...
0
2016-06-07T11:24:17Z
[ "python", "google-api", "google-api-python-client" ]
Best practice to design django forms for CRUD operations
37,669,824
<p>I am building a django web application for admin which mainly involves CRUD (create,read, update and delete) operations. I need suggestions/best practices to design the forms. I am new to django and python and need experts suggestions. Currently I have created different methods in the views like</p> <pre><code>def...
3
2016-06-07T02:59:03Z
37,756,908
<p>Your CRUD operations seems pretty straightforward, so in this case try using Django's <a href="http://Built-in%20class-based%20generic%20views%C2%B6" rel="nofollow">Class Based Generic Views</a>.</p> <p>As the doc states, this is one of the purposes they were created for:</p> <blockquote> <p>Django’s generic v...
2
2016-06-10T20:44:52Z
[ "python", "django", "crud" ]
Best practice to design django forms for CRUD operations
37,669,824
<p>I am building a django web application for admin which mainly involves CRUD (create,read, update and delete) operations. I need suggestions/best practices to design the forms. I am new to django and python and need experts suggestions. Currently I have created different methods in the views like</p> <pre><code>def...
3
2016-06-07T02:59:03Z
37,756,990
<p>If all you need is really a crud interface to django models, you may as well use the <code>django.contrib.admin</code> app which is designed to do exactly that. Just give users permissions to admin only the objects they need. </p> <p>See <a href="https://docs.djangoproject.com/en/1.9/ref/contrib/admin/" rel="nofoll...
-2
2016-06-10T20:51:17Z
[ "python", "django", "crud" ]
Best practice to design django forms for CRUD operations
37,669,824
<p>I am building a django web application for admin which mainly involves CRUD (create,read, update and delete) operations. I need suggestions/best practices to design the forms. I am new to django and python and need experts suggestions. Currently I have created different methods in the views like</p> <pre><code>def...
3
2016-06-07T02:59:03Z
37,757,150
<p>Class based views are the answer. With class based views:</p> <pre><code>from django.views.generic.edit import (CreateView, DeleteView, UpdateView) class MyView(CreateView): model = MyModel </code></pre> <p>is enough to give you a working view. Replace CreateView with UpdateView and DeleteView. This gives you...
1
2016-06-10T21:05:44Z
[ "python", "django", "crud" ]
Python itertools.combinations_with_replacement not returning all combinations
37,669,869
<p>I have written a simple python program:</p> <pre><code>#!/usr/bin/env python3.5 import sys, itertools sCharacters = '123' for iCombinationLength in range(0, len(sCharacters)+1): for aCombination in itertools.combinations_with_replacement(sCharacters, iCombinationLength): print(''.join(aCombination)) </code><...
2
2016-06-07T03:07:10Z
37,669,896
<p>"combinations" is an order-insensitive term; if you have <code>113</code>, then you don't need <code>131</code> or <code>311</code>, because all of them are the same "combination" (if the input sequence to <code>combinations_with_replacement</code> is unique, you could view the outputs as being all unique values aft...
2
2016-06-07T03:11:51Z
[ "python", "python-3.x", "itertools" ]
Disabling pyc files in production
37,669,883
<p><code>pyc</code> files have been the cause of grief in the past and I have just recently seen a few posts about preventing python from generating them. Currently we just run a script to clean them up after any code changes to ensure fresh ones get generated but it would be much easier to just disable them in general...
2
2016-06-07T03:10:03Z
37,669,985
<p>You can try adding the following code to your main. Any module imported after will not create a .pyc:</p> <pre><code>import sys sys.dont_write_bytecode=True </code></pre> <p>Or setting the enviroment variable:</p> <pre><code>PYTHONDONTWRITEBYTECODE </code></pre> <p>You could also edit or create your <code>usercu...
1
2016-06-07T03:25:49Z
[ "python", "python-2.7", "pyc" ]
Disabling pyc files in production
37,669,883
<p><code>pyc</code> files have been the cause of grief in the past and I have just recently seen a few posts about preventing python from generating them. Currently we just run a script to clean them up after any code changes to ensure fresh ones get generated but it would be much easier to just disable them in general...
2
2016-06-07T03:10:03Z
37,670,100
<p>Disabling the writing and use of compiled bytecode comes with a performance cost at startup -- your Python code is loaded into memory when the process spawns, and non-.pyc/.pyo files means the interpreter is forced to parse every imported file on startup. If you're currently removing all .pyc and .pyo files from yo...
2
2016-06-07T03:43:38Z
[ "python", "python-2.7", "pyc" ]
is there a way to sum up a count?
37,669,905
<p>This is my first post, and I will try to be as detailed as possible.</p> <p>I am recreating the game "Mastermind", but instead of colors, letters are used. The color "red" would be "R", "yellow" would be "Y", etc...</p> <p>I must check for errors, and when an error is inputted by the user, the output should be <co...
1
2016-06-07T03:13:58Z
37,669,993
<p>use the <code>sum</code> built in:</p> <pre><code>uppercase_guess = guess.upper() #no need to call it every time. if sum(uppercase_guess.count(i) for i in "RGYBWO") == 4: ... </code></pre> <p>Although if you want to check that every character is one of those characters it might be clearer to do:</p> <pre><cod...
2
2016-06-07T03:26:57Z
[ "python" ]
is there a way to sum up a count?
37,669,905
<p>This is my first post, and I will try to be as detailed as possible.</p> <p>I am recreating the game "Mastermind", but instead of colors, letters are used. The color "red" would be "R", "yellow" would be "Y", etc...</p> <p>I must check for errors, and when an error is inputted by the user, the output should be <co...
1
2016-06-07T03:13:58Z
37,670,050
<p>Your phrasing is not 100% clear, but I think that you are asking if you can check the contents of the input more efficiently. There are a couple of ways of doing it that are shorter and more flexible than what you have now.</p> <p>You want to check that the input is of length four, and contains no illegal character...
2
2016-06-07T03:35:23Z
[ "python" ]
is there a way to sum up a count?
37,669,905
<p>This is my first post, and I will try to be as detailed as possible.</p> <p>I am recreating the game "Mastermind", but instead of colors, letters are used. The color "red" would be "R", "yellow" would be "Y", etc...</p> <p>I must check for errors, and when an error is inputted by the user, the output should be <co...
1
2016-06-07T03:13:58Z
37,670,441
<p>Try this:</p> <p>Since red could be really be "R" or "r" code for both. </p> <pre><code>allowed = 'RrGgBbYyOoWw' # So, now you accept either case and drop `.upper()` if len(guess) == 4 and sum([guess.count(i) for i in allowed]): </code></pre>
0
2016-06-07T04:22:44Z
[ "python" ]
Getting a list of Urls and then finding specific text from all of them in Python 3.5.1
37,669,952
<p>So I have this code that will give me the urls I need in a list format</p> <pre><code>import requests from bs4 import BeautifulSoup offset = 0 links = [] with requests.Session() as session: while True: r = session.get("http://rayleighev.deviantart.com/gallery/44021661/Reddit?offset=%d" % offset) soup = Bea...
0
2016-06-07T03:21:09Z
37,670,945
<p>Your code:</p> <pre><code>for link in links: url = print("%s" % link) </code></pre> <p>assigns None to url. Perhaps you mean:</p> <pre><code>for link in links: url = "%s" % link.get("href") </code></pre> <p>There's also no reason to use urllib to get the sites content, you can use requests as you did bef...
0
2016-06-07T05:09:51Z
[ "python", "python-3.x", "beautifulsoup", "python-requests", "urllib" ]
Django: GET jquery 404 error
37,669,966
<p>My django is getting a 404 error when trying to get the <code>jquery-2.2.4.js</code> file. However, it is getting the <code>css/boardcss.css</code> file just fine, even though they are both in the same top-level /static/ folder, after doing collectstatic. Any help?</p> <p>Here is the jquery 404 error when I run my ...
2
2016-06-07T03:23:19Z
37,670,063
<p>ok, so you have 2 static folders. I believe that is your problem. note when you go up one level and then look for static, in one of them you have a jquery file and the other you don't.</p> <p>you might need to configure:</p> <p><a href="https://docs.djangoproject.com/en/1.9/ref/settings/#std:setting-STATICFILES_FI...
1
2016-06-07T03:37:38Z
[ "jquery", "python", "django" ]
Time complexity for running len(array) in python?
37,670,070
<p>How does Python find the length of the array? Is it stored somewhere in an internal data-structure or does it have to iterate through the entire thing to find the length?</p> <p>I ask because I'm using it for a binary search which should run in O(log(n)), but this obviously doesn't make sense if I have to iterate t...
0
2016-06-07T03:38:31Z
37,670,147
<p>Lists can store their length as part of their structure. Since it only needs to be stored in one place, it can add a maximum of <code>O(1)</code> to all computations and therefore not be too much overhead.</p> <p>Getting the length is therefore <code>O(1)</code> because it's just the lookup of a field.</p> <p>For ...
2
2016-06-07T03:50:36Z
[ "python" ]
How/where should I store data in a Django app that is not connected to any HTTP request?
37,670,206
<p>I have created a Django app with the usual components: applications, models views, templates, etc. </p> <p>The architecture of a Django app is such that it basically just sits there and does nothing until you call one of the views by hitting a REST endpoint. Then it serves a page (or in my case some JSON) and waits...
1
2016-06-07T03:57:33Z
37,676,442
<p>Lot's of different ways and it's primarily a matter of opinion. The simplest of course would be to keep that data in the source file for the module that connects to twitter. Which looks like your existing system. Which works fine as long as this is not an app that's being commited to a public VCS repository.</p> <p...
1
2016-06-07T10:11:35Z
[ "python", "django", "rest", "twitter", "python-twitter" ]
How do you make a function that divides fractions into simplest form python
37,670,363
<p>I am taking a class and i'm confused. It would really help if you could guide me through the proccess of this and tell me what I am doing wrong. I have an error that has to do with the parentheses since theres nothing in them. I am a newbie so i'm sorry.</p> <pre><code>def FractionDivider(a,b,c,d): n = () d...
0
2016-06-07T04:13:32Z
37,670,416
<p>Your function is taking in arguments <code>a</code>, <code>b</code>, <code>c</code>, and <code>d</code>, but you're not using them anywhere. You're instead defining four new variables. Try:</p> <pre><code>def FractionDivider(n, d, n2, d2): </code></pre> <p>and get rid of your empty parentheses bits, see if that do...
0
2016-06-07T04:19:50Z
[ "python", "python-2.7", "parentheses" ]
How do you make a function that divides fractions into simplest form python
37,670,363
<p>I am taking a class and i'm confused. It would really help if you could guide me through the proccess of this and tell me what I am doing wrong. I have an error that has to do with the parentheses since theres nothing in them. I am a newbie so i'm sorry.</p> <pre><code>def FractionDivider(a,b,c,d): n = () d...
0
2016-06-07T04:13:32Z
37,670,424
<p>you cannot declare a variable as you are doing n = () and then try to assign an integer or string to it. </p> <p>n=() does not mean:</p> <blockquote> <p>n equals nothing at the moment but i will assign a variable shortly.</p> </blockquote> <p>() ---> Tuples <a href="https://docs.python.org/3/tutorial/datastru...
0
2016-06-07T04:20:53Z
[ "python", "python-2.7", "parentheses" ]
How do you make a function that divides fractions into simplest form python
37,670,363
<p>I am taking a class and i'm confused. It would really help if you could guide me through the proccess of this and tell me what I am doing wrong. I have an error that has to do with the parentheses since theres nothing in them. I am a newbie so i'm sorry.</p> <pre><code>def FractionDivider(a,b,c,d): n = () d...
0
2016-06-07T04:13:32Z
37,670,481
<p><code>n=()</code> is a valid python statement and there is no issue with that. However <code>n=()</code> is evaluating <code>n</code> to an empty <code>tuple()</code>. I believe that what you are trying to do is as follows. </p> <pre><code>def FractionDivider(a,b,c,d): ''' Divides a fraction by another ...
0
2016-06-07T04:26:47Z
[ "python", "python-2.7", "parentheses" ]
Python-doit dependecy on a dataset in an h5 file
37,670,445
<p>I have a doit task which depends on one of several datasets contained in an h5 file. </p> <p>Does anyone have any idea how I could (1) check the dependency to determine whether or not to execute the task and (2) save the dependency's signature for checking next time the task is executed?</p>
-1
2016-06-07T04:22:58Z
37,683,521
<p>In <code>doit</code> you can write custom rules to check if a task is up-to-date or not. Check <code>uptodate</code> <a href="http://pydoit.org/dependencies.html#uptodate" rel="nofollow">http://pydoit.org/dependencies.html#uptodate</a></p>
0
2016-06-07T15:29:50Z
[ "python" ]
Check if a python series contains any string in another list
37,670,473
<p>I have a series of equal length strings of 24 characters like </p> <pre><code>my_series = ['ThisIsASentenceXXXXXXXXX', 'SoIsThisXXXXXXXXXXXXXXXX', 'YouGetThePointXXXXXXXXXX'] </code></pre> <p>And I have a list also with equal length strings of 4 characters like</p> <pre><code>my_list = ['This', 'XXXX', 'GetT'] </...
1
2016-06-07T04:26:06Z
37,670,590
<p>The following generator will create a 2 dimensional list. Each list will contain any matches, and it's position will match to the my_list index.</p> <pre><code>n_list = [[x for x in my_series if item in x] for item in my_list] </code></pre> <p>Output:</p> <blockquote> <blockquote> <p>[['ThisIsASentenceXXXXX...
3
2016-06-07T04:38:21Z
[ "python" ]
Check if a python series contains any string in another list
37,670,473
<p>I have a series of equal length strings of 24 characters like </p> <pre><code>my_series = ['ThisIsASentenceXXXXXXXXX', 'SoIsThisXXXXXXXXXXXXXXXX', 'YouGetThePointXXXXXXXXXX'] </code></pre> <p>And I have a list also with equal length strings of 4 characters like</p> <pre><code>my_list = ['This', 'XXXX', 'GetT'] </...
1
2016-06-07T04:26:06Z
37,670,646
<p>You need to split each entries in the <code>my_series</code> into 6 chunks:</p> <pre><code>serires_chunks = [(s[0:4], s[4:8], s[8:12], s[12:16], s[16:20], s[20:24]) for s in my_series] </code></pre> <p>Then you can iterate over this chunks to find the matching items:</p> <pre><code>for item in m...
-1
2016-06-07T04:44:02Z
[ "python" ]
De-referening an hdf5 format?
37,670,489
<p>I am working with two different languages i.e. Matlab and python. I created 5 variables in Matlab. Each variable has a size- (150x1) cells as shown below:</p> <p><a href="http://i.stack.imgur.com/qfwIi.png" rel="nofollow"><img src="http://i.stack.imgur.com/qfwIi.png" alt="enter image description here"></a></p> <p>...
1
2016-06-07T04:27:43Z
37,671,895
<p>Maybe you should save the data in a regular hdf5 file. The .mat file is based on hdf5, but it is not a plain hdf5 file.</p> <p>In MATLAB you can do it natively using <a href="http://es.mathworks.com/help/matlab/import_export/exporting-to-hierarchical-data-format-hdf5-files.html" rel="nofollow">http://es.mathworks....
3
2016-06-07T06:22:14Z
[ "python", "matlab", "python-2.7", "h5py" ]
Python: Dot product of each vector in two lists of vectors
37,670,658
<p>Say I have two lists containing vector:</p> <pre><code>A = [(1,1,1), (0,1,1)] B = [(1,0,1), (1,0,0)] </code></pre> <p>I hope to perform dot product between each vector elementwise so that the output is </p> <pre><code>C = [2, 0] </code></pre> <p>How can I do this in python?</p>
2
2016-06-07T04:45:00Z
37,670,707
<p>You can use numpy for this: <a href="http://docs.scipy.org/doc/numpy/reference/" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/</a></p> <pre><code>import numpy dtprd = numpy.dot(...) </code></pre> <p>Also, see: <a href="http://stackoverflow.com/questions/5919530/what-is-the-pythonic-way-to-calculate-do...
0
2016-06-07T04:48:36Z
[ "python" ]
Python: Dot product of each vector in two lists of vectors
37,670,658
<p>Say I have two lists containing vector:</p> <pre><code>A = [(1,1,1), (0,1,1)] B = [(1,0,1), (1,0,0)] </code></pre> <p>I hope to perform dot product between each vector elementwise so that the output is </p> <pre><code>C = [2, 0] </code></pre> <p>How can I do this in python?</p>
2
2016-06-07T04:45:00Z
37,670,752
<p>We can use zipping, summing, and list comprehensions for a fancy one-liner:</p> <pre><code>A = [(1,1,1), (0,1,1)] B = [(1,0,1), (1,0,0)] C = [sum(i*j for i, j in zip(a, b)) for a, b in zip(A, B)] print(C) # [2, 0] </code></pre>
1
2016-06-07T04:52:28Z
[ "python" ]
Python: Dot product of each vector in two lists of vectors
37,670,658
<p>Say I have two lists containing vector:</p> <pre><code>A = [(1,1,1), (0,1,1)] B = [(1,0,1), (1,0,0)] </code></pre> <p>I hope to perform dot product between each vector elementwise so that the output is </p> <pre><code>C = [2, 0] </code></pre> <p>How can I do this in python?</p>
2
2016-06-07T04:45:00Z
37,670,758
<p>In pure Python, try a nested list/generator comprehension:</p> <pre><code>&gt;&gt;&gt; [sum(ai * bi for ai, bi in zip(a, b)) ... for a, b in zip(A, B)] [2, 0] </code></pre> <p>or with numpy, you can do an element-wise product of the 2-dimensional arrays, followed by a sum along each row:</p> <pre><code>&gt;&gt;&...
1
2016-06-07T04:53:40Z
[ "python" ]
Python: Dot product of each vector in two lists of vectors
37,670,658
<p>Say I have two lists containing vector:</p> <pre><code>A = [(1,1,1), (0,1,1)] B = [(1,0,1), (1,0,0)] </code></pre> <p>I hope to perform dot product between each vector elementwise so that the output is </p> <pre><code>C = [2, 0] </code></pre> <p>How can I do this in python?</p>
2
2016-06-07T04:45:00Z
37,670,763
<p>Try this:</p> <pre><code>[sum([y*z for y, z in zip(*x)]) for x in zip(A, B)] </code></pre> <p>This produces:</p> <pre><code>[2, 0] </code></pre>
0
2016-06-07T04:54:04Z
[ "python" ]
Python: Dot product of each vector in two lists of vectors
37,670,658
<p>Say I have two lists containing vector:</p> <pre><code>A = [(1,1,1), (0,1,1)] B = [(1,0,1), (1,0,0)] </code></pre> <p>I hope to perform dot product between each vector elementwise so that the output is </p> <pre><code>C = [2, 0] </code></pre> <p>How can I do this in python?</p>
2
2016-06-07T04:45:00Z
37,670,773
<pre><code>def dot_product(vector_a, vector_b): vector_c = (vector_a[0]*vector_b[0],vector_a[1]*vector_b[1],vector_a[2]*vector_b[2]) #vector multiplication return sum(vector_c) #sum of each chord in the new vector c = [dot_product(a[0],a[1]), dot_product(b[0],b[1])] </code></pre>
0
2016-06-07T04:55:09Z
[ "python" ]
How can I use Requests with a Pandas dataframe to create multiple Get http request?
37,670,697
<p>I am a hobby programmer and would like to solve a real-world problem I am having. I am a user of a software system that exposes an api that allows one to update/add records using Get. I have the imported the data I would like to modify the system with into Pandas and don't know the best way to iterate over the row...
0
2016-06-07T04:47:45Z
37,670,879
<p>Not sure why you want to use pandas, you can get a list of payloads to iterate through with</p> <pre><code>F1 = ['A','A','A'] F3 = ['HELLO', 'GOODBYE', 'HELLO_AGAIN'] F16 = ['EA','BX','CA'] payloads = [dict(payload,**{'F1': F1, 'F3': F3, 'F16': F16}) for F1,F3,F16 in zip(F1,F3,F16)] </code></pre> <p>EDIT: If yo...
0
2016-06-07T05:05:06Z
[ "python", "pandas", "get", "python-requests" ]
How to implement single sign on in all my sub-domain?
37,670,831
<p>My main domain is <code>example.com</code> and I have sub-domain <code>test.example.com</code> and <code>best.example.com</code>.</p> <p>I want to share user authentication cookies in all my sub domain and all user will login from <code>login.example.com</code>, any user login will redirect to this login domain.</p...
1
2016-06-07T05:00:10Z
37,670,877
<p>Using python default AuthTktAuthenticationPolicy and ACLAuthorizationPolicy. In pyramid AuthTktAuthenticationPolicy you have to give a secret key, your sceret key will be same for all sub-domainan and you have give parent_domain=True in AuthTktAuthenticationPolicy then if you login in login.example.com you automatic...
3
2016-06-07T05:04:57Z
[ "python", "authentication", "pyramid" ]
cron couldn't run Scrapy
37,670,895
<p>The code in crontab <code>0 * * * * cd /home/scrapy/foo/ &amp;&amp; scrapy crawl foo &gt;&gt; /var/log/foo.log</code></p> <p>It failed to run the crawl, as there was no log in my log file. I tested using <code>0 * * * * cd /home/scrapy/foo/ &amp;&amp; pwd &gt;&gt; /var/log/foo.log</code>, it echoed '/home/scrapy/fo...
0
2016-06-07T05:06:17Z
37,671,078
<p>You should use logging module(<a href="https://docs.python.org/2/library/logging.html" rel="nofollow">https://docs.python.org/2/library/logging.html</a>,) not redirection.(if you use logging module, you can handle log path and log level)</p> <p>and try this code in crontab</p> <pre><code>0 * * * * /usr/bin/python2...
-1
2016-06-07T05:19:59Z
[ "python", "cron", "scrapy", "crontab" ]
cron couldn't run Scrapy
37,670,895
<p>The code in crontab <code>0 * * * * cd /home/scrapy/foo/ &amp;&amp; scrapy crawl foo &gt;&gt; /var/log/foo.log</code></p> <p>It failed to run the crawl, as there was no log in my log file. I tested using <code>0 * * * * cd /home/scrapy/foo/ &amp;&amp; pwd &gt;&gt; /var/log/foo.log</code>, it echoed '/home/scrapy/fo...
0
2016-06-07T05:06:17Z
37,671,502
<p>Problem solved. Rather than running the crawl as <code>root</code>, use <code>crontab -u user -e</code> to create a crontab for <code>user</code>, and run as <code>user</code>.</p>
0
2016-06-07T05:53:52Z
[ "python", "cron", "scrapy", "crontab" ]
How to improve Haar Cascade accuracy in OpenCV?
37,670,973
<p>I have collected 1000 positive(50*50) images and 1000 negative(50*50) images and trained Haar Cascade in OpenCV. I am trying to detect mobile phones. code for training :</p> <pre><code>opencv_traincascade -data data -vec crop1.vec -bg mob_neg.txt -numPos 900 -numNeg 900 -numStages 15 -w 50 -h 50 bgcolor 255 -bgthre...
0
2016-06-07T05:11:57Z
39,170,224
<p>I'm very much a novice but found this article helpful:</p> <p><a href="https://pythonprogramming.net/haar-cascade-object-detection-python-opencv-tutorial/" rel="nofollow">https://pythonprogramming.net/haar-cascade-object-detection-python-opencv-tutorial/</a></p> <p>In it the author mentions a rule of thumb of usin...
0
2016-08-26T15:53:28Z
[ "python", "opencv", "haar-classifier" ]
Pygame on Yocto
37,671,014
<p>I've been trying to install the python library for making games, pygame, in my yocto image of linux for my raspberry pi 2. I have a python code of a game, I've run it in raspbian and it runs pretty slow, but it runs. Now in my image of linux I already have python but I have failed in installing the pygame library. E...
-1
2016-06-07T05:15:19Z
37,674,754
<p>Did you check your PYTHONPATH is set ? To set it, do:</p> <pre><code>export PYTHONPATH=/opt/ros/indigo/lib/python2.7/site-packages </code></pre> <p>You can add this line to your .profile or .bashrc</p>
0
2016-06-07T08:53:38Z
[ "python", "pygame", "yocto" ]
Using classes and objects to compute a students GPA
37,671,063
<p>Here's my code: </p> <pre><code>class student: def __init__(self): self.totalSumOGrades = 0 self.numberOGrades = 0 def getAverageScore(self): return (self.totalSumOGrades / self.numberOGrades) def addGrade(self,grade): self.totalSumOGrades = str(grade) self.numb...
-4
2016-06-07T05:19:04Z
37,676,250
<p>So as I promised an answer / feedback version to help the OP walk through and pick some new questions - here it is (offered in the hope that train hacking is sufficiently high quality to show case some concepts and offer agood start to create a real solution based on this):</p> <pre><code>#! /usr/bin/env python fro...
0
2016-06-07T10:02:22Z
[ "python", "python-3.x" ]
Find text but skip other elements
37,671,207
<p>I currently try to get the text out of a 'td' element but there are more elements inside it. so the find() returns me the whole text inside the td tag. Here's the Code:</p> <pre><code>&lt;td class="some class"&gt; Some text that i want&lt;br&gt; &lt;a href="some/link"&gt;some more text&lt;/a&gt; &lt;sp...
0
2016-06-07T05:31:07Z
37,671,784
<p>Simply use <code>.text</code> on that element. </p> <pre><code>b=bs4.BeautifulSoup("""&lt;td class="some class"&gt; Some text that i want&lt;br&gt; &lt;a href="some/link"&gt;some more text&lt;/a&gt; &lt;span class="some other class"&gt;some more text&lt;/span&gt; &lt;br&gt; &lt;/td&gt;""") txt = b.find('td').text ...
0
2016-06-07T06:14:29Z
[ "python", "web-scraping", "beautifulsoup" ]
Find text but skip other elements
37,671,207
<p>I currently try to get the text out of a 'td' element but there are more elements inside it. so the find() returns me the whole text inside the td tag. Here's the Code:</p> <pre><code>&lt;td class="some class"&gt; Some text that i want&lt;br&gt; &lt;a href="some/link"&gt;some more text&lt;/a&gt; &lt;sp...
0
2016-06-07T05:31:07Z
37,671,898
<p>For the first text only you can get the 'td' class, convert it into a list and get the first index:</p> <pre><code>t =''' &lt;td class="some class"&gt; Some text that i want&lt;br&gt; &lt;a href="some/link"&gt;some more text&lt;/a&gt; &lt;span class="some other class"&gt;some more text&lt;/span&gt; &...
0
2016-06-07T06:22:36Z
[ "python", "web-scraping", "beautifulsoup" ]
Find text but skip other elements
37,671,207
<p>I currently try to get the text out of a 'td' element but there are more elements inside it. so the find() returns me the whole text inside the td tag. Here's the Code:</p> <pre><code>&lt;td class="some class"&gt; Some text that i want&lt;br&gt; &lt;a href="some/link"&gt;some more text&lt;/a&gt; &lt;sp...
0
2016-06-07T05:31:07Z
37,680,145
<p>A more common way to get the "Some text that i want" would be to use <code>find(text=True)</code>, which would find the <em>first text node</em> inside a tag:</p> <pre><code>from bs4 import BeautifulSoup data = """&lt;td class="some class"&gt; Some text that i want&lt;br&gt; &lt;a href="some/link"&gt;some more...
0
2016-06-07T13:00:26Z
[ "python", "web-scraping", "beautifulsoup" ]
how to implement this code using loops in bash or python
37,671,210
<p>Below code basically prints a dot "." where Im trying to imitate a progress bar in shellscript</p> <pre><code>#!/bin/bash printf "Copying files .." sleep 1 printf "." sleep 1 printf "." sleep 1 printf ".." clear sleep 1 echo "" echo "File copy complete" </code></pre>
0
2016-06-07T05:31:09Z
37,671,289
<p>It may help you !</p> <pre><code>import time print "Copying files .." time.sleep(1) print "." time.sleep(1) print "." time.sleep(1) print ".." time.sleep(1) print "" print "File copy complete" </code></pre>
0
2016-06-07T05:37:08Z
[ "python", "bash" ]
how to implement this code using loops in bash or python
37,671,210
<p>Below code basically prints a dot "." where Im trying to imitate a progress bar in shellscript</p> <pre><code>#!/bin/bash printf "Copying files .." sleep 1 printf "." sleep 1 printf "." sleep 1 printf ".." clear sleep 1 echo "" echo "File copy complete" </code></pre>
0
2016-06-07T05:31:09Z
37,671,346
<p>There are so many ways to write a loop. I kind of like:</p> <pre><code>yes | sed 5q | while read r; do sleep 1; printf .; done; echo </code></pre> <p>But you really don't want a loop; you want to keep printing the progress bar until the copy finishes, so you want something like:</p> <pre><code>progress() { while...
1
2016-06-07T05:41:24Z
[ "python", "bash" ]
how to implement this code using loops in bash or python
37,671,210
<p>Below code basically prints a dot "." where Im trying to imitate a progress bar in shellscript</p> <pre><code>#!/bin/bash printf "Copying files .." sleep 1 printf "." sleep 1 printf "." sleep 1 printf ".." clear sleep 1 echo "" echo "File copy complete" </code></pre>
0
2016-06-07T05:31:09Z
37,671,455
<p>In Python you could do something like this:</p> <pre><code>from time import sleep from sys import stdout Print = stdout.write Print("Copying files..") for x in xrange(4): Print(".") sleep(1) print "\nFile copy complete." </code></pre> <p>On each iteration it prints a new <code>.</code></p> <p>After a q...
1
2016-06-07T05:49:22Z
[ "python", "bash" ]
Object Oriented Programming: object initialization of a class by passing the instance of other class
37,671,215
<p>I have created a test subject to understand my Object Oriented Programming.</p> <pre><code>class Asset(object): def __init__(self, project): self.project = project def do_something(self): return self.project.x, self.project.y, True class Project(object): def __init__(self, x, y): ...
0
2016-06-07T05:31:25Z
37,671,326
<p>Yes it is correct.</p> <p>You can also pass an <code>Asset</code> as a parameter of <code>Project</code> constructor, like this:</p> <pre><code>class Asset(object): def __init__(self, project=None): self.project = project class Project(object): def __init__(self, x, y, asset): self.x = x ...
1
2016-06-07T05:39:58Z
[ "python", "class", "object" ]
Object Oriented Programming: object initialization of a class by passing the instance of other class
37,671,215
<p>I have created a test subject to understand my Object Oriented Programming.</p> <pre><code>class Asset(object): def __init__(self, project): self.project = project def do_something(self): return self.project.x, self.project.y, True class Project(object): def __init__(self, x, y): ...
0
2016-06-07T05:31:25Z
37,671,372
<p>Yes, you perfectly can. This design pattern is called <strong>Composition over inheritance</strong></p> <blockquote> <p><strong>Composition over inheritance</strong> (or composite reuse principle) in object-oriented programming is the principle that classes should achieve polymorphic behavior and code reuse b...
3
2016-06-07T05:43:02Z
[ "python", "class", "object" ]
Object Oriented Programming: object initialization of a class by passing the instance of other class
37,671,215
<p>I have created a test subject to understand my Object Oriented Programming.</p> <pre><code>class Asset(object): def __init__(self, project): self.project = project def do_something(self): return self.project.x, self.project.y, True class Project(object): def __init__(self, x, y): ...
0
2016-06-07T05:31:25Z
37,671,816
<p>This may be called <a href="https://en.wikipedia.org/wiki/Object_composition" rel="nofollow">object composition</a>, and you are mainly expressing: a Project "has a" Assert. In most languages, "field", "property" etc. are used to denote the reference object (Assert here).</p> <p>For design pattern Composition over ...
0
2016-06-07T06:16:40Z
[ "python", "class", "object" ]
Global variable is not defined error
37,671,620
<p>I have tried to implement the code for streaming tweets based on geolocation and got the code for same but i am constantly getting the error as "global name 'requestid' is not defined." The code written is as given below:</p> <pre><code># Geolocation twitter crawler using streaming API import os import sys import ...
-1
2016-06-07T06:02:10Z
37,676,367
<p>requestid is not defined as indicated. I know nothing about this code; however, is requestid bundled in the received JSON packet? If so, extract it from same before using it to build your csv filename in the on_data(...) method.</p>
0
2016-06-07T10:08:05Z
[ "python", "dictionary", "geolocation", "web-crawler" ]
Lost connection to MySQL server at 'waiting for initial communication packet'
37,671,774
<p>I have seen many stack overflows questions and some blogs tried workarounds, but nothings helped - hence re-posting the question with more details. </p> <p>I am seeing the weird behaviour with MySQL and Python application, details are as follows:</p> <p>1) My application works perfectly fine with MySQL (tried and ...
2
2016-06-07T06:13:48Z
37,741,979
<p><strong>Found a reason - answering my question:</strong></p> <p>When I used to run MySQL from my application - it was running under system user privileges - so it used to pick "<strong>C:\WINDOWS\TEMP</strong>" as a temp directory- this directory was messed up - has lot of unnecessary files .. and MySQL was stuck ...
1
2016-06-10T07:06:51Z
[ "python", "mysql", "windows" ]
Control PWR Led on Raspberry 3
37,671,824
<p>I read quite a few articels that say that the power led is now hardwired on a raspy 3 device but some say it is somehow possible (but do not give specific answers). </p> <p>My question(s): 1.) is it possible to control the led via python and how. 2.) if not then can I permanently disable it?</p>
0
2016-06-07T06:17:34Z
37,675,188
<p>The power LED is now also acting as a low-voltage indicator now. It is possible (however not trivial) to use it as an output but then the low-voltage indicaton is not working anymore. If I understand it correctly, the devs need to come up with a solution, so not much "normal" users can do for now.</p> <p>There is a...
1
2016-06-07T09:15:36Z
[ "python", "raspberry-pi3" ]
It is possible to execute a Python script that is on a Raspberry Pi using Web2Py which is installed on an other machine?
37,671,865
<p>I have a Raspberry Pi, that must run a Python script so it can manually turn ON/OFF a LED. Because I don't want to run a web server on the Pi, I installed Web2Py on another machine. For now I can only retrieve data from a MySQL database (temperature and humidity), but I cannot run other scripts using a button from t...
0
2016-06-07T06:20:24Z
37,672,056
<p>On your machine with the web server, use paramiko (python library) to communicate with the pi and launch a script there, then get the answer back and display it (if there is one).</p> <p>On the web server machine :</p> <pre><code>// server.py def leds_set(state): import paramiko ssh = paramiko.SSHClient() s...
1
2016-06-07T06:33:14Z
[ "python", "web" ]
python3 to parse html part with xpath
37,671,953
<p>I just want to extract div part html part from the following html with path xpath. I just give some part of this link html:</p> <pre><code> &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Items 1 to 20 -- Example Page 1&lt;/title&gt; &lt;script type="text/javascript"&gt; ...
0
2016-06-07T06:26:40Z
37,691,848
<p>I have solved this issue, just use the following code, add the //* in my code, it works:</p> <pre><code> buy_info2 = tree.xpath('//div[contains(@title, "item-body")]//*') </code></pre> <p>then I can I get all the html element that I want to. Thanks!</p>
0
2016-06-08T01:21:01Z
[ "python", "html", "xpath" ]
python3 to parse html part with xpath
37,671,953
<p>I just want to extract div part html part from the following html with path xpath. I just give some part of this link html:</p> <pre><code> &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Items 1 to 20 -- Example Page 1&lt;/title&gt; &lt;script type="text/javascript"&gt; ...
0
2016-06-07T06:26:40Z
37,764,142
<p>You can pull the div using the class name:</p> <pre><code>In [2]: from lxml import html In [3]: xml = html.fromstring(h) In [4]: div = xml.xpath("//div[@class='item-body']")[0] In [5]: print(html.tostring(div)) &lt;div class="item-body" title="item1"&gt; &lt;div title="buyer-name"&gt;Carson Busses&lt;/div&gt; ...
0
2016-06-11T13:12:37Z
[ "python", "html", "xpath" ]
Tensorflow negative sampling
37,671,974
<p>I am trying to follow the udacity tutorial on tensorflow where I came across the following two lines for word embedding models:</p> <pre><code> # Look up embeddings for inputs. embed = tf.nn.embedding_lookup(embeddings, train_dataset) # Compute the softmax loss, using a sample of the negative labels each time....
2
2016-06-07T06:27:55Z
37,673,769
<p>You can find the documentation for <code>tf.nn.sampled_softmax_loss()</code> <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/nn.html#candidate-sampling" rel="nofollow">here</a>. There is even a good explanation of <strong>Candidate Sampling</strong> provided by TensorFlow <a href="https://www.tenso...
3
2016-06-07T08:03:46Z
[ "python", "tensorflow" ]
Tensorflow negative sampling
37,671,974
<p>I am trying to follow the udacity tutorial on tensorflow where I came across the following two lines for word embedding models:</p> <pre><code> # Look up embeddings for inputs. embed = tf.nn.embedding_lookup(embeddings, train_dataset) # Compute the softmax loss, using a sample of the negative labels each time....
2
2016-06-07T06:27:55Z
37,676,279
<p><a href="https://www.tensorflow.org/versions/r0.9/extras/candidate_sampling.pdf" rel="nofollow">Candidate sampling</a> explains how the sampled loss function is calculated:</p> <ul> <li>Compute the loss function in a subset <em>C</em> of all training samples <em>L</em>, where <em>C = T ⋃ S</em>, <em>T</em> is the...
1
2016-06-07T10:03:35Z
[ "python", "tensorflow" ]
Find common prefix ends with multiple suffix in python
37,672,011
<p>I have a list of string.</p> <pre><code>A = [ 'kite1.json', 'kite1.mapping.json', 'kite1.analyzer.json', 'kite2.json', 'kite3.mapping.json', 'kite3.mapping.mapping.json', 'kite3.mapping.analyzer.json', ] </code></pre> <p>I need to find common prefix which ends with all of <code>.json</code>, <code>....
3
2016-06-07T06:30:02Z
37,672,250
<p>Well, all you need is to collect a set of prefixes for each suffix in <code>['.json', '.mapping.json', '.analyzer.json']</code> and then just take an intersection of these sets:</p> <pre><code>In [1]: A = [ ...: 'kite1.json', ...: 'kite1.mapping.json', ...: 'kite1.analyzer.json', ...: 'kite2.jso...
1
2016-06-07T06:43:48Z
[ "python" ]
Find common prefix ends with multiple suffix in python
37,672,011
<p>I have a list of string.</p> <pre><code>A = [ 'kite1.json', 'kite1.mapping.json', 'kite1.analyzer.json', 'kite2.json', 'kite3.mapping.json', 'kite3.mapping.mapping.json', 'kite3.mapping.analyzer.json', ] </code></pre> <p>I need to find common prefix which ends with all of <code>.json</code>, <code>....
3
2016-06-07T06:30:02Z
37,672,259
<p>Use <a href="https://docs.python.org/2/library/re.html#re.match" rel="nofollow"><code>re.match</code></a> and <a href="https://docs.python.org/2/library/re.html#re.MatchObject.group" rel="nofollow">capturing groups</a> to extract all matches for each of your patterns. Then take the <a href="https://docs.python.org/2...
1
2016-06-07T06:44:17Z
[ "python" ]
Find common prefix ends with multiple suffix in python
37,672,011
<p>I have a list of string.</p> <pre><code>A = [ 'kite1.json', 'kite1.mapping.json', 'kite1.analyzer.json', 'kite2.json', 'kite3.mapping.json', 'kite3.mapping.mapping.json', 'kite3.mapping.analyzer.json', ] </code></pre> <p>I need to find common prefix which ends with all of <code>.json</code>, <code>....
3
2016-06-07T06:30:02Z
37,672,510
<p>If this were <a href="http://codegolf.stackexchange.com">code-golf</a>, I might win:</p> <pre><code>def ew(sx): return set([s[:-len(sx)] for s in A if s.endswith(sx)]) ew('.analyzer.json') &amp; ew('.mapping.json') &amp; ew('.json') </code></pre> <p>The <code>ew()</code> function loops through <code>A</code>,...
3
2016-06-07T06:59:36Z
[ "python" ]
Find common prefix ends with multiple suffix in python
37,672,011
<p>I have a list of string.</p> <pre><code>A = [ 'kite1.json', 'kite1.mapping.json', 'kite1.analyzer.json', 'kite2.json', 'kite3.mapping.json', 'kite3.mapping.mapping.json', 'kite3.mapping.analyzer.json', ] </code></pre> <p>I need to find common prefix which ends with all of <code>.json</code>, <code>....
3
2016-06-07T06:30:02Z
37,672,518
<pre><code>string = "\n".join(A) json_prefices = re.findall(r"(.*?)\.json", string) mapping_json_prefices = re.findall(r"(.*?)\.mapping\.json", string) analyzer_json_prefices = re.findall(r"(.*?)\.analyzer\.json", string) result = list(set(json_prefices) &amp; set(mapping_json_prefices) &amp; set(analy...
0
2016-06-07T06:59:59Z
[ "python" ]
Get name of Amazon Web Services Codecommit Repository in triggered Lambda function
37,672,138
<p>I've created a trigger in my AWS CodeCommit repositories which runs a Lambda function whenever it is triggered. The Lambda function calls a script at my development server to perform a git pull. So far so good. </p> <p>The problem is that I need to pass the name or ID of the repository that sets off the trigger to ...
1
2016-06-07T06:38:22Z
37,687,443
<p>The code to pull out the repository is in the Python <a href="http://docs.aws.amazon.com/codecommit/latest/userguide/how-to-notify-lambda.html" rel="nofollow">example</a>. The code snippet is:</p> <pre><code>#Get the repository from the event and show its git clone URL repository = event['Records'][0]['eventSourceA...
1
2016-06-07T19:09:31Z
[ "python", "git", "amazon-web-services", "lambda", "aws-codecommit" ]
Streaming wrapper around program that writes to multiple output files
37,672,160
<p>There is a program (which I cannot modify) that creates two output files. I am trying to write a Python wrapper that invokes this program, reads both output streams simultaneously, combines the output, and prints to stdout (to facilitate streaming). How can I do this without deadlocking? The following proof of conce...
2
2016-06-07T06:39:24Z
37,672,877
<p><code>Popen</code> only spawns the process. You have to do something like <code>child.communicate()</code> to actually interact with it and obtain its output.</p> <p>Also, I think you'll need to <code>open</code> the pipes for reading before starting the process.</p>
1
2016-06-07T07:18:11Z
[ "python", "subprocess", "deadlock", "pipeline" ]
Streaming wrapper around program that writes to multiple output files
37,672,160
<p>There is a program (which I cannot modify) that creates two output files. I am trying to write a Python wrapper that invokes this program, reads both output streams simultaneously, combines the output, and prints to stdout (to facilitate streaming). How can I do this without deadlocking? The following proof of conce...
2
2016-06-07T06:39:24Z
37,686,462
<blockquote> <p>I'm seeing big chunks of one file and then big chunks of the other file, regardless of whether I write to stdout, stderr, or tty.</p> </blockquote> <p>If you can't make the child to use line-buffering for files then a simple solution <em>to read complete interleaved lines from the output files while ...
3
2016-06-07T18:13:16Z
[ "python", "subprocess", "deadlock", "pipeline" ]
How to manipulate integer data in CSV?
37,672,505
<p>I am trying to make a bank , but i am failing to change the integer data of the file. What my file contains is:</p> <pre><code>astle,hello,11 monish,mr7,0 </code></pre> <p>Now in my 'choice1'(later show in the code) when i try to deposit say suppose 100 , it does not change the value instead gives the same value....
0
2016-06-07T06:59:13Z
37,687,186
<p>You need to convert the value from <code>str</code> to <code>int</code>. Try this. </p> <pre><code>row[2] = str(int(row[2]) + c) </code></pre>
0
2016-06-07T18:54:46Z
[ "python", "python-2.7", "csv" ]
How to pass the start url in scrappy rules link extractor?
37,672,566
<p>I have a set of start urls, like below:</p> <pre><code>start_urls = [www.example.com,www.example.com/ca,wwww.example.com/ap] </code></pre> <p>Now I have written code for extracting all the urls occurring inside each start_urls like below:</p> <pre><code>rules = (Rule( LinkExtractor( allow_domains = ('...
0
2016-06-07T07:02:35Z
37,683,012
<ol> <li><p>You could not use the <code>CrawlSpider</code> and pass the start_url information yourself from <code>start_requests</code> through all your callbacks</p></li> <li><p>You could create a <a href="http://doc.scrapy.org/en/latest/topics/spider-middleware.html#spider-middleware" rel="nofollow"><code>Spider Midd...
0
2016-06-07T15:05:43Z
[ "python", "web-scraping", "scrapy" ]
Python - Speed up for converting a categorical variable to it's numerical index
37,672,704
<p>I need to convert a column of categorical variables in a Pandas data frame into a numerical value that corresponds to the index into an array of the unique categorical variables in the column (long story !) and here's a code snippet that accomplishes that:</p> <pre><code>import pandas as pd import numpy as np d = ...
3
2016-06-07T07:10:18Z
37,672,792
<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.factorize.html" rel="nofollow"><code>factorize</code></a>:</p> <pre><code>df['col'] = pd.factorize(df.col)[0] print (df) col 0 0 1 1 2 0 3 0 4 1 </code></pre> <p><a href="http://pandas.pydata.org/pandas-docs/stable/reshapin...
3
2016-06-07T07:14:39Z
[ "python", "performance", "numpy", "pandas", "dataframe" ]
Python - Speed up for converting a categorical variable to it's numerical index
37,672,704
<p>I need to convert a column of categorical variables in a Pandas data frame into a numerical value that corresponds to the index into an array of the unique categorical variables in the column (long story !) and here's a code snippet that accomplishes that:</p> <pre><code>import pandas as pd import numpy as np d = ...
3
2016-06-07T07:10:18Z
37,672,825
<p>You can use <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.unique.html" rel="nofollow"><code>np.unique</code></a>'s optional argument <code>return_inverse</code> to ID each string based on their uniqueness among others and set those in the input dataframe, like so -</p> <pre><code>_,idx =...
3
2016-06-07T07:15:39Z
[ "python", "performance", "numpy", "pandas", "dataframe" ]
how to write a regex for this string: (RA pp 24-25; 2 AA pp. 184-185, 194-200, 201-210, 900-410, 789.) and there was a a test ( AA pp. 450)
37,672,726
<p>I'm looking for a regex which gives me <code>2 AA pp. 184-185</code>, <code>194-200</code>, <code>201-210</code>, <code>900-410</code>, <code>789.</code> and <code>AA pp 450</code> from:</p> <pre><code>RA pp 24-25; 2 AA pp. 184-185, 194-200, 201-210, 900-410, 789. </code></pre> <p>I've come up with this so far: </...
-3
2016-06-07T07:11:24Z
37,672,956
<p>This regex:</p> <pre><code>import re p = re.compile(ur'(?:([-\d\w ]+)[;,.] ?)', re.MULTILINE | re.IGNORECASE) test_str = u"RA pp 24-25; 2 AA pp. 184-185, 194-200, 201-210, 900-410, 789." print re.findall(p, test_str) </code></pre> <p>Gives: </p> <blockquote> <p>[u'RA pp 24-25', u'2 AA pp', u'184-185', u'194-20...
0
2016-06-07T07:22:42Z
[ "python", "regex", "python-2.7" ]
how to write a regex for this string: (RA pp 24-25; 2 AA pp. 184-185, 194-200, 201-210, 900-410, 789.) and there was a a test ( AA pp. 450)
37,672,726
<p>I'm looking for a regex which gives me <code>2 AA pp. 184-185</code>, <code>194-200</code>, <code>201-210</code>, <code>900-410</code>, <code>789.</code> and <code>AA pp 450</code> from:</p> <pre><code>RA pp 24-25; 2 AA pp. 184-185, 194-200, 201-210, 900-410, 789. </code></pre> <p>I've come up with this so far: </...
-3
2016-06-07T07:11:24Z
37,675,129
<p>You can use the <code>re.split</code>:</p> <pre><code>string = "RA pp 24-25; 2 AA pp. 184-185, 194-200, 201-210, 900-410, 789." print re.split(r'[;,]\s*', string) </code></pre> <p>The output is:</p> <pre><code>['RA pp 24-25', '2 AA pp. 184-185', '194-200', '201-210', '900-410', '789.'] </code></pre>
0
2016-06-07T09:12:47Z
[ "python", "regex", "python-2.7" ]
Serving python objects in memory for other python programs
37,672,766
<p>Consider the following code the second line takes about a minute to finish ,and for each program I have the lines below, so how can i rather serve the nlp object rather than loading it each time from various programs?</p> <pre><code>import spacy nlp = spacy.load('en') </code></pre> <p>Ideally something like :</p> ...
0
2016-06-07T07:13:53Z
37,672,869
<p>What you're looking for is called serialization. The python package for that is called pickle. You can find the documentation here: <a href="https://docs.python.org/2/library/pickle.html" rel="nofollow">https://docs.python.org/2/library/pickle.html</a></p> <pre><code>// save.py // Save a dictionary into a pickle f...
0
2016-06-07T07:17:46Z
[ "python", "server", "nlp", "spacy" ]
Store output of for loop into single variable
37,672,799
<p>I have a for loop that retrieves bigram data of a page of text from an SQLite3 database.</p> <pre><code>def bigram_db(): cursr.execute("SELECT * FROM trainedGrammar") data = cursr.fetchall() for data in data: element = data txt = element[0] #fetch first element of list txt += txt return txt </code></pre...
0
2016-06-07T07:14:55Z
37,673,061
<p>You don't need to execute <code>fetchall()</code>, you can iterate directly on the cursor. And you cannot use the same variable <code>txt</code> for two purposes; in the loop, the line <code>txt = element[0]</code> overwrites its old value.</p> <p>Your function should look like this:</p> <pre><code>def bigram_db()...
2
2016-06-07T07:27:51Z
[ "python" ]
How can I remove specific index from list in python
37,672,850
<p>I'm trying to figure out how to remove specific index from list, but I don't know how to fix my problem. Can someone help me to solve this?</p> <p>First, I have to get some numbers from users using input.</p> <pre><code>numbers = int(input("input any numbers: ")) list_num = list(numbers) </code></pre> <p>Second, ...
-1
2016-06-07T07:16:56Z
37,672,945
<p>You can delete it by using keyword <strong><em>del</em></strong>. Here is the example.</p> <pre><code>my_list = [1, 2, 3, 4, 5] del my_list[0] # 0 is the index </code></pre> <p>This will delete the first index of my_list. So the resultant list will be <strong><em>[2, 3, 4, 5]</em></strong></p> <p><a href="http://...
2
2016-06-07T07:22:03Z
[ "python", "list", "indexing" ]
How can I remove specific index from list in python
37,672,850
<p>I'm trying to figure out how to remove specific index from list, but I don't know how to fix my problem. Can someone help me to solve this?</p> <p>First, I have to get some numbers from users using input.</p> <pre><code>numbers = int(input("input any numbers: ")) list_num = list(numbers) </code></pre> <p>Second, ...
-1
2016-06-07T07:16:56Z
37,673,655
<p>There were several issues with your code including syntax, indentation and logic. I have formatted your code into a working manner. Good Luck.</p> <pre><code>numbers = input("input any numbers:") list_num = list(numbers) ret = [] for i,v in enumerate(list_num): if i == 0 and v == 1: continue if v =...
-1
2016-06-07T07:57:33Z
[ "python", "list", "indexing" ]
How can I remove specific index from list in python
37,672,850
<p>I'm trying to figure out how to remove specific index from list, but I don't know how to fix my problem. Can someone help me to solve this?</p> <p>First, I have to get some numbers from users using input.</p> <pre><code>numbers = int(input("input any numbers: ")) list_num = list(numbers) </code></pre> <p>Second, ...
-1
2016-06-07T07:16:56Z
37,673,770
<p>Please review your question again. Please correct your question because it is unclear what you are trying to achieve. These are the two conditions that i think you wish to achieve.</p> <ol> <li>if <code>list[0] == 1</code> then remove that element.</li> <li>if <code>list[i+1]-1 == list[i]</code> then remove <code>l...
1
2016-06-07T08:03:48Z
[ "python", "list", "indexing" ]
schedule repeating jobs in Python with time unit specified as a variable
37,672,950
<p>I've been using the excellent <code>schedule</code> library to run a variety of jobs, but there is one thing I can't find.</p> <p>The Python code for running a job every 10 minutes looks like this:</p> <pre><code>schedule.every(10).minutes.do(job) </code></pre> <p>Question is: how would I elegantly incorporate th...
0
2016-06-07T07:22:15Z
37,715,823
<p>I've answered my own question. Thanks to those who replied.</p> <pre><code># specify time interval units as a variable in code... interval = 3 time_unit = 'hours' schedule.every(interval).set_units(time_unit).do(job) </code></pre> <p>Hotfix in the <code>schedule</code> library (class Job)-- add the following metho...
0
2016-06-09T02:19:47Z
[ "python", "schedule" ]
Plot google maps data as a picture without generating an html file
37,673,073
<p>I'm using the python library gmplot for getting a map from GoogleMaps and georeferencing some point coordinates. I would like to plot my Googlemap result in a detached window like I do with images generated with matplotlib, but with gmplot I can see only the draw() function which generates an html of the googlemaps ...
-1
2016-06-07T07:28:33Z
37,673,578
<p>If you want to store a map as an image you can refer <a href="http://stackoverflow.com/questions/7490491/capture-embedded-google-map-image-with-python-without-using-a-browser">this question</a> to do that. With some minor change i was able to get the result in a .bmp format.</p> <p>here is my small edited code for ...
1
2016-06-07T07:53:43Z
[ "python", "google-maps" ]
Recursively calling a Merge Sort algorithm
37,673,137
<p>I'm new to recursion, and currently writing a Merge Sort algorithm that compares the first elements of two lists and determines which one is smaller, then adds the smaller one to a new list.</p> <p>I'm trying to update the three lists after each comparison and have the function call itself again with the updated li...
4
2016-06-07T07:31:54Z
37,673,197
<p>Your code lead to infinite recursion. You should move <code>list1</code>,<code>list2</code> and <code>new_list</code> initialization outside of <code>merge_Sort</code> function.</p> <pre><code>def merge_Sort(list1, list2, new_list): for i in range(len(list1)): if list1[0] &lt; list2[0]: new_...
7
2016-06-07T07:35:09Z
[ "python", "algorithm", "recursion" ]
Comparing columns in Pyspark
37,673,414
<p>I am working on a PySpark DataFrame with n columns. I have a set of m columns (m &lt; n) and my task is choose the column with max values in it.</p> <p>For example: </p> <p>Input: PySpark DataFrame containing col_1 = [1,2,3], col_2 = [2,1,4], col_3 = [3,2,5]. </p> <p>Ouput = col_4 = max(col1, col_2, col_3) = [3,...
1
2016-06-07T07:45:46Z
37,675,525
<p>You can reduce using SQL expressions over a list of columns:</p> <pre class="lang-py prettyprint-override"><code>from pyspark.sql.functions import max as max_, col, when from functools import reduce def row_max(*cols): return reduce( lambda x, y: when(x &gt; y, x).otherwise(y), [col(c) if isins...
1
2016-06-07T09:30:10Z
[ "python", "apache-spark", "pyspark" ]
Pyspark - Using a custom function in map transform
37,673,462
<p>I run the following file (called <code>test_func.py</code>) with <code>py.test</code>:</p> <pre><code>import findspark findspark.init() from pyspark.context import SparkContext def filtering(data): return data.map(lambda p: modif(p)).count() def modif(row): row.split(",") class Test(object): sc = ...
1
2016-06-07T07:48:09Z
37,674,487
<p>The key here is the <code>Traceback</code> you got.</p> <p>PySpark is telling you that the worker process doesn't have access to <code>clustering.test_func.py</code>. When you initialize the <code>SparkContext</code> you can pass a list of files that should be copied to the worker:</p> <pre><code>sc = SparkContext...
0
2016-06-07T08:40:19Z
[ "python", "apache-spark", "pyspark" ]
How to import an updated module without restarting session in Rodeo?
37,673,577
<p>In Rodeo, if my script A imports a module B, and I make modifications to module B after running script A once, I have to restart the session in order for my script A to read the updated module B, in the process wiping my workspace and namespace clean. Is there a way to iterate quickly on importing B into A in a less...
1
2016-06-07T07:53:35Z
37,673,795
<p>Try this:</p> <pre><code>import moduleB reload (moduleB) </code></pre> <p>after new edits in ModuleB you can just use <strong><code>reload(moduleB)</code></strong></p>
1
2016-06-07T08:05:05Z
[ "python", "rodeo" ]
How to import an updated module without restarting session in Rodeo?
37,673,577
<p>In Rodeo, if my script A imports a module B, and I make modifications to module B after running script A once, I have to restart the session in order for my script A to read the updated module B, in the process wiping my workspace and namespace clean. Is there a way to iterate quickly on importing B into A in a less...
1
2016-06-07T07:53:35Z
37,713,496
<p>I do this with <code>exec</code>.</p> <pre><code>exec(open("Path/To/Script/A.py").read()) </code></pre> <p>Also, Rodeo is undergoing rapid development so it's helpful if you put your version number in the question. I recommend checking out the latest version, 1.4.9, downloadable from the <a href="https://github.c...
2
2016-06-08T21:46:08Z
[ "python", "rodeo" ]
IndexError: list index out of range. Why do I get this error in the second function but not the first function?
37,673,589
<p>The function <strong>derivative</strong> computes the derivative of a polynomial; the degree of each entry needs to be reduced by one, each entry must be multiplied by the previous degree, and the term at degree[0] needs to be removed. </p> <p>This code</p> <pre><code>lst = [1,2,3] """This list represents the poly...
2
2016-06-07T07:54:20Z
37,673,740
<p>The line <code>i = degree*(i+1)</code> basically means squared index. You have array of length <code>i</code>, but trying to get element with index <code>i*i</code>.</p>
2
2016-06-07T08:02:14Z
[ "python" ]
IndexError: list index out of range. Why do I get this error in the second function but not the first function?
37,673,589
<p>The function <strong>derivative</strong> computes the derivative of a polynomial; the degree of each entry needs to be reduced by one, each entry must be multiplied by the previous degree, and the term at degree[0] needs to be removed. </p> <p>This code</p> <pre><code>lst = [1,2,3] """This list represents the poly...
2
2016-06-07T07:54:20Z
37,673,745
<p>the index <code>i</code> with its computation <code>i = degree*(i+1)</code> will grow equal or larger than <code>len(poly)</code> and <code>len(copy)</code> and hence out of range</p>
0
2016-06-07T08:02:30Z
[ "python" ]
IndexError: list index out of range. Why do I get this error in the second function but not the first function?
37,673,589
<p>The function <strong>derivative</strong> computes the derivative of a polynomial; the degree of each entry needs to be reduced by one, each entry must be multiplied by the previous degree, and the term at degree[0] needs to be removed. </p> <p>This code</p> <pre><code>lst = [1,2,3] """This list represents the poly...
2
2016-06-07T07:54:20Z
37,674,248
<p>Here is a quick hack I did :) Hope it meets your requirements, you just gotta be aware of lists length. </p> <pre><code>lst = [1,2,3] dlist=[] derivate=[] for i in range(len(lst)): #Here you multiply the coeficients by the power dlist.append(lst.__getitem__(i)*i) #print dlist for m in range(len(dlist)): #In ...
0
2016-06-07T08:29:12Z
[ "python" ]
Applying different functions to generator depending on its length
37,673,675
<h3>Problem</h3> <p>I have an iterator <code>spam</code> to which I want to apply the function <code>foo</code> if it generates few items, and <code>bar</code> otherwise. With other words, I wish to translate the following code for iterables to generators:</p> <pre><code>if len(spam) &lt;= max_size_for_foo: foo(s...
1
2016-06-07T07:58:40Z
37,673,922
<p>The easiest way is probably to define your generator in a function so that it can be reused:</p> <pre><code>def spam_func(): return (i for i in [1, 2, 3]) spam_length = sum(1 for _ in spam_func()) if spam_length &lt;= max_size_for_foo: foo(spam_func()) else: bar(spam_func()) </code></pre>
1
2016-06-07T08:13:03Z
[ "python", "generator" ]
Applying different functions to generator depending on its length
37,673,675
<h3>Problem</h3> <p>I have an iterator <code>spam</code> to which I want to apply the function <code>foo</code> if it generates few items, and <code>bar</code> otherwise. With other words, I wish to translate the following code for iterables to generators:</p> <pre><code>if len(spam) &lt;= max_size_for_foo: foo(s...
1
2016-06-07T07:58:40Z
37,674,222
<p>There is no such thing as generator length, because generator easily can be infinite:</p> <pre><code>def square(): a = 0 while True: yield a**2 a += 1 </code></pre> <p>One solution is <code>sum(1 for _ in gen)</code>. Another one may be wrap your generator with a class something like this:<...
-1
2016-06-07T08:27:38Z
[ "python", "generator" ]
String matching a pattern and not containing some words
37,673,681
<p>I'm looking for a regex which match words with a specific pattern (see below) but which doesn't contain one of three specific words</p> <p>The pattern is </p> <pre><code>[a-zA-Z0-9_~+-]{1,64} </code></pre> <p>and the words I don't want to be contained in the whole word are 'TEST', 'SPECIFIC1' and 'SPECIFIC2'</p> ...
1
2016-06-07T07:59:00Z
37,673,933
<p>If you surround the expression with <code>^</code> and <code>$</code> you can put the negative lookahead together with your character class to accomplish this.</p> <pre><code>^((?!(TEST|SPECIFIC1|SPECIFIC2))[a-zA-Z0-9_~+-]){1,64}$ </code></pre> <p><a href="https://regex101.com/r/hN9fO5/2" rel="nofollow">Here's</a>...
2
2016-06-07T08:13:37Z
[ "python", "regex" ]
Python - UDP client
37,673,742
<p>I am currently reading a Python <a href="https://www.nostarch.com/blackhatpython" rel="nofollow">book</a> and came across the following example:</p> <pre><code>import socket target_host = "127.0.0.1" target_port = 80 # create a socket object client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # send some da...
3
2016-06-07T08:02:24Z
37,674,211
<p>You need to run a server to listen on the port your sender sent to. there is a good explanation <a href="https://wiki.python.org/moin/UdpCommunication" rel="nofollow">here</a>.</p> <p>A nice example for you is (based on the above link):</p> <pre><code>import socket UDP_IP = "127.0.0.1" UDP_PORT = 80 sock = socke...
3
2016-06-07T08:27:12Z
[ "python", "sockets", "udp" ]
pandas dataframe add new column based on calulation on other column and avoid chained index
37,673,804
<p>I have a pandas dataframe and I need to add a new column, which would be based on calculation of specific columns,indicated by a column 'site'. I have found a way to do this with resort to numpy, but always it gives warning about chained index. I am sure there should be better solution, please help if you know.</p> ...
0
2016-06-07T08:05:35Z
37,675,312
<p>Well, i´m not too sure about your first quest but i think that this will help you.</p> <pre><code>import pandas as pd reader = pd.read_csv(path,engine='python') reader['new'] = reader['treasury.maturity.rate']+reader['bond.yield'] reader.to_csv('test.csv',index=False) </code></pre> <p>As you can see,you don´t ne...
0
2016-06-07T09:20:29Z
[ "python", "dataframe", "calculated-columns" ]
PyMongo: JSON Keys getting updated in mongo
37,673,812
<p>I am having difficulty updating nested json structure in mongo. I am using pymongo along with Mongoengine-Rest-framework.</p> <p>Since this particular json has dynamic structure and is heavily nested, I chose to use pymongo over mongo-engine ORM.</p> <p>The create, retrieve and delete operations faring fine. I wou...
3
2016-06-07T08:06:08Z
37,674,542
<p>First, change the object to update to this:</p> <pre><code>to_update = { "house_no": "5102", "street": "Some_street", "city": "some_city", "state": "some_state" } </code></pre> <p>And then use it to update the specific part of the document you want:</p> <pre><code>collection.update_one({_id: id}, { '$...
0
2016-06-07T08:43:10Z
[ "python", "json", "mongodb", "pymongo" ]
PyMongo: JSON Keys getting updated in mongo
37,673,812
<p>I am having difficulty updating nested json structure in mongo. I am using pymongo along with Mongoengine-Rest-framework.</p> <p>Since this particular json has dynamic structure and is heavily nested, I chose to use pymongo over mongo-engine ORM.</p> <p>The create, retrieve and delete operations faring fine. I wou...
3
2016-06-07T08:06:08Z
37,674,697
<p>use this to add address 2:</p> <blockquote> <p>collection.update({'_id': ObjectId(doc_id)}, {'$set': {'details.%s' % 'address2': address2}}, upsert=True)</p> </blockquote> <p><strong>Checkout complete code :</strong></p> <pre><code>import pymongo from bson.objectid import ObjectId data = {"name": "Some_name"...
0
2016-06-07T08:50:44Z
[ "python", "json", "mongodb", "pymongo" ]
Python: retrieving an enum variable from c++ using ctypes
37,673,814
<p>I have the following enum defined in C++ API:</p> <pre><code>typedef enum RESULT_ENUM { SUCCESS, ERR_INVALID_PORT_DEFINITION, ERR_TOO_MANY_SAMPLES, ERR_RECORDING_THREAD_ALREADY_RUNNING, ERR_RECORDING_WITHOUT_APPLY_SETTINGS, ... }RESULT; </code></pre> <p>I have a program in C++ that uses the...
0
2016-06-07T08:06:12Z
37,675,519
<p>The name to value mapping is not compiled into the binary.</p> <p>All ctypes code that needs the value of a enum hard codes that value in the python.</p> <p>If you wrap the C++ code in a python extension you can choose to expose the enum values as python symbols of your module.</p> <p>If you control the C++ imple...
0
2016-06-07T09:29:55Z
[ "python", "c++", "enums", "ctypes" ]
Extra protection layer for Django Rest Framework and OAuth2 Toolkit
37,673,882
<p>This is a follow up question for <a href="http://stackoverflow.com/questions/36383965/generating-single-access-token-with-django-oauth2-toolkit">this</a>.</p> <p>I'm using the latest <a href="https://github.com/evonove/django-oauth-toolkit" rel="nofollow">Django OAuth2 Toolkit (0.10.0)</a> with Python 2.7, Django 1...
1
2016-06-07T08:10:15Z
37,697,192
<p>This method of attack is called replay attack. <a href="https://www.youtube.com/watch?v=Ar97HbWLijU" rel="nofollow">This video by Professor Messer</a> explains replay attack.</p> <p>You can't really implement anything client side (browser) to overcome this because of the transparency of web browsers.</p> <p>What y...
1
2016-06-08T08:31:48Z
[ "python", "django", "oauth-2.0", "django-rest-framework", "django-oauth" ]
TypeError while template matching in opencv python
37,674,014
<p>Part of my code is :</p> <pre><code>import pyscreenshot as ImageGrab img=ImageGrab.grab() img = img.load() img = np.array(img) template = cv2.imread('s2_5.jpg',0) res = cv2.matchTemplate(img,template,cv2.TM_CCOEFF) </code></pre> <p>I'm getting the following error message:</p> <pre><code>Traceback (most recent cal...
1
2016-06-07T08:17:39Z
37,675,067
<p>You get that error because <code>img</code> and <code>template</code> are not of the same type, and more importantly, as the error messages says, <code>img</code>'s type is not supported by <a href="http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_template_matching/py_template_matchi...
1
2016-06-07T09:09:28Z
[ "python", "opencv", "numpy", "typeerror", "template-matching" ]
Python 2.7, requests, login into onlydomains.com site
37,674,166
<p>Since couple of days I try to login into <code>www.onlydomains.com</code> site to retrieve my domain lists into a script. I've already have something like this:</p> <pre><code>#!/usr/bin/env python # -*- coding: utf-8 -*- import requests, sys, re, whois from bs4 import BeautifulSoup def onlydomains(): with re...
1
2016-06-07T08:24:38Z
37,674,989
<p>I think that the best way to solve your problem will be with selenium(i remember do something like what you want to do with BS but i don´t remember how now)</p> <pre><code>from selenium import webdriver chromedriver = 'C:\\chromedriver.exe' browser = webdriver.Chrome(chromedriver) browser.get('http://www.example...
-1
2016-06-07T09:06:09Z
[ "python", "authentication", "beautifulsoup", "python-requests" ]
Python 2.7, requests, login into onlydomains.com site
37,674,166
<p>Since couple of days I try to login into <code>www.onlydomains.com</code> site to retrieve my domain lists into a script. I've already have something like this:</p> <pre><code>#!/usr/bin/env python # -*- coding: utf-8 -*- import requests, sys, re, whois from bs4 import BeautifulSoup def onlydomains(): with re...
1
2016-06-07T08:24:38Z
37,676,210
<p>If you look at what is returned from the post you can see a <code>window.location = some_url</code>:</p> <pre><code> &lt;script type="text/javascript"&gt; $(document).ready(function(){ setTimeout(function(){ window.location = 'https://onlydomains....
1
2016-06-07T10:00:25Z
[ "python", "authentication", "beautifulsoup", "python-requests" ]
OpenCV's Kalman Filter lacks Matricies
37,674,234
<p>I have OpenCv 2.4.8 installed and, for the most part, working on Python 2.7 (I'm on Ubuntu).</p> <p>Everything seems to be working fine with OpenCv. However, the following code</p> <pre><code>import numpy as np kalman = cv2.KalmanFilter(4,2) kalman.measurementMatrix = np.array([[1,0,0,0],[0,1,0,0]],np.float32) </c...
0
2016-06-07T08:28:15Z
37,674,680
<p>So, what it seems you need to do is get pyKalman rather than using the opencv one. From my quick search, all that is available from opencv is what you mention:</p> <pre><code>'KERNEL_SYMMETRICAL', 'KMEANS_PP_CENTERS', 'KMEANS_RANDOM_CENTERS', 'KMEANS_USE_INITIAL_LABELS', 'KNearest', 'KalmanFilter', 'KeyPoint', 'LEV...
0
2016-06-07T08:49:44Z
[ "python", "opencv", "kalman-filter" ]
What is the difference between 'SAME' and 'VALID' padding in tf.nn.max_pool of tensorflow?
37,674,306
<p>What is the difference between 'SAME' and 'VALID' padding in <code>tf.nn.max_pool</code> of <code>tensorflow</code>?</p> <p>In my opinion, 'VALID' means there will be no zero padding outside the edges when we do max pool. </p> <p>According to <a href="https://arxiv.org/pdf/1603.07285v1.pdf">A guide to convolution ...
7
2016-06-07T08:32:16Z
37,674,568
<p>The <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/nn.html" rel="nofollow">TensorFlow Convolution</a> example gives an overview about the difference between <code>SAME</code> and <code>VALID</code> :</p> <ul> <li><p>For the <code>SAME</code> padding, the output height and width are computed as:</...
4
2016-06-07T08:44:19Z
[ "python", "tensorflow", "deep-learning" ]
What is the difference between 'SAME' and 'VALID' padding in tf.nn.max_pool of tensorflow?
37,674,306
<p>What is the difference between 'SAME' and 'VALID' padding in <code>tf.nn.max_pool</code> of <code>tensorflow</code>?</p> <p>In my opinion, 'VALID' means there will be no zero padding outside the edges when we do max pool. </p> <p>According to <a href="https://arxiv.org/pdf/1603.07285v1.pdf">A guide to convolution ...
7
2016-06-07T08:32:16Z
37,675,359
<p>I'll give an example to make it clearer:</p> <ul> <li><code>x</code>: input image of shape [2, 3], 1 channel</li> <li><code>valid_pad</code>: max pool with 2x2 kernel, stride 2 and VALID padding.</li> <li><code>same_pad</code>: max pool with 2x2 kernel, stride 2 and SAME padding (this is the <strong>classic</strong...
6
2016-06-07T09:22:30Z
[ "python", "tensorflow", "deep-learning" ]
What is the difference between 'SAME' and 'VALID' padding in tf.nn.max_pool of tensorflow?
37,674,306
<p>What is the difference between 'SAME' and 'VALID' padding in <code>tf.nn.max_pool</code> of <code>tensorflow</code>?</p> <p>In my opinion, 'VALID' means there will be no zero padding outside the edges when we do max pool. </p> <p>According to <a href="https://arxiv.org/pdf/1603.07285v1.pdf">A guide to convolution ...
7
2016-06-07T08:32:16Z
39,371,113
<p>If you like ascii art:</p> <ul> <li><p><code>"VALID"</code> = without padding:</p> <pre><code> inputs: 1 2 3 4 5 6 7 8 9 10 11 (12 13) |________________| dropped |_________________| </code></pre></li> <li><p><code>"SAME"</code> = ...
6
2016-09-07T13:22:48Z
[ "python", "tensorflow", "deep-learning" ]
Read until an only partially known line - Python
37,674,605
<p>I need to get (parse) from a device its whole output.</p> <p>My solution was: 1) Determine how the last line of its output looks like </p> <p>2) Use the code below to read the output until the last line (which is a way around of saying - read the whole output)</p> <pre><code>last_line = "text of the last line" re...
0
2016-06-07T08:46:33Z
37,674,911
<p>You should read (again) the <code>re</code> chapter from the Python standard library manual.</p> <p>The correct usage is:</p> <pre><code>import re ... eof = re.compile(r'\s*\{\s*"diag":.*,\s*"status":.*\}') # compile the regex ... </code></pre> <p>The above expression uses <code>\s*</code> to allow for optional w...
0
2016-06-07T09:01:44Z
[ "python", "regex" ]
AWS Lambda/SNS Publish ignore invalid endpoints
37,674,606
<p>i'm sending apple push notifications via AWS SNS via Lambda with Boto3 and Python. </p> <pre><code>from __future__ import print_function import boto3 def lambda_handler(event, context): client = boto3.client('sns') for record in event['Records']: if record['eventName'] == 'INSERT': rec...
0
2016-06-07T08:46:37Z
37,678,717
<p>Aws lamdba on failure retries the function till the event expires from the stream. </p> <p>In your case since the exception on the 2nd endpoint is not handled, the retry mechanism ensures the reexecution of post to the first endpoint.</p> <p>If you handle the exception and ensure the function successfully ends eve...
2
2016-06-07T11:56:38Z
[ "python", "amazon-web-services", "aws-lambda", "amazon-sns", "boto3" ]
Approach behind having everything as an object in Python
37,674,728
<p>Why is everything in Python, an object? According to what I read, everything including functions is an object. It's not the same in other languages. So what prompted this shift of approach, to treat everything including, even functions, as objects.</p>
2
2016-06-07T08:52:14Z
37,675,343
<p>The power of everything being an object is that you can define behavior for each object. For example a function being an object gives you an easy way to access the docs of the function for introspection.</p> <pre><code>print( function.__doc__ ) </code></pre> <p>The alternative would be to provide a library of func...
-1
2016-06-07T09:21:44Z
[ "python" ]
Approach behind having everything as an object in Python
37,674,728
<p>Why is everything in Python, an object? According to what I read, everything including functions is an object. It's not the same in other languages. So what prompted this shift of approach, to treat everything including, even functions, as objects.</p>
2
2016-06-07T08:52:14Z
37,675,428
<p><em><b>why is everything in Python, an object?</b></em></p> <p>Python (unlike other languages) is a truly Object Orient language (aka OOP) when everything is an object, it becomes easier to search, manipulate or access things. (But everything comes at the cost of speed)</p> <p><em>what <b>prompted</b> this shift o...
-1
2016-06-07T09:25:37Z
[ "python" ]