Python-pakketten ontwikkelen
James Fulton
Climate informatics researcher
import numpy as np
help(np.sum)
...
sum(a, axis=None, dtype=None, out=None)
Sum of array elements over a given axis.
Parameters
----------
a : array_like
Elements to sum.
axis : None or int or tuple of ints, optional
Axis or axes along which a sum is performed.
The default, axis=None, will sum all of the
elements of the input array.
...
import numpy as np
help(np.array)
...
array(object, dtype=None, copy=True)
Create an array.
Parameters
----------
object : array_like
An array, any object exposing the array
interface ...
dtype : data-type, optional
The desired data-type for the array.
copy : bool, optional
If true (default), then the object is copied.
...
import numpy as np
x = np.array([1,2,3,4])
help(x.mean)
...
mean(...) method of numpy.ndarray instance
a.mean(axis=None, dtype=None, out=None)
Returns the average of the array elements
along given axis.
Refer to `numpy.mean` for full documentation.
...
def count_words(filepath, words_list):""" ... """
def count_words(filepath, words_list):"""Tel hoe vaak deze woorden in totaal voorkomen."""
def count_words(filepath, words_list):"""Tel hoe vaak deze woorden in totaal voorkomen. De telling gebeurt op een tekstbestand op de opgegeven locatie. """
def count_words(filepath, words_list):"""Tel hoe vaak deze woorden in totaal voorkomen. De telling gebeurt op een tekstbestand op de opgegeven locatie. [leg uit wat filepath en words_list zijn] [wat er wordt geretourneerd] """
Google-stijl voor documentatie
"""Samenvattende regel.
Uitgebreide beschrijving van de functie.
Args:
arg1 (int): Beschrijving van arg1
arg2 (str): Beschrijving van arg2
NumPy-stijl
"""Samenvattende regel.
Uitgebreide beschrijving van de functie.
Parameters
----------
arg1 : int
Beschrijving van arg1 ...
Returns
----------
numpy.ndarray
reStructuredText-stijl
"""Samenvattende regel.
Uitgebreide beschrijving van de functie.
:param arg1: Beschrijving van arg1
:type arg1: int
:param arg2: Beschrijving van arg2
:type arg2: str
Epytext-stijl
"""Samenvattende regel.
Uitgebreide beschrijving van de functie.
@type arg1: int
@param arg1: Beschrijving van arg1
@type arg2: str
@param arg2: Beschrijving van arg2
Populair in wetenschappelijke Python-pakketten zoals
numpyscipypandassklearnmatplotlibdaskimport scipy
help(scipy.percentile)
percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear') Compute the q-th percentile of the data along the specified axis. Returns the q-th percentile(s) of the array elements.Parameters ----------a : array_likeInput array or object that can be converted to an array.
Andere types zijn o.a. int, float, bool, str, dict, numpy.array, enz.
import scipy
help(scipy.percentile)
percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear')
...
Parameters
----------
...
axis : {int, tuple of int, None}
...
interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}
import scipy
help(scipy.percentile)
percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear')
...
Returns
-------
percentile : scalar or ndarray
If `q` is a single percentile and `axis=None`, then the result
is a scalar. If multiple percentiles are given, first axis of
the result corresponds to the percentiles...
...
Andere secties
RaisesSee AlsoNotesReferencesExamplespyment kan docstrings genererenpyment -w -o numpydoc textanalysis.py
def count_words(filepath, words_list):
# Open the text file
...
return n
-w - bestand overschrijven-o numpydoc - uitvoer in NumPy-stijlpyment -w -o numpydoc textanalysis.py
def count_words(filepath, words_list):
"""
Parameters
----------
filepath :
words_list :
Returns
-------
type
"""
pyment -w -o google textanalysis.py
def count_words(filepath, words_list):
"""Tel hoe vaak deze woorden in totaal voorkomen.
De telling gebeurt op een tekstbestand op de opgegeven locatie.
Parameters
----------
filepath : str
Pad naar tekstbestand.
words_list : list of str
Tel hoe vaak deze woorden voorkomen.
Returns
-------
"""
pyment -w -o google textanalysis.py
def count_words(filepath, words_list):
"""Tel hoe vaak deze woorden in totaal voorkomen.
De telling gebeurt op een tekstbestand op de opgegeven locatie.
Args:
filepath(str): Pad naar tekstbestand.
words_list(list of str): Tel hoe vaak deze woorden voorkomen.
Returns:
"""
mysklearn/__init__.py
"""
Lineaire regressie voor Python
============================
mysklearn is een compleet pakket om
lineaire regressie in Python te implementeren.
"""
mysklearn/preprocessing/__init__.py
"""
Een subpackage voor standaard pre-processing-bewerkingen.
"""
mysklearn/preprocessing/normalize.py
"""
Een module voor het normaliseren van data.
"""
Python-pakketten ontwikkelen