Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
A Benchmark of matrix multiplication between C and Python

#Motivation

After a Python convention in my city (Python Brasil) me, a unqualified newbie and a friend of mine from the comp. sci. academia discussed with a few colleagues about the potential advantages of python, including its application in the scientific field for numerical applications.
One of their arguments was that runtime optimization provided by pypy offered a significant advantage over C.

Well without further ado, here are the source codes for each language.

#Source Codes

**python w/ numpy**

#! /usr/bin/python

import sys
import numpy as np
import time

n = int(sys.argv[1])
m1_file = sys.argv[2]
m2_file = sys.argv[3]

m1 = np.loadtxt(m1_file)
m2 = np.loadtxt(m2_file)
m3 = np.zeros(m1.shape)

start = time.time()
np.matmul(m1, m2, m3)
end = time.time()

print m3

print 'Time:', (end - start) * 1000.0


**python**

#! /usr/bin/python2

import sys
import time

n = int(sys.argv[1])
m1_file = sys.argv[2]
m2_file = sys.argv[3]

def readm(filename):
f = open(filename, 'r')
d = f.read()
mat = [[float(i) for i in row] for row in [s.split(' ')[0:n] for s in d.split('\n')[0:n]]]
return mat

m1 = readm(m1_file)
m2 = readm(m2_file)
m3 = [[0 for i in range(n)] for j in range(n)]

start = time.time();
for i in range(n):
for j in range(n):
for k in range(n):
m3[i][j] += (m1[i][k] * m2[k][j])
end = time.time();

for i in range(n):
for j in range(n):
print m3[i][j],
print ''

print 'Time:', (end - start) * 1000.0

**C**

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#ifdef ARRAY
void readm(FILE* f, int n, double* m) {
#endif
#ifdef MATRIX
void readm(FILE* f, int n, double** m) {
#endif
int i, j;
#ifdef ARRAY
for (i = 0; i < n * n; ++i)
fscanf(f, "%lf", &m[i]);
#endif

#ifdef MATRIX
for (i = 0; i < n; ++i)
for (j = 0; j < n; ++j)
fscanf(f, "%lf", &m[i][j]);
#endif
}

int main(int argc, char** argv) {
int i, j, k;
double start, end;
struct timeval tv_start, tv_end;

int n = atoi(argv[1]);
FILE* f1 = fopen(argv[2], "r");
FILE* f2 = fopen(argv[3], "r");

#ifdef ARRAY
double* m1 = (double*) malloc(sizeof(double) * n * n);
double* m2 = (double*) malloc(sizeof(double) * n * n);
double* m3 = (double*) malloc(sizeof(double) * n * n);

for (i = 0; i < n * n; ++i) m3[i] = 0;

readm(f1, n, m1);
readm(f2, n, m2);

gettimeofday(&tv_start, NULL);
for (i = 0; i < n; ++i)
for (j = 0; j < n; ++j)
for (k = 0; k < n; ++k)
m3[(i * n) + j] += (m1[(i * n) + k] * m2[(k * n) + j]);
gettimeofday(&tv_end, NULL);


for (i = 0; i < n; ++i) {
for (j = 0; j < n; ++j)
fprintf(stderr, "%lf ", m3[(i * n) + j]);
fprintf(stderr, "\n");
}
#endif

#ifdef MATRIX
double** m1 = (double**) malloc(sizeof(double*) * n);
double** m2 = (double**) malloc(sizeof(double*) * n);
double** m3 = (double**) malloc(sizeof(double*) * n);

for (i = 0; i < n; ++i) {
m1[i] = (double*) malloc(sizeof(double) * n);
m2[i] = (double*) malloc(sizeof(double) * n);
m3[i] = (double*) malloc(sizeof(double) * n);
}

for (i = 0; i < n; ++i)
for (j = 0; j < n; ++j)
m3[i][j] = 0;

readm(f1, n, m1);
readm(f2, n, m2);

gettimeofday(&tv_start, NULL);
for (i = 0; i < n; ++i)
for (j = 0; j < n; ++j)
for (k = 0; k < n; ++k)
m3[i][j] += (m1[i][k] * m2[k][j]);
gettimeofday(&tv_end, NUL
Fast-Docker: Docker Tutorial, Cheatsheet, Sample Usage Scenarios (HowTos)

Containerize your Flask Application with Docker! Docker can be used to create portable applications and independent environments. Using Docker Containers, applications can easily run on Cloud Environments (AWS, GCP, Azure).

This repo aims to cover Docker details (Dockerfile, Image, Container, Commands, Volumes, Docker-Compose, Networks, Swarm, Stack) fastly, and possible example usage scenarios (HowTo: Applications) in a nutshell. Possible usage scenarios are aimed to update over time.

**Tutorial Link:** [**https://github.com/omerbsezer/Fast-Docker**](https://github.com/omerbsezer/Fast-Docker)

Quick Look (HowTo)

* [App: Python App - Flask: Creating First Docker Image and Container using Docker File](https://github.com/omerbsezer/Fast-Docker/blob/main/FirstImageFirstContainer.md)
* [App: Binding Volume to the Different Containers](https://github.com/omerbsezer/Fast-Docker/blob/main/DockerVolume.md)
* [App: Binding Mount to the Container](https://github.com/omerbsezer/Fast-Docker/blob/main/DockerVolume.md#app_mount)
* [App: Docker-Compose File - Creating 2 Different Containers: WordPress Container depends on MySql Container](https://github.com/omerbsezer/Fast-Docker/blob/main/DockerCompose.md)
* [App: Creating Docker Swarm Cluster With 5 PCs using PlayWithDocker : 3 x WordPress Containers and 1 x MySql Container using Docker-Compose File](https://github.com/omerbsezer/Fast-Docker/blob/main/DockerStackService.md)
* [App: Running Docker Free Local Registry, Tagging Image, Pushing Image to the Local Registry, Pulling Image From Local Registry and Deleting Images from Local Registry](https://github.com/omerbsezer/Fast-Docker/blob/main/DockerLocalRegistry.md)
* [App: Transferring Content between Host PC and Docker Container](https://github.com/omerbsezer/Fast-Docker/blob/main/DockerTransferringContent.md)
* [Docker Commands Cheatsheet](https://github.com/omerbsezer/Fast-Docker/blob/main/DockerCommandCheatSheet.md)

Table of Contents

* [Motivation](https://github.com/omerbsezer/Fast-Docker#motivation)
* [Needs](https://github.com/omerbsezer/Fast-Docker#needs)
* [Benefits](https://github.com/omerbsezer/Fast-Docker#benefits)
* [Problems Docker does not solve](https://github.com/omerbsezer/Fast-Docker#problems)
* [What is Docker?](https://github.com/omerbsezer/Fast-Docker#whatIsDocker)
* [Architecture](https://github.com/omerbsezer/Fast-Docker#architecture)
* [Installation](https://github.com/omerbsezer/Fast-Docker#installation)


/r/flask
https://redd.it/mm6ijb
Fast-Docker: Docker Tutorial, Cheatsheet, Sample Usage Scenarios (HowTos)

Containerize your Django Application with Docker! Docker can be used to create portable applications and independent environments. Using Docker Containers, applications can easily run on Cloud Environments (AWS, GCP, Azure).

This repo aims to cover Docker details (Dockerfile, Image, Container, Commands, Volumes, Docker-Compose, Networks, Swarm, Stack) fastly, and possible example usage scenarios (HowTo: Applications) in a nutshell. Possible usage scenarios are aimed to update over time.

**Tutorial Link:** [**https://github.com/omerbsezer/Fast-Docker**](https://github.com/omerbsezer/Fast-Docker)

Quick Look (HowTo)

* [App: Python App - Flask: Creating First Docker Image and Container using Docker File](https://github.com/omerbsezer/Fast-Docker/blob/main/FirstImageFirstContainer.md)
* [App: Binding Volume to the Different Containers](https://github.com/omerbsezer/Fast-Docker/blob/main/DockerVolume.md)
* [App: Binding Mount to the Container](https://github.com/omerbsezer/Fast-Docker/blob/main/DockerVolume.md#app_mount)
* [App: Docker-Compose File - Creating 2 Different Containers: WordPress Container depends on MySql Container](https://github.com/omerbsezer/Fast-Docker/blob/main/DockerCompose.md)
* [App: Creating Docker Swarm Cluster With 5 PCs using PlayWithDocker : 3 x WordPress Containers and 1 x MySql Container using Docker-Compose File](https://github.com/omerbsezer/Fast-Docker/blob/main/DockerStackService.md)
* [App: Running Docker Free Local Registry, Tagging Image, Pushing Image to the Local Registry, Pulling Image From Local Registry and Deleting Images from Local Registry](https://github.com/omerbsezer/Fast-Docker/blob/main/DockerLocalRegistry.md)
* [App: Transferring Content between Host PC and Docker Container](https://github.com/omerbsezer/Fast-Docker/blob/main/DockerTransferringContent.md)
* [Docker Commands Cheatsheet](https://github.com/omerbsezer/Fast-Docker/blob/main/DockerCommandCheatSheet.md)

Table of Contents

* [Motivation](https://github.com/omerbsezer/Fast-Docker#motivation)
* [Needs](https://github.com/omerbsezer/Fast-Docker#needs)
* [Benefits](https://github.com/omerbsezer/Fast-Docker#benefits)
* [Problems Docker does not solve](https://github.com/omerbsezer/Fast-Docker#problems)
* [What is Docker?](https://github.com/omerbsezer/Fast-Docker#whatIsDocker)
* [Architecture](https://github.com/omerbsezer/Fast-Docker#architecture)
* [Installation](https://github.com/omerbsezer/Fast-Docker#installation)


/r/django
https://redd.it/mmd7xx
PEP 802 – Display Syntax for the Empty Set

PEP 802 – Display Syntax for the Empty Set
https://peps.python.org/pep-0802/

# Abstract

We propose a new notation, {/}, to construct and represent the empty set. This is modelled after the corresponding mathematical symbol ‘∅’.

This complements the existing notation for empty tuples, lists, and dictionaries, which use ()[], and {} respectively.

>>> type({/})
<class 'set'>
>>> {/} == set()
True

# Motivation

Sets are currently the only built-in collection type that have a display syntax, but no notation to express an empty collection. The Python Language Reference notes this, stating:

>An empty set cannot be constructed with {}; this literal constructs an empty dictionary.

This can be confusing for beginners, especially those coming to the language from a scientific or mathematical background, where sets may be in more common use than dictionaries or maps.

A syntax notation for the empty set has the important benefit of not requiring a name lookup (unlike set()). {/} will always have a consistent meaning, improving teachability of core concepts to beginners. For example, users must be careful not to use set as a local variable name, as doing so prevents constructing new sets. This can be frustrating as beginners may not know how to recover the `set` type if they have overriden the name.

/r/Python
https://redd.it/1mnuan1