Notebook Articles

Take notes and save or share what you have learned

Articles: 586

Les opérateurs arithmétiques en python

Liste des opérateurs arithmétiques en python [TOC] ### Définition d'un opérateurs: Un opérateur est un symbole (ou un mot réservé) utilisé pour effectuer une opération entre des opérandes. ### L'opérateur addition + Additionner deux entiers >>> 3 + 2 5 Additionner un entier et un nombre réel >>> 2.1 + 3 5.1 Additionner deux nombre réels >>> 4.3 + 2.1 6.4 ### L'opérateur soustraction - Soustraction d'un entier par un autre entier

How to add a new column in a table using python and numpy ?

Examples of how add a new column in a table using python and numpy: [TOC] Let's consider an array of size (10,4): \begin{equation} A = \left( \begin{array}{ccc} 4 & 11 & 10 & 2 \\\\ 8 & 18 & 5 & 10 \\\\ 3 & 15 & 17 & 13 \\\\ 14 & 15 & 17 & 16 \\\\ 4 & 11 & 2 & 10 \\\\ 1 & 14 & 5 & 11 \\\\ 16 & 5 & 12 & 8 \\\\ 17 & 17 & 15 & 0 \\\\ 4 & 5 & 12 & 8 \\\\ 6 & 2 & 19 & 15 \end{array}\right) \end{equation} >>> import numpy as np

Comment ajouter une colonne dans un tableau avec numpy et python ?

Exemples de comment ajouter une colonne dans un tableau avec numpy et python ? [TOC] Soit un tableau de dimension (10,4): \begin{equation} A = \left( \begin{array}{ccc} 4 & 11 & 10 & 2 \\\\ 8 & 18 & 5 & 10 \\\\ 3 & 15 & 17 & 13 \\\\ 14 & 15 & 17 & 16 \\\\ 4 & 11 & 2 & 10 \\\\ 1 & 14 & 5 & 11 \\\\ 16 & 5 & 12 & 8 \\\\ 17 & 17 & 15 & 0 \\\\ 4 & 5 & 12 & 8 \\\\ 6 & 2 & 19 & 15 \end{array}\right) \end{equation} >>> import numpy as

How to homogenize with the latitude a MODIS-2B-CLDCLASS-lidar sample ?

Example of how to homogenize with the latitude a MODIS-2B-CLDCLASS-lidar random sample [TOC] ### Example for a month of data input files can be downloaded here: - [sample 0](/Files/2008-01-sample-00-modis-caliop-cldclass-lidar/) - [sample 1](/Files/2008-01-sample-01-modis-caliop-cldclass-lidar-1/) [images:2008-01-sample-homogenization-02;2008-01-sample-homogenization-06 dim:1*2 size:100 caption:Colocated (1month) MODIS and 2B-CLDCLASS-lidar sample homogenization with python ]

Get the latitude and longitude of a 2B-CLDCLASS-lidar granule with python

Example of python code to read the latitude and longitude of a 2B-CLDCLASS-lidar granule using python #!/usr/bin/env python from pyhdf.SD import SD, SDC from pyhdf.HDF import * from pyhdf.VS import * import pprint file_path = '' file_name = '2008183012329_11573_CS_2B-CLDCLASS-LIDAR_GRANULE_P_R04_E02.hdf' # Read HDF Files (VD data) Latitude & Longitude f = HDF(file_path+file_name, SDC.READ) vs = f.vstart() Latitude = vs.attach('Latitude') Longitude = vs.at

How to find the hypotenuse of a right triangle in python ?

To find the hypotenuse of a right triangle in python, a solution is to use the module[math](https://docs.python.org/2/library/math.html#math.hypot), example: >>> import math >>> x = 2 >>> y = 3 >>> math.hypot(x,y) 3.605551275463989 Check: >>> z2 = x**2+y**2 >>> math.sqrt(z2) 3.605551275463989 ### Références Links | Site ------------- | ------------- [hypot()](https://docs.python.org/2/library/math.html#math.hypot) | python doc

How to apply a numerical Fourier transform for a simple function using python ?

Some examples of how to calculate and plot the Fourier transform using python and scipy [fft](https://docs.scipy.org/doc/scipy/reference/generated/scipy.fftpack.fft.html#scipy.fftpack.fft) [TOC] ### Cosinus function [images:fourrier-transform-cosinus;fourrier-transform-cosinus-abs dim:1*2 size:100 caption:How to apply a numerical Fourier transform for a simple function using python ? ] import numpy as np import matplotlib.pyplot as plt import scipy.fftpack #-----------------

How to read a JSON file using python ?

Example of how to read a JSON file using python: [TOC] #### Read a JSON file with python Let's consider a JSON (JavaScript Object Notation) file called data.json: { "abstract": "Hello how are you today ?", "link_01": { "name": "Welcome page", "priority": "1" }, "link_02": { "name": "Home page", "priority": "2" } } To read the file with python: with open('data.json') as json_data: print(type(json_data)) returns <class '_io.TextIOWr

Calcul numérique de la transformée de Fourier de fonctions usuelles avec python

Quelques exemples de comment calculer numériquement une transformée de Fourier pour quelques fonctions usuelles avec python en utilisant scipy [fft](https://docs.scipy.org/doc/scipy/reference/generated/scipy.fftpack.fft.html#scipy.fftpack.fft) [TOC] ### Fonction cosinus [images:fourrier-transform-cosinus;fourrier-transform-cosinus-abs dim:1*2 size:100 caption:Calcul numérique de la transformée de Fourier de fonctions usuelles avec python] import numpy as np import matplotlib.pyplo

How to calculate Legendre polynomials in fortran 90 ?

Legendre polynomials can be calculated using the recurrence relation: \begin{equation} P\_n = \frac{(2n-1)}{n}.x.P\_{n-1}-(n-1).P\_{n-2} \end{equation} with $P_0=1$ et $P_1=x$ Source code in fortran 90: program legendre_polynomials implicit none integer, parameter :: pr = selected_real_kind(15,3) integer :: i,j,n integer :: nb_pl, nb_x real(pr), dimension(:,:), allocatable :: pl real(pr) :: pl_n2, pl_n1 real(pr) :: x, x_min, x_max, x_resol real(pr

How to calculate and plot Legendre polynomials with python and matplotlib ?

To find the Legendre polynomials a solution is to use [scipy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.legendre.html#scipy.special.legendre): [TOC] ### Calculate Legendre polynomials using scipy >>> from scipy.special import legendre >>> n = 3 >>> Pn = legendre(n) >>> Pn(0) 0.0 >>> Pn(0.2) -0.27999999999999997 >>> Pn(0.5) -0.43749999999999994 >>> Calculate on the range [-1,1]: >>> from scipy.special im

How to plot a Gabor filter using python and matplotlib ?

how to plot Gabor filters using python and matplotlib, examples: [TOC] ### 2D Gabor filter with matplotlib [images:460;461 dim:1*2 size:100 caption:Plot a Gabor filter using Matplotlib (left figure: grayscale); (right figure:normalized between 0 and 255) ] import numpy as np import matplotlib.pyplot as plt import matplotlib.cm as cm import math f = 0.1 theta = math.radians(0.0) # Converts angle x from degrees to radians. sigma_x = 7.0 sigma_y = 7.0 radius = 20

Calculate the remainder of an Euclidean division (modulo operation) in python

To calculate the remainder of an Euclidean division in python, a solution is to use the modulo operator %, example: >>> 10 % 2 0 since 10 = 2 * 5 + 0 >>> 10 % 3 1 since 10 = 3 * 3 + 1 Another solution is to use the python module "math" with the function [math.fmod()](https://docs.python.org/2/library/math.html): >>> import math >>> math.fmod(10.0,2.0) 0.0 >>> math.fmod(10.0,3.0) 1.0 >>> math.fmod(11.0,3.2) 1.3999999999999995

How to read a microsoft excel file using python ?

To read an excel file using python, a solution is to use the python module called [xlrd](https://pypi.org/project/xlrd/). An example with a file called 'read_excel_file_with_python.xlsx': [TOC] [images:how-to-read-excel-file-with-python-01;how-to-read-excel-file-with-python-02 dim:1*2 size:100 caption:How to read a microsoft excel file using python ?] ### Get the spreadsheet names import xlrd import numpy as np workbook = xlrd.open_workbook('read_excel_file_with_python.xlsx')

Comment lire un fichier microsoft excel avec python ?

Pour lire un fichier excel avec python il existe le module [xlrd](https://pypi.org/project/xlrd/). Exemple avec un fichier intitulé 'read_excel_file_with_python.xlsx': [TOC] [images:how-to-read-excel-file-with-python-01;how-to-read-excel-file-with-python-02 dim:1*2 size:100 caption:Comment lire un fichier excel avec python ?] ### Lire le nom des feuilles excel: import xlrd import numpy as np workbook = xlrd.open_workbook('read_excel_file_with_python.xlsx') SheetNameList = wo

How to create (extract) a sample from an array in python ?

Let's consider a table called "a", goal: extract a random sample of size 3 from the table [TOC] import numpy as np a = np.array([[0, 4, 9, 8, 2], [1, 5, 4, 1, 7], [2, 5, 1, 9, 3], [3, 7, 5, 9, 7], [4, 2, 6, 6, 3], [5, 1, 8, 1, 7], [6, 2, 9, 7, 4], [7, 9, 2, 9, 3], [8, 9, 4, 9, 6], [9, 6, 2, 7, 2]]) print(a) returns [[0 4 9 8 2] [1 5 4 1 7] [2 5 1 9 3] [3 7 5 9 7] [4 2 6 6 3] [5 1 8 1 7] [6

Comment créer (extraire) un échantillon à partir d'un tableau en python ?

Exemple de comment créer (extraire) un échantillon à partir d'un tableau en python ? Soit un tableau 2D appelé "a", on veut extraire un échantillon aléatoire du tableau composé par exemple de 3 éléments: [TOC] import numpy as np a = np.array([[0, 4, 9, 8, 2], [1, 5, 4, 1, 7], [2, 5, 1, 9, 3], [3, 7, 5, 9, 7], [4, 2, 6, 6, 3], [5, 1, 8, 1, 7], [6, 2, 9, 7, 4], [7, 9, 2, 9, 3], [8, 9, 4, 9, 6], [9, 6, 2, 7, 2]])

How to plot a simple vector field in matplotlib ?

To plot a vector field in matplotlib, a simple solution is to use [quiver](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.quiver.html): quiver(X, Y, U, V, **kw) with - X : The x coordinates of the arrow locations - Y : The y coordinates of the arrow locations - U : The x components of the arrow vectors - V : The y components of the arrow vectors ### Plot a simple vector with quiver: [image:how-to-plot-a-vector-in-matplotlib-fig3 size:50 caption:How to plot a simple

Comment tracer un simple champ vectoriel avec matplotlib ?

Pour tracer un champ vectoriel avec matplotlib, il existe la fonction [quiver](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.quiver.html): quiver(X, Y, U, V, C, **kw) avec - X coordonnée x de l'origine du vecteur - Y coordonnée y de l'origine du vecteur - U coordonnée x de l'extrémité du vecteur - V coordonnée y de l'extrémité du vecteur - C couleur du vecteur ### Tracer un simple vecteur avec quiver Exemple de comment tracer un simple vecteur: [image:how-to-pl

How to plot a simple vector with matplotlib ?

To plot a simple vector using matplotlib a solution is to use [arrow](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.arrow.html) [TOC] ### Plot a simple vector with matplotlib [image:how-to-plot-a-vector-in-matplotlib-fig1 size:50 caption:How to plot a simple vector with matplotlib ? ] import matplotlib.pyplot as plt import numpy as np ax = plt.axes() ax.arrow(2.0, 4.0, 6.0, 4.0, head_width=0.5, head_length=0.7, fc='lightblue', ec='black') plt.grid() plt.xlim

Comment tracer un simple vecteur avec matplotlib ?

Pour tracer un simple vecteur avec matplotlib on peut utiliser [arrow](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.arrow.html) [TOC] ### Tracer un simple vecteur avec matplotlib [image:how-to-plot-a-vector-in-matplotlib-fig1 size:50 caption:Comment tracer un vecteur ou un champ vectoriel avec matplotlib ? ] import matplotlib.pyplot as plt import numpy as np ax = plt.axes() ax.arrow(2.0, 4.0, 6.0, 4.0, head_width=0.5, head_length=0.7, fc='lightblue', ec='black')

How to calculate the natural logarithm in python ?

Examples of how to calculate the natural logarithm in python [TOC] ### Calculate the natural logarithm with math natural logarithm can be calculated using the python module called [math](https://docs.python.org/2/library/math.html#math.log): >>> import math >>> math.e 2.718281828459045 >>> e = math.e >>> math.log(e) 1.0 ### Calculate the natural logarithm with numpy natural logarithm can also be calculated using [numpy](https://docs.scipy.org/doc

Comment calculer le logarithme naturel (népérien) avec python ?

Exemples de comment calculer le logarithme naturel (népérien) avec python [TOC] ### Calculer le logarithme népérien avec le module math Avec le module [math](https://docs.python.org/2/library/math.html#math.log): >>> import math >>> math.e 2.718281828459045 >>> e = math.e >>> math.log(e) 1.0 ### Calculer le logarithme népérien avec numpy Avec [numpy](https://docs.scipy.org/doc/numpy/reference/generated/numpy.log.html): >>> import numpy as n

How to add a heat map on a global map using d3.js and topojson ?

An example to add a heat map on a global map using d3.js and topojson. To run the code use the file: [world-110m.json](/Files/world-110m/). [image:simple-global-heatmap-d3 size:100 caption:How to add a heat map on a global map using d3.js and topojson ?] <!DOCTYPE html> <meta charset="utf-8"> <style> path { fill: none; stroke: #000; stroke-width: .5px; } .land-boundary { stroke-width: 1px; } .county-boundary { stroke: #aaa; } </style>

How to plot a simple global map using d3.js and topojson ?

An example of how to plot a simple global map using [d3.js](https://d3js.org/) and [topojson](https://github.com/topojson/topojson). The code need the file [world-110m.json](/Files/world-110m/). To test the code locally, a solution is to use python and launch a local testing server: python -m http.server 8001 then go to http://localhost:8001/ in the browser. [image:simple-global-map-d3 size:100 caption:How to plot a simple global map using d3.js and topojson ?] Source code

About


An article helps to save or share information. After creating an article it is possible to add multiple authors and manage the permissions

Create an article

Search


Use the following form to retrieve an article: