background preloader

Python

Facebook Twitter

Performance - fixing a Python progress bar in Command Prompt. Console (text) progress indicator class. Progress bar class. Python: Lambda Functions. Python supports the creation of anonymous functions (i.e. functions that are not bound to a name) at runtime, using a construct called "lambda". This is not exactly the same as lambda in functional programming languages, but it is a very powerful concept that's well integrated into Python and is often used in conjunction with typical functional concepts like filter(), map() and reduce().

This piece of code shows the difference between a normal function definition ("f") and a lambda function ("g"): As you can see, f() and g() do exactly the same and can be used in the same ways. Note that the lambda definition does not include a "return" statement -- it always contains an expression which is returned. The following code fragments demonstrate the use of lambda functions. The above code defines a function "make_inrementor" that creates an anonymous function on the fly and returns it. The following takes this a step further. In the second example, map() is used to convert our list. Python Tutorial: Lambda Operator, filter, reduce and map. Lambda Operator Some like it, others hate it and many are afraid of the lambda operator. We are confident that you will like it, when you have finished with this chapter of our tutorial. If not, you can learn all about "List Comprehensions", Guido van Rossums preferred way to do it, because he doesn't like Lambda, map, filter and reduce either. becasu The lambda operator or lambda function is a way to create small anonymous functions, i.e. functions without a name.

These functions are throw-away functions, i.e. they are just needed where they have been created. Lambda functions are mainly used in combination with the functions filter(), map() and reduce(). The lambda feature was added to Python due to the demand from Lisp programmers. The general syntax of a lambda function is quite simple: lambda argument_list: expression The argument list consists of a comma separated list of arguments and the expression is an arithmetic expression using these arguments. The map() Function Filtering. NumPy for MATLAB users – Mathesaurus. Help Searching available documentation Using interactively Operators Arithmetic operators Relational operators Logical operators root and logarithm Round off Mathematical constants Missing values; IEEE-754 floating point status flags Complex numbers Trigonometry Generate random numbers Vectors Sequences Concatenation (vectors) Repeating Miss those elements out Maximum and minimum Vector multiplication Matrices Concatenation (matrices); rbind and cbind Array creation Reshape and flatten matrices Shared data (slicing) Indexing and accessing elements (Python: slicing) Assignment Transpose and inverse Sum Sorting Matrix manipulation Equivalents to "size" Matrix- and elementwise- multiplication Find; conditional indexing Multi-way arrays File input and output Plotting Basic x-y plots Axes and titles Log plots Filled plots and bar plots Functions Polar plots Histogram plots 3d data Contour and image plots Perspective plots of surfaces over the x-y plane Scatter (cloud) plots Save plot to a graphics file Data analysis Set membership operators.

Plotting data on a map (Example Gallery) — Basemap Matplotlib Toolkit 1.0.2 documentation. Following are a series of examples that illustrate how to use Basemap instance methods to plot your data on a map. More examples are included in the examples directory of the basemap source distribution. There are a number of Basemap instance methods for plotting data: contour(): draw contour lines.contourf(): draw filled contours.imshow(): draw an image.pcolor(): draw a pseudocolor plot.pcolormesh(): draw a pseudocolor plot (faster version for regular meshes).plot(): draw lines and/or markers.scatter(): draw points with markers.quiver(): draw vectors.barbs(): draw wind barbs.drawgreatcircle(): draw a great circle.

Many of these instances methods simply forward to the corresponding matplotlib Axes instance method, with some extra pre/post processing and argument checking. You can also plot on the map directly with the matplotlib pyplot interface, or the OO api, using the Axes instance associated with the Basemap. Plot contour lines on a basemap (Source code) Plot precip with filled contours.

Python