Comparaison Point/Sample vs numpy array

​Bonjour,

Dans le tableau suivant, je reprends ici les méthodes de Point et Sample et indique, quand j’ai pu les trouver, les équivalents Numpy.

Les méthodes de Point ont presque toutes un équivalent Numpy :

Méthode Description Équivalent Numpy
add(*args) Append a component (in-place). np.append (not in-place)
at(*args) Access to an element of the collection. FONCTIONNE SEULEMENT EN C++
clear() Reset the collection to zero dimension. ​np.array() (not in-place)
dot(rhs) Compute the scalar product. dot
find(val) Find the index of a given value. where
getClassName() Accessor to the object’s name. class
getDimension() Accessor to the vector’s dimension. shape
getId() Accessor to the object’s id. Pas d’équivalent
getName() Accessor to the object’s name. Pas d’équivalent
getShadowedId() Accessor to the object’s shadowed id. Pas d’équivalent
getSize() Accessor to the vector’s dimension (or size). shape
getVisibility() Accessor to the object’s visibility state.
hasName() Test if the object is named. Pas d’équivalent
hasVisibleName() Test if the object has a distinguishable name. Pas d’équivalent
isDecreasing() Check if the components are in decreasing order. np.all(np.diff(a) < 0)
isEmpty() Tell if the collection is empty. size
isIncreasing() Check if the components are in increasing order. np.all(np.diff(a) > 0)
isMonotonic() Check if the components are in nonincreasing or nondecreasing order. np.all(np.diff(a) < 0) or np.all(np.diff(a) > 0)
isNonDecreasing() Check if the components are in nondecreasing order. np.all(np.diff(a) >= 0)
isNonIncreasing() Check if the components are in nonincreasing order. np.all(np.diff(a) <= 0)
norm() Compute the Euclidean () norm. np.linalg.norm
norm1() Compute the norm. np.linalg.norm(ord=1)
normInf() Compute the norm. np.linalg.norm(ord=inf)
normSquare() Compute the squared Euclidean norm. dot(a)
normalize() Compute the normalized vector with respect to its Euclidean norm. a / np.linalg.norm(a)
normalizeSquare() Compute the normalized vector with respect to its squared Euclidean norm. a / a.dot(a)
resize(newSize) Change the size of the collection. reshape
setName(name) Accessor to the object’s name. Pas d’équivalent
setShadowedId(id) Accessor to the object’s shadowed id. Pas d’équivalent
setVisibility(visible) Accessor to the object’s visibility state. Pas d’équivalent

Sample propose davantage de méthodes originales, mais les équivalents Numpy sont tout de même nombreux. La fonction np.std présente un piège : par défaut, elle n’utilise pas la version non biaisée, contrairement à OT.

Méthode Description Équivalent Numpy
BuildFromPoint(point) Static method for building a sample from a sequence of float. reshape(-1, 1)
ImportFromCSVFile(*args) Static method for building a sample from a CSV file. genfromtxt
ImportFromTextFile(*args) Static method for building a sample from a text file. genfromtxt
add(*args) Append a sample (in-place). np.append (not in-place)
asPoint() Accessor to the internal linear storage for 1D sample. reshape(-1)
clear() Erase all values. np.array (not in-place)
computeCenteredMoment(k) Estimate componentwise centered moments. ((a – a.mean(axis=0))**k).mean()
computeCovariance() Estimate the covariance matrix. np.cov(a.T)
computeEmpiricalCDF(point[, tail]) Estimate the empirical cumulative distribution function (ECDF). Pas d’équivalent
computeKendallTau() Estimate the Kendall coefficients matrix. Pas d’équivalent
computeKurtosis() Estimate the componentwise kurtosis (4th order centered normalized moment). Pas d’équivalent
computeLinearCorrelation() (ditch me?)
computeMean() Estimate the mean vector. mean(axis=0)
computeMedian() Estimate the componentwise medians (50%-quantiles). median(axis=0)
computePearsonCorrelation() Estimate the Pearson correlation matrix. np.corrcoef(a.T)
computeQuantile*(args) Estimate the quantile of the joint distribution underlying the sample. Pas d’équivalent
computeQuantilePerComponent(*args) Estimate the componentwise quantiles. np.quantile(axis=0)
computeRange() Compute the range per component. np.ptp(axis=0)
computeRawMoment(k) Compute the raw (non-centered) moment per component. (a**k).mean()
computeSkewness() Estimate the componentwise skewness (3rd order centered normalized moment). Pas d’équivalent
computeSpearmanCorrelation() Estimate the Spearman correlation matrix. Pas d’équivalent
computeStandardDeviation() Estimate the componentwise standard deviations. std(axis=0, ddof=1)
computeVariance() Estimate the componentwise variances. var(axis=0, ddof=1)
erase(*args) Erase point(s) at or between index(es) (in-place). np.delete(a, (i), axis=0) (not in-place)
exportToCSVFile(*args) Dump the sample to a CSV file. tofile(filename, sep=‘,’)
find(point) Get the position of a point in the sample. np.where
getClassName() Accessor to the object’s name. Pas d’équivalent
getDescription() Accessor to the componentwise description. Pas d’équivalent
getDimension() Accessor to the sample’s dimension. shape[1]
getId() Accessor to the object’s id. Pas d’équivalent
getImplementation() Accessor to the underlying implementation.
getMarginal(*args) Accessor to sample marginal(s) (column(s)). a[:, index]
getMax() Accessor to the componentwise maximum values. max(axis=0)
getMin() Accessor to the componentwise minimum values. min(axis=0)
getName() Accessor to the object’s name. Pas d’équivalent
getSize() Accessor to the sample size. shape[0]
rank(*args) Compute the sample (componentwise) ranks. argsort(axis=0).argsort(axis=0)
select(indices) Select points in a sample. a[i]
setDescription(description) Accessor to the componentwise description. Pas d’équivalent
setName(name) Accessor to the object’s name. Pas d’équivalent
sort(*args) Sort the sample. sort(axis=0)
sortAccordingToAComponent(index) Sort the sample according to the given component. a[a[:, index].argsort()]
sortAccordingToAComponentInPlace(index) Sort the sample in place according to the given component. Not in-place
sortInPlace() Sort the sample in place. Not in-place
sortUnique() Sort the sample and remove duplicate points. np.unique(a).sort()
sortUniqueInPlace() Sort the sample in place and remove duplicate points. Not in-place
split(index) Trunk the sample. a[0:index] (not in-place)
stack(sample) Stack (horizontally) the given sample to the current one (in-place). np.concatenate (not in-place)

Cordialement

Joseph

2 Likes