Today we've issued the 2.1.1 bugfix release.
The release package and checksums are available from our downloads page, as well as from the Python Package Index. The PGP key ID used for this release is Carlton Gibson: E17DF5C82B4F9D00.
Today we've issued the 2.1.1 bugfix release.
The release package and checksums are available from our downloads page, as well as from the Python Package Index. The PGP key ID used for this release is Carlton Gibson: E17DF5C82B4F9D00.
We are pleased to announce the second batch of cut videos from EuroPython 2018 in Edinburgh, Scotland, UK.
EuroPython 2018 YouTube Playlist
In this batch, we have included all videos for Thursday, July 26 2018, the second conference day.
Next week we will publish videos for the final conference day. In total, we will have more than 130 videos available for you to watch.
All EuroPython videos, including the ones from previous conferences, are available on our EuroPython YouTube Channel.
Enjoy,
–
EuroPython 2018 Team
https://ep2018.europython.eu/
https://www.europython-society.org/
Suppose you want to multiply two 2 × 2 matrices together. How many multiplication operations does it take? Apparently 8, and yet in 1969 Volker Strassen discovered that he could do it with 7 multiplications.
The obvious way to multiply two n× n matrices takes n³ operations: each entry in the product is the inner product of a row from the first matrix and a column from the second matrix. That amounts to n² inner products, each requiring n multiplications.
You can multiply two square matrices with O(n³) operations with the method described above, and it must take at least O(n²) operations because the product depends on all of the 2n² entries of the two matrices. Strassen’s result suggests that the optimal algorithm for multiplying matrices takes O(nk) operations for some k between 2 and 3. By applying Strassen’s algorithm recursively to larger matrices you can get k = log2 7 = 2.807.
The best known value at the moment is k = 2.3728639.
Yesterday the blog Gödel’s Lost Letter and P = NP posted an article Limits on Matrix Multiplication where they report on recent developments for finding the smallest value of k. A new paper doesn’t report a new value of k, but a limit on what current approaches to the problem can prove. Maybe k can equal 2, but there is a lower bound, strictly bigger than 2, on how small current approaches can go.
When I first heard of Strassen’s method, I was told it’s a curious but impractical result. Strassen saved one multiplication at the expense of introducing several more addition operations.
According to the Wikipedia article on matrix multiplication, recursively applying Strassen’s method can save time for n> 100. But there’s more to consider than counting operations. Strassen’s method, and subsequent algorithms, are more complicated. They may not be more efficient in practice even if they use fewer operations because the operations may not vectorize well.
Wikipedia reports that Strassen’s algorithm is not as numerically stable as the traditional approach, but this doesn’t matter when working over finite fields where arithmetic is exact.
Let’s look at just what Strassen’s method does. We want to find the product of two matrices:
I started to spell out Strassen’s method in LaTeX equations, but I thought it would be much better to write it out in code so I can be sure that I didn’t make a mistake.
The following Python code randomly fills in the values of the a’s and b’s, computes the c’s using the conventional method, then asserts that you can find these values from the q’s computed from Strassen’s method. Note there is one multiplication in each of the seven q’s.
from random import randint # Fill matrices with random integer values a11 = randint(0, 9) a12 = randint(0, 9) a21 = randint(0, 9) a22 = randint(0, 9) b11 = randint(0, 9) b12 = randint(0, 9) b21 = randint(0, 9) b22 = randint(0, 9) # Traditional matrix multiplication c11 = a11*b11 + a12*b21 c12 = a11*b12 + a12*b22 c21 = a21*b11 + a22*b21 c22 = a21*b12 + a22*b22 # Strassen's method q1 = (a11 + a22)*(b11 + b22) q2 = (a21 + a22)*b11 q3 = a11*(b12 - b22) q4 = a22 * (-b11 + b21) q5 = (a11 + a12)*b22 q6 = (-a11 + a21)*(b11 + b12) q7 = (a12 - a22)*(b21 + b22) assert(c11 == q1 + q4 - q5 + q7) assert(c21 == q2 + q4) assert(c12 == q3 + q5) assert(c22 == q1 + q3 - q2 + q6)
Since Strassen’s method takes more operations than the traditional method for multiplying 2 × 2 matrices, how can it take fewer operations than the traditional method for multiplying large matrices?
When you apply Strassen’s method to a matrix partitioned into submatrices, its multiplications become matrix multiplications, and its additions become matrix additions. These operations are O(n2.807) and O(n2) respectively, so saving multiplications at the cost of more additions is a win.
What does software development look like? Here’s a short video / visualisation of the creation of Mu as told via the interactions, interventions and changes by developers to Mu’s own source code hosted on GitHub.
What exactly are you looking at?
I used the gource
tool turn the commit history of Mu’s
development on GitHub into a video. I added some Creative Commons licensed music
and the results look and sound quite effective. What I really like is how the
video reflects the wide variety of people and types of contributions made to
the source code for Mu. Together, we’re continuing to build the best editor
we possibly can for beginner programmers and those who support them.
By Tom Augspurger This work is supported byAnaconda, Inc. This post describes a recent improvement made to TPOT. TPOT is an automated machine learning library for Python. It does some feature engineering and hyper-parameter optimization for you. TPOT uses genetic algorithms to evaluate which models are performing well and how to choose new models to try out in the next …
Read more →
The post Distributed Auto-ML with TPOT with Dask appeared first on Anaconda.
Artist in residence. |
According to python.org art does not exist |
They say people come to Python for the language and stay for the community. We couldn’t agree more! You mean the world to us, and we are honored to have you as a reader!
Today, we’re celebrating reaching 1,000,000 monthly page views at realpython.com.
We are so thankful to you and the rest of the Python community for helping us reach this milestone. More than one million views a month is a mind-blowing number to us—and it means much more to us than the increase in server fees 😉
Reaching this milestone shows us that we are providing you with the resources you need to grow as a developer, and that fills us with joy.
We write comprehensive tutorials twice a week because we care about teaching. We are all passionate Pythonistas, and we want everyone to know that the Python community can be their home, too.
To show our appreciation, we have decided to give away some of our paid Python courses and books as a big thank you to the community for your continued support.
The contest will run from September 1st to September 30th. At the end of the contest, a random entrant will be picked to receive the Grand Prize. Each week, throughout the contest, we will randomly pick winners for smaller prizes.
To enter the contest, you can do any of the following:
Now for the part you’ve been waiting for—the prizes!
Here’s what we are giving away each week:
Week 1:Managing Python Dependencies Course(worth $49)
Week 2:Python Tricks eBook + Videos Bundle(worth $29)
Week 3:The Pythonic Wallpapers Pack(worth $9.99)
Week 4:All three Real Python Courses(worth $60)
The Grand Prize at the end of the month includes the following:
This adds up to a total value of over $200.
It’s easy! Just click the link below:
Join the Real Python contest for a chance to win »
From all of us at Real Python, thank you! We truly appreciate all the shares, comments, and feedback you have taken the time to provide. It helps us to continually learn as teachers and ensures we are providing the best tutorials and content we can to help you grow as a developer.
Here’s the contest link again:
Enter for your chance to walk away with over $200 of prizes »
[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]
Perhaps you were wondering - why on CheckiO almost all of the missions are scattered and not related in any way? The thing is, we were actually looking for a fascinating story and, finally, we are ready to present it to you. Throughout the entire month of September, on the new Escher’s Island will appear new tasks, which are part of a long story about finding treasures and overcoming difficulties.
When I set up xrdp
on Raspbian Jessie a while ago, the keyboard layout appeared to be wrong - commonly used keys seemed to be returning US keycodes rather than UK ones. I found this post very helpful in resolving the problem, but it didn't quite fit the bill when I tried to do the same with a Raspbian Stretch instance recently. Here's what I did on Raspbian Stretch to set up xrdp
to provide the correct keycodes.
First, I checked the keboard layout was as expected:
$ cat /etc/default/keyboard | grep LAYOUT
XKBLAYOUT="gb"
Then, I generated a keyboard mapping file using xrdp-genkeymap
:
$ xrdp-genkeymap km-00000809.ini
This filename follows the current filename convention (under Jessie, it was km-0809.ini
). I then copied this file into the xrdp
configuration files directory:
$ sudo cp km-00000809.ini /etc/xrdp
The next step was to edit the file /etc/xrdp/xrdp_keyboard.ini
, which appears to be new in Raspbian Stretch. Here are the lines I added, in an excerpt from the file:
[default_rdp_layouts]
rdp_layout_us=0x00000409
rdp_layout_de=0x00000407
< ... lines omitted ... >
rdp_layout_br=0x00000416
rdp_layout_pl=0x00000415
rdp_layout_gb=0x00000809
; <rdp layout name> = <X11 keyboard layout value>
[default_layouts_map]
rdp_layout_us=us
rdp_layout_de=de
< ... lines omitted ... >
rdp_layout_br=br(abnt2)
rdp_layout_pl=pl
rdp_layout_gb=gb
In each case, I added the rdp_layout_gb=
lines. The final step was to restart the xrdp
service:
$ sudo service xrdp restart
On reconnecting, I found that the keycodes were as they should have been, and I had access to the £@'~#\|
keys again in their expected places on the keyboard.
For DSP, mathematics is a fundamental tool to understand the different techniques. Hence, I'm also interested in different aspects of mathematics. And what aspect could be more "pure" mathematics than number theory and prime numbers? In this regard, to at least understand the still unsolved Riemann Hypothesis, where a price money of 1,000,000 will be given to the one who proves or disproves it, has been bothering me for quite some time. Despite a lot of material about the hypothesis being online, it was the book of Barry Mazur and William Stein entitled "Prime Numbers and the Riemann Hypothesis" which provided me at least a superficial understanding of it.
The nice thing about this book is its very simple approach, requiring not more than high school math. Each page contains graphs and illustrations of the analyzed functions and hence makes it quite easy to follow. Accordingly, it's a very nice book to get to know a bit about the Riemann Hypothesis (RH). However, admittedly, the mathematical treatment is intentionally quite superficial.
In this notebook, I do not want to directly talk about the RH. Instead, the notebook arose when I tried to replicate some calculations from the ...
Submitted by @clamytoe.
“How to find stuff in Git” by @tygertechttps://t.co/koyvqy10j1
— Christopher Ross (@crossphd) August 31, 2018
Submitted by @dgjustice.
All those who use #Traefikhttps://t.co/yKDNf5iI0v
— Avishay (@AvishaySaban) August 30, 2018
“A Simple Tutorial on How to document your #Python Project using #Sphinx and #Rinohtype” by Rich Yap https://t.co/Pn56gqrA4c
— Pybites (@pybites) August 23, 2018
RT @ThePSF: Looking for a job doing what you love with Python? Check out https://t.co/HfrDboAVbd - there are currently over 170 jobs on the…
— Brett Cannon (@brettsky) August 29, 2018
📰 Advanced Git Tips for 🐍Python Developers https://t.co/ovWfaPcd2W
— Real Python (@realpython) August 26, 2018
Submitted by @Erik.
An A-Z of useful Python tricks https://t.co/5ouBpmSGff
— freeCodeCamp.org (@freeCodeCamp) August 29, 2018
RT @ThePSF: Basic membership in the Python Software Foundation is free. Join here: https://t.co/W2H2ShVTDr
— Betsy Waliszewski (@betswaliszewski) September 01, 2018
Last week marked the end of our biggest summer ever! THANK YOU to everyone who supported the 50 Kode With Klossy ca… https://t.co/Sdubz2cFvl
— Kode With Klossy (@kodewithklossy) August 26, 2018
Short overview of what it's like to write a #python#asyncio socket server from @pgjones - An Asyncio socket tutori… https://t.co/dIC9Hf59Xl
— Cristian Medina (@tryexceptpass) August 27, 2018
RT @Cindybarriento5: Scanning for additional resources on understanding classes a bit better and found this awesome article detailing #pyth…
— Jason Wattier (@jmwatt3) August 31, 2018
Here's @talkpython#175: Teaching Python to network engineers with @hfpreston from @CiscoDevNethttps://t.co/WMSDw08k9z#DevNet#NetDevOps
— Talk Python Podcast (@TalkPython) September 01, 2018
RT @iamtrask: This is still one of the most impressive Deep Learning demos of 2018 - huge opportunity for new open-source Web Development t…
— TestDriven.io (@testdrivenio) August 31, 2018
RT @sam2code: -- What's the best advice you've ever received? -- "When given a choice, choose the thing that scares you a little. If it's…
— Programming Wisdom (@CodeWisdom) September 01, 2018
RT @randal_olson: This looks big: pyodide, the scientific #Python stack compiled to WebAssembly. Run Python *locally* in your browser, inte…
— Jake VanderPlas (@jakevdp) August 25, 2018
RT @arongriffis: Working on a new Bash book. So far: Intro: You chose the wrong tool. Ch 1: Have you considered Python? Ch 2: Try calling P…
— Ned Batchelder (@nedbat) August 24, 2018
>>>frompybitesimportBob,JulianKeepCalmandCodeinPython!
How do you write tests for things that aren’t that easy to write tests for?
That question is a possibly terrible summary of a question sent to me by a listener. And to help me start answering that question, I asked a friend of mine to help, Antony Shaw.
Of course, different types of applications have different test strategies, so there’s not a universal answer. But I know some of you out there have experience and expertise around how to tackle this problem.
Listen to the discussion Anthony and I have about it, and let me know if you have some techniques or tips to add.
Special Guest: Anthony Shaw.
Sponsored By:
<p>How do you write tests for things that aren’t that easy to write tests for?</p> <p>That question is a possibly terrible summary of a question sent to me by a listener. And to help me start answering that question, I asked a friend of mine to help, Antony Shaw.</p> <p>Of course, different types of applications have different test strategies, so there’s not a universal answer. But I know some of you out there have experience and expertise around how to tackle this problem.</p> <p>Listen to the discussion Anthony and I have about it, and let me know if you have some techniques or tips to add. </p><p>Special Guest: Anthony Shaw.</p><p>Sponsored By:</p><ul><li><a rel="nofollow" href="https://www.patreon.com/testpodcast">Patreon Supporters</a>: <a rel="nofollow" href="https://www.patreon.com/testpodcast">Help support the show with as little as $1 per month. Funds help pay for expenses associated with the show.</a></li></ul><p><a rel="payment" href="https://www.patreon.com/testpodcast">Support Test and Code</a></p>In this tutorial, We'll introduce React basics to Django developers. You can use React to build UIs using re-usable components which allow maximum reusability and a virtual DOM that provides better performance.
In this tutorial, we'll learn how to include React in a Django template and learn about the basics of React such as components, state and props.
But what's virtual DOM? This is the definition from the official React website
The virtual DOM (VDOM) is a programming concept where an ideal, or “virtual”, representation of a UI is kept in memory and synced with the “real” DOM by a library such as ReactDOM. This process is called reconciliation.
React is nowadays-2018-the most popular front-end library for building User Interfaces. Throughout this tutorial we'll go through a basic understanding of React.js by creating a React application from scratch and step by step. We will focus on the core features of React. After getting the core concepts, you can dive into more learning more comfortably.
By following this tutorial, you'll learn:
How to get started with React using a <script>
tag;
How to include React in a Django template;
What's a React component;
How to create React components;
How to use the ReactDOM
library to mount your React app into the DOM;
How to handle data in React;
The difference between props and state in React;
How to use props;
How to use state;
How to mutate or update state in React etc.
React provides a set of modern features such as:
A component based architecture;
Reusable components;
Stateful and stateless components;
And virtual dom.
Since we are getting started with React, we are not going to use complicated tools such as create-react-app
(In fact this tool was created to make creating React applications less complex without worrying about Webpack and complex front-end tooling), instead we'll use a simple setup i.e the old way of using libraries in front-end web development.
Start by creating a basic HTML page:
<html><head><title>React Tutorial</title></head><body></body></html>
Now use the <script>
tag to include React
and ReactDOM
libraries. In the <head>
of your HTML page, add:
<script src="https://unpkg.com/react@15/dist/react.min.js"></script><script src="https://unpkg.com/react-dom@15/dist/react-dom.min.js"></script>
You also need to include Babel:
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
We are using the unpkg.com
service which allows us to import NPM modules as normal JavaScript scripts without using npm and related modern front-end tools to install and use the dependencies.
Since React makes use of modern JavaScript features, we use Babel which is transpiler that transpiles the ES6 features to JavaScript features that can be interprited by most existing browsers.
We also use Babel for transforming JSX templates (used by React to include HTML in JavaScript) into JavaScript.
We are loading React from a <script>
tag, you can also use modern tools like npm and the import/require system when building complex apps.
Next, we need to add a root <div>
where we'll mount our React application.
Inside the <body>
element, add the following HTML:
<divid="root"></div>
Also, inside the <body>
tag, add the following <script>
where we're going to add the React code:
<scripttype="text/babel">/* React code */</script>
At this step, you can install an http server so you can run the example on your browser or simply use codepen.
In this section, we'll see how to include React in Django templates. Django has a powerful template system that makes use of inheritance to reduce repetition and augment code reuse so let's start by creating the base.html
template inside the templates
folder and add the following HTML:
{% load static %}
<!doctype html><html><head><metacharset="utf-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><title>Django & React Tutorial</title><metacontent="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"name="viewport"></head><script src="https://unpkg.com/react@15/dist/react.min.js"></script><script src="https://unpkg.com/react-dom@15/dist/react-dom.min.js"></script><script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script><body><noscript>You need to enable JavaScript to continue with this application.</noscript><divid="root"></div>
{% block inner %}
{% endblock %}
</body></html>
Create an index.html
template that extends the base.html
template and add the following content:
{% extends "base.html" %}
{% block inner %}
<script type="text/babel">/* React code here */</script>
{% endblock %}
In React, you build your UI as a hierarchy of components. A component controls a part of the UI and It's simply a JavaScript/ES6 class that extends the base React.Component
. For example, this is a simple HelloWorld
component:
classHelloWorldextendsReact.Component{render(){return<h1>HelloWorld!</h1>;
}}
The component simply renders a <h1>Hello World!</h1>
. We use the render()
method which is provided by the parent React.Component
. The render()
method should return what your component needs to render on the screen.
In React, you can use different types of components such as parent and child components. You will also make use of smart and dump components. A smart component maintains state while a dump component doesn't maintain any state.
Components have many benefits. The most important benefit for a developer is code-reuse i.e you can reuse your components in the same app or throughout multiple apps.
Now that we have a basic React component that renders something on the screen and a simple HTML page, we need to mount the simple React application in the HTML body of our page. For this matter, we need to use the ReactDOM
library.
Before the closing </body>
tag, add the following code within a <script>
tag:
<script>ReactDOM.render(<HelloWorld/>,document.getElementById("root"));</script>
We use the render()
method to mount the our top-level and only component into the root <div>
which we grab using the document.getElementById("root")
method.
This will be enough to mount our React component. You should now see a Hello World on the screen.
You can make use of data in React using two forms: props
and state
.
Props are used to communicate or pass data between components and they are external to the component while state is used to maintain the internal state of a component.
A React component can change its internal state directly but not the props.
Props allow you to pass data to a component which allows for maximum re-usability of the component.
Let's, for example change our previous HelloWorld component to be more dynamic by rendering a message that's passed via a prop instead of always rendering Hello World.
We can pass a message prop to the component using the following syntax:
<HelloWorldmessage="Hello React"/>
The prop is called message, you can use any meaningful name for your prop. The message prop takes a Hello React value.
Now, we need to change the component to handle the prop:
classHelloWorldextendsReact.Component{render(){return<h1>{this.props.message}</h1>;
}}
We access the props in our component by using the this.props
object. Since this is JavaScript code we include it inside curly braces which tells JSX to interpret and render the result.
As you can see this allows us to use the component to render different messages instead of just the Hello World message.
A component in React can maintain its own internal state using a state object. The component that maintains a state is called a smart component.
Let's now add state to our previous component:
classHelloWorldextendsReact.Component{constructor(){super();this.state={message:"Hello React!"};}render(){return<p>{this.state.message}</p>;
}}
In the constructor of the component, we simply assign a JavaScript object to this.state
to initialize it.
The message is now a part of the internal state of the component.
We can access the state using this.state
.
To mutate or change state in your React component, you simply need to use the this.setState()
method. For example:
this.setState({message:"Hello Again"});
In this tutorial, we've quickly gone through the basic concepts of React.