The Python Book | |||
Latest All — By Topic 2019 2016 2015 2014 Topics:
angle argsort beautifulsoup binary bisect clean collinear covariance cut_paste_cli datafaking dataframe datetime day_of_week delta_time df2sql doctest exif floodfill fold format frequency gaussian geocode httpserver is join legend linalg links matrix max namedtuple null numpy oo osm packaging pandas plot point range regex repeat reverse sample_words shortcut shorties sort stemming strip_html stripaccent tools visualization zen zip Tags:
3d aggregation angle archive argsort atan beautifulsoup binary bisect class clean collinear colsum comprehension count covariance csv cut_paste_cli datafaking dataframe datetime day_of_week delta_time deltatime df2sql distance doctest dotproduct dropnull exif file floodfill fold format formula frequency function garmin gaussian geocode geojson gps groupby html httpserver insert ipython is join kfold legend linalg links magic matrix max min namedtuple none null numpy onehot oo osm outer_product packaging pandas plot point quickies range read_data regex repeat reverse sample sample_data sample_words shortcut shorties sort split sqlite stack stemming string strip_html stripaccent tools track tuple visualization zen zip zipfile |
linalg
20150206
Linear Algebra MOOCOdds of letters in scrable:
Use // to find the remainderRemainder using modulo: Remainder using // : InfinityInfinity: float('infinity') : SetTest membership with 'in' and 'not in'. Note the difference between set (curly braces!) and tuple:
Union of sets: use the bar operator Intersection of sets: use the ampersand operator Empty set: is not Add / remove elements with .add() and .remove(). Add another set with .update()
Intersect with another set:
Bind another variable to the same set: (any changes to s or t are visible to the other)
Make a complete copy:
Set comprehension:
.. union of 2 sets combined with if (the if clause can be considered a filter) ..
Double comprehension : iterate over the Cartesian product of two sets:
Compare to a list, which will return 2 more elements ( the 4 and the 6) :
Or producing tuples:
The factors of n:
Or use it in a loop:
Lists
Skip elements in a slice: use the colon separate triple a:b:c notation
List of lists and comprehension:
Tuples
Unpacking in a comprehension:
Converting list/set/tupleUse constructors: Note about range: a range represents a sequence, but it is not a list. Either iterate through the range or use set() or list() to turn it into a set or list. Note about zip: it does not return a list, an 'iterator of tuples'. Dictionary comprehensions
Iterate over the k,v pairs with items(), producing tuples:
Modules
While debugging it may be easier to use 'reload' (from package imp) to reload your module VariousThe enumerate function.
|