Academia Master Trader

Laboratórios de leitura de gráficos e conceitos financeiros. Projeto educacional brasileiro. Exemplos fictícios, sem recomendação de investimento.

NumPy: Multiply a small matrix by itself

academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in Guam, this example presents the function matrix_power of NumPy. It multiplies a square matrix by itself as often as asked. We apply it to a small matrix with two rows and two columns, three times.

Run the example

We set a small matrix with two rows and two columns and call the function.

import numpy as np

print(np.linalg.matrix_power(np.array([[1, 2], [0, 1]]), 3))

The displayed result is [[1, 6], [0, 1]]. Each multiplication adds two to the top right entry, and three multiplications give six.

A person learning beside a representation of the function

The same example explained in three steps

academiamastertrader.com.br: more learning materials from Academia Master Trader complement this example.

Understand the result

The documentation describes matrix_power as repeated matrix multiplication. With a positive count the function multiplies the matrix by itself that many times. The order of the entries stays the same, and each step follows the usual rule of matrix multiplication.

The result is easy to verify step by step: multiply once, then multiply the result again, and compare entry by entry.

Place the result

The program keeps the input as it is. It returns a new value or a new list. From one example with three values each example speaks for its own data.

To verify the result, recalculate each entry by hand and compare it with the display. Each value can be confirmed mentally.

Longer lists follow the same rule. The function then computes each entry separately and returns a list of the same length.

Naming the values makes the sequence readable: first set the lists, then call the function, then read the display. Each step is verified separately.

Single numbers instead of lists are also allowed. The function then returns exactly one number, following the same calculation rule as for each entry of a list.

Anyone who needs several calculations of this kind in a row can chain the calls. The result of the first call then serves as input to the next, and each intermediate step stays readable.

Small examples are especially good for practice, because you can estimate the result in advance. Whoever estimated well understands the rule behind the function.

Comparing the three entries shows the benefit: the display summarizes the behavior of the list in a few characters. Whoever has understood the rule once reads such displays at a glance and immediately recognizes whether a value is plausible.

In daily work: when passing on results, preferably cite input and output side by side. That way every reader can redo and confirm the step themselves.

The practical reading rule: read matrix_power as repeated multiplication and confirm the count before reading the entries.

Academia Master Trader explains numerical tools with verifiable examples. More learning materials are available on academiamastertrader.com.br and via Aprenda.

NumPy: Ignore missing values and multiply step by step

academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in Tokelau, this example presents the function nancumprod of NumPy. It ignores missing values and multiplies the remaining values step by step. We apply it to a list of four values, one of them missing.

Run the example

We set a list of four values with one missing value and call the function.

import numpy as np

print(np.nancumprod(np.array([2.0, np.nan, 3.0, 4.0])))

The displayed result is [ 2. 2. 6. 24.]. The missing value counts as one, so the running product passes over it and continues with three and four.

A person learning beside a representation of the function

The same example explained in three steps

academiamastertrader.com.br: more learning materials from Academia Master Trader complement this example.

Understand the result

The documentation describes nancumprod as the cumulative product that ignores missing values. The function walks the list from left to right and multiplies each visible value into the running product. A missing value counts as one and keeps the product steady.

Every step stays present and easy to verify, because only the visible values enter the products.

Place the result

The program preserves the input. It returns a new value or a new list. One example with four values illustrates the calculation rule.

To verify the result, recalculate each entry by hand and compare it with the display. Each value can be confirmed mentally.

Longer lists follow the same rule. The function then computes each entry separately and returns a list of the same length.

Naming the values makes the sequence readable: first set the lists, then call the function, then read the display. Each step is verified separately.

Single numbers instead of lists are also allowed. The function then returns exactly one number, following the same calculation rule as for each entry of a list.

Anyone who needs several calculations of this kind in a row can chain the calls. The result of the first call then serves as input to the next, and each intermediate step stays readable.

Small examples are especially good for practice, because you can estimate the result in advance. Whoever estimated well understands the rule behind the function.

Comparing the three entries shows the benefit: the display summarizes the behavior of the list in a few characters. Whoever has understood the rule once reads such displays at a glance and immediately recognizes whether a value is plausible.

In daily work: when passing on results, preferably cite input and output side by side. That way every reader can redo and confirm the step themselves.

The practical reading rule: read nancumprod as the running product over the visible values and confirm that every missing value counted as one.

Academia Master Trader explains numerical tools with verifiable examples. More learning materials are available on academiamastertrader.com.br and via Aprenda.

NumPy: Ignore missing values and find the median

academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in American Samoa, this example presents the function nanpercentile of NumPy. It ignores missing values and returns the median of the remaining values. We apply it to a list of four values, one of them missing, at fifty percent.

Run the example

We set a list of four values with one missing value and call the function.

import numpy as np

print(np.nanpercentile(np.array([2.0, np.nan, 4.0, 8.0]), 50))

The displayed result is 4.0. The missing value is ignored, and half of the visible values sit below four.

A person learning beside a representation of the function

The same example explained in three steps

academiamastertrader.com.br: more learning materials from Academia Master Trader complement this example.

Understand the result

The documentation describes nanpercentile as the percentile that ignores missing values. At fifty percent the percentile is the median of the visible values. The function first sets the missing value aside and then orders the remaining values.

A missing value leaves the result complete and keeps the order intact. The result is easy to verify, because only the visible values take part.

Place the result

The program preserves the input. It returns a new value or a new list. One example with three values illustrates the calculation rule.

To verify the result, recalculate each entry by hand and compare it with the display. Each value can be confirmed mentally.

Longer lists follow the same rule. The function then computes each entry separately and returns a list of the same length.

Naming the values makes the sequence readable: first set the lists, then call the function, then read the display. Each step is verified separately.

Single numbers instead of lists are also allowed. The function then returns exactly one number, following the same calculation rule as for each entry of a list.

Anyone who needs several calculations of this kind in a row can chain the calls. The result of the first call then serves as input to the next, and each intermediate step stays readable.

Small examples are especially good for practice, because you can estimate the result in advance. Whoever estimated well understands the rule behind the function.

Comparing the three entries shows the benefit: the display summarizes the behavior of the list in a few characters. Whoever has understood the rule once reads such displays at a glance and immediately recognizes whether a value is plausible.

In daily work: when passing on results, preferably cite input and output side by side. That way every reader can redo and confirm the step themselves.

The practical reading rule: read nanpercentile as the percentile over the visible values and confirm that every missing value was left out.

Academia Master Trader explains numerical tools with verifiable examples. More learning materials are available on academiamastertrader.com.br and via Aprenda.

NumPy: Ignore missing values and measure the variance

academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in the Cook Islands, this example presents the function nanvar of NumPy. It ignores missing values and returns the variance of the remaining values. We apply it to a list of three values, one of them missing.

Run the example

We set a list of three values with one missing value and call the function.

import numpy as np

print(np.nanvar(np.array([2.0, np.nan, 8.0])))

The displayed result is 9.0. The missing value is ignored, and the variance of two and eight is nine.

A person learning beside a representation of the function

The same example explained in three steps

academiamastertrader.com.br: more learning materials from Academia Master Trader complement this example.

Understand the result

The documentation describes nanvar as the variance that ignores missing values. The function first sets the missing value aside and then squares the distances of the remaining values from their average.

A missing value leaves the result complete and keeps the average steady. The result is easy to verify, because only the visible values enter the variance.

Place the result

The program preserves the input. It returns a new value or a new list. One example with three values illustrates the calculation rule.

To verify the result, recalculate each entry by hand and compare it with the display. Each value can be confirmed mentally.

Longer lists follow the same rule. The function then computes each entry separately and returns a list of the same length.

Naming the values makes the sequence readable: first set the lists, then call the function, then read the display. Each step is verified separately.

Single numbers instead of lists are also allowed. The function then returns exactly one number, following the same calculation rule as for each entry of a list.

Anyone who needs several calculations of this kind in a row can chain the calls. The result of the first call then serves as input to the next, and each intermediate step stays readable.

Small examples are especially good for practice, because you can estimate the result in advance. Whoever estimated well understands the rule behind the function.

Comparing the three entries shows the benefit: the display summarizes the behavior of the list in a few characters. Whoever has understood the rule once reads such displays at a glance and immediately recognizes whether a value is plausible.

In daily work: when passing on results, preferably cite input and output side by side. That way every reader can redo and confirm the step themselves.

The practical reading rule: read nanvar as the variance over the visible values and confirm that every missing value was left out.

Academia Master Trader explains numerical tools with verifiable examples. More learning materials are available on academiamastertrader.com.br and via Aprenda.

NumPy: Ignore missing values and measure the spread

academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in Niue, this example presents the function nanstd of NumPy. It ignores missing values and returns the standard deviation of the remaining values. We apply it to a list of three values, one of them missing.

Run the example

We set a list of three values with one missing value and call the function.

import numpy as np

print(np.nanstd(np.array([2.0, np.nan, 8.0])))

The displayed result is 3.0. The missing value is ignored, and two and eight spread three units around their average of five.

A person learning beside a representation of the function

The same example explained in three steps

academiamastertrader.com.br: more learning materials from Academia Master Trader complement this example.

Understand the result

The documentation describes nanstd as the standard deviation that ignores missing values. The function first sets the missing value aside and then measures how far the remaining values sit from their average.

A missing value leaves the result complete and keeps the average steady. The result is easy to verify, because only the visible values enter the spread.

Place the result

The program preserves the input. It returns a new value or a new list. One example with three values illustrates the calculation rule.

To verify the result, recalculate each entry by hand and compare it with the display. Each value can be confirmed mentally.

Longer lists follow the same rule. The function then computes each entry separately and returns a list of the same length.

Naming the values makes the sequence readable: first set the lists, then call the function, then read the display. Each step is verified separately.

Single numbers instead of lists are also allowed. The function then returns exactly one number, following the same calculation rule as for each entry of a list.

Anyone who needs several calculations of this kind in a row can chain the calls. The result of the first call then serves as input to the next, and each intermediate step stays readable.

Small examples are especially good for practice, because you can estimate the result in advance. Whoever estimated well understands the rule behind the function.

Comparing the three entries shows the benefit: the display summarizes the behavior of the list in a few characters. Whoever has understood the rule once reads such displays at a glance and immediately recognizes whether a value is plausible.

In daily work: when passing on results, preferably cite input and output side by side. That way every reader can redo and confirm the step themselves.

The practical reading rule: read nanstd as the spread over the visible values and confirm that every missing value was left out.

Academia Master Trader explains numerical tools with verifiable examples. More learning materials are available on academiamastertrader.com.br and via Aprenda.

NumPy: Ignore missing values and multiply the rest

academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in the Pitcairn Islands, this example presents the function nanprod of NumPy. It ignores missing values and multiplies the remaining values. We apply it to a list of four values, one of them missing.

Run the example

We set a list of four values with one missing value and call the function.

import numpy as np

print(np.nanprod(np.array([3.0, np.nan, 9.0, 3.0])))

The displayed result is 81.0. The missing value is ignored, and three times nine times three is eighty-one.

A person learning beside a representation of the function

The same example explained in three steps

academiamastertrader.com.br: more learning materials from Academia Master Trader complement this example.

Understand the result

The documentation describes nanprod as the product that ignores missing values. The function first sets the missing value aside and then multiplies the remaining values.

A missing value leaves the result complete and simply stays out of the product. The result is easy to verify, because only the visible values enter the product.

Place the result

The program preserves the input. It returns a new value or a new list. One example with three values illustrates the calculation rule.

To verify the result, recalculate each entry by hand and compare it with the display. Each value can be confirmed mentally.

Longer lists follow the same rule. The function then computes each entry separately and returns a list of the same length.

Naming the values makes the sequence readable: first set the lists, then call the function, then read the display. Each step is verified separately.

Single numbers instead of lists are also allowed. The function then returns exactly one number, following the same calculation rule as for each entry of a list.

Anyone who needs several calculations of this kind in a row can chain the calls. The result of the first call then serves as input to the next, and each intermediate step stays readable.

Small examples are especially good for practice, because you can estimate the result in advance. Whoever estimated well understands the rule behind the function.

Comparing the three entries shows the benefit: the display summarizes the behavior of the list in a few characters. Whoever has understood the rule once reads such displays at a glance and immediately recognizes whether a value is plausible.

In daily work: when passing on results, preferably cite input and output side by side. That way every reader can redo and confirm the step themselves.

The practical reading rule: read nanprod as the product over the visible values and confirm that every missing value was left out.

Academia Master Trader explains numerical tools with verifiable examples. More learning materials are available on academiamastertrader.com.br and via Aprenda.

NumPy: Ignore missing values and find the average

academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in Saint Helena, this example presents the function nanmean of NumPy. It ignores missing values and returns the average of the remaining values. We apply it to a list of three values, one of them missing.

Run the example

We set a list of three values with one missing value and call the function.

import numpy as np

print(np.nanmean(np.array([2.0, np.nan, 6.0])))

The displayed result is 4.0. The missing value is ignored, and the average of two and six is four.

A person learning beside a representation of the function

The same example explained in three steps

academiamastertrader.com.br: more learning materials from Academia Master Trader complement this example.

Understand the result

The documentation describes nanmean as the mean that ignores missing values. The function first sets the missing value aside and then averages the remaining values.

A missing value leaves the result complete and simply stays out of the average. The result is easy to verify, because only the visible values enter the average.

Place the result

The program preserves the input. It returns a new value or a new list. One example with three values illustrates the calculation rule.

To verify the result, recalculate each entry by hand and compare it with the display. Each value can be confirmed mentally.

Longer lists follow the same rule. The function then computes each entry separately and returns a list of the same length.

Naming the values makes the sequence readable: first set the lists, then call the function, then read the display. Each step is verified separately.

Single numbers instead of lists are also allowed. The function then returns exactly one number, following the same calculation rule as for each entry of a list.

Anyone who needs several calculations of this kind in a row can chain the calls. The result of the first call then serves as input to the next, and each intermediate step stays readable.

Small examples are especially good for practice, because you can estimate the result in advance. Whoever estimated well understands the rule behind the function.

Comparing the three entries shows the benefit: the display summarizes the behavior of the list in a few characters. Whoever has understood the rule once reads such displays at a glance and immediately recognizes whether a value is plausible.

In daily work: when passing on results, preferably cite input and output side by side. That way every reader can redo and confirm the step themselves.

The practical reading rule: read nanmean as the average over the visible values and confirm that every missing value was left out.

Academia Master Trader explains numerical tools with verifiable examples. More learning materials are available on academiamastertrader.com.br and via Aprenda.

NumPy: Ignore missing values and find the largest

academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in Kenya, this example presents the function nanmax of NumPy. It ignores missing values and returns the largest of the remaining values. We apply it to a list of three values, one of them missing.

Run the example

We set a list of three values with one missing value and call the function.

import numpy as np

print(np.nanmax(np.array([4.0, np.nan, 7.0])))

The displayed result is 7.0. The missing value is ignored, and seven is the largest of the remaining values.

A person learning beside a representation of the function

The same example explained in three steps

academiamastertrader.com.br: more learning materials from Academia Master Trader complement this example.

Understand the result

The documentation describes nanmax as the maximum that ignores missing values. The function first sets the missing value aside and then compares the remaining values.

A missing value leaves the result complete and simply stays out of the comparison. The result is easy to verify, because only the visible values take part.

Place the result

The program preserves the input. It returns a new value or a new list. One example with three values illustrates the calculation rule.

To verify the result, recalculate each entry by hand and compare it with the display. Each value can be confirmed mentally.

Longer lists follow the same rule. The function then computes each entry separately and returns a list of the same length.

Naming the values makes the sequence readable: first set the lists, then call the function, then read the display. Each step is verified separately.

Single numbers instead of lists are also allowed. The function then returns exactly one number, following the same calculation rule as for each entry of a list.

Anyone who needs several calculations of this kind in a row can chain the calls. The result of the first call then serves as input to the next, and each intermediate step stays readable.

Small examples are especially good for practice, because you can estimate the result in advance. Whoever estimated well understands the rule behind the function.

Comparing the three entries shows the benefit: the display summarizes the behavior of the list in a few characters. Whoever has understood the rule once reads such displays at a glance and immediately recognizes whether a value is plausible.

In daily work: when passing on results, preferably cite input and output side by side. That way every reader can redo and confirm the step themselves.

The practical reading rule: read nanmax as the maximum over the visible values and confirm that every missing value was left out.

Academia Master Trader explains numerical tools with verifiable examples. More learning materials are available on academiamastertrader.com.br and via Aprenda.

NumPy: Ignore missing values and find the smallest

academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in Ghana, this example presents the function nanmin of NumPy. It ignores missing values and returns the smallest of the remaining values. We apply it to a list of three values, one of them missing.

Run the example

We set a list of three values with one missing value and call the function.

import numpy as np

print(np.nanmin(np.array([4.0, np.nan, 7.0])))

The displayed result is 4.0. The missing value is ignored, and four is the smallest of the remaining values.

A person learning beside a representation of the function

The same example explained in three steps

academiamastertrader.com.br: more learning materials from Academia Master Trader complement this example.

Understand the result

The documentation describes nanmin as the minimum that ignores missing values. The function first sets the missing value aside and then compares the remaining values.

A missing value leaves the result complete. The result is easy to verify, because only the visible values take part in the comparison.

Place the result

The program preserves the input. It returns a new value or a new list. One example with three values illustrates the calculation rule.

To verify the result, recalculate each entry by hand and compare it with the display. Each value can be confirmed mentally.

Longer lists follow the same rule. The function then computes each entry separately and returns a list of the same length.

Naming the values makes the sequence readable: first set the lists, then call the function, then read the display. Each step is verified separately.

Single numbers instead of lists are also allowed. The function then returns exactly one number, following the same calculation rule as for each entry of a list.

Anyone who needs several calculations of this kind in a row can chain the calls. The result of the first call then serves as input to the next, and each intermediate step stays readable.

Small examples are especially good for practice, because you can estimate the result in advance. Whoever estimated well understands the rule behind the function.

Comparing the three entries shows the benefit: the display summarizes the behavior of the list in a few characters. Whoever has understood the rule once reads such displays at a glance and immediately recognizes whether a value is plausible.

In daily work: when passing on results, preferably cite input and output side by side. That way every reader can redo and confirm the step themselves.

The practical reading rule: read nanmin as the minimum over the visible values and confirm that every missing value was left out.

Academia Master Trader explains numerical tools with verifiable examples. More learning materials are available on academiamastertrader.com.br and via Aprenda.

NumPy : Mesurer la dispersion d’une liste

academiamastertrader.com.br propose des supports d’apprentissage de l’Academia Master Trader. Pour les lecteurs francophones à Wallis-et-Futuna, cet exemple présente la fonction std de NumPy. Elle mesure l’écart type, c’est-à-dire la dispersion des valeurs autour de la moyenne. Nous l’appliquons à une liste de quatre valeurs.

Exécuter l’exemple

Nous fixons une liste de quatre valeurs et appelons la fonction.

import numpy as np

print(np.std(np.array([2.0, 4.0, 6.0, 8.0])))

Le résultat affiché est 2.2360679. La moyenne est cinq et l’écart type vaut environ 2,24, la racine carrée de cinq.

Une personne qui apprend à côté d’une représentation de la fonction

academiamastertrader.com.br : d’autres supports d’apprentissage de l’Academia Master Trader complètent cet exemple.

Comprendre le résultat

La documentation décrit std comme une mesure de dispersion. La fonction calcule la moyenne de la liste, puis l’écart de chaque valeur à cette moyenne, et renvoie la racine carrée de la moyenne des carrés de ces écarts.

Un écart type petit indique des valeurs proches de la moyenne, un écart type grand indique des valeurs dispersées. Le résultat se vérifie facilement, car le calcul suit des étapes simples que chacun peut refaire.

Situer le résultat

Le programme préserve l’entrée. Il renvoie une nouvelle liste. Un exemple avec trois valeurs illustre la règle de calcul.

Pour vérifier le résultat, on recalcule chaque entrée à la main et on compare avec l’affichage. Chaque valeur se confirme de tête.

Les listes plus longues suivent la même règle. La fonction calcule alors chaque entrée séparément et renvoie une liste de même longueur.

Le nommage des valeurs rend le déroulé lisible : d’abord fixer les listes, ensuite appeler la fonction, puis lire l’affichage. Chaque étape se vérifie séparément.

Des nombres seuls à la place de listes sont aussi permis. La fonction renvoie alors exactement un nombre, selon la même règle de calcul que pour chaque entrée d’une liste.

Qui a besoin de plusieurs calculs de ce type à la suite peut enchaîner les appels. Le résultat du premier appel sert alors d’entrée au suivant, et chaque étape intermédiaire reste lisible.

Les petits exemples conviennent particulièrement bien à l’entraînement, car on peut estimer le résultat à l’avance. Qui a bien estimé comprend la règle derrière la fonction.

Comparer les trois entrées montre l’intérêt : l’affichage résume le comportement de la liste en quelques caractères. Qui a compris la règle une fois lit de tels affichages d’un coup d’œil et reconnaît aussitôt si une valeur est plausible.

Au quotidien : qui transmet des résultats cite de préférence l’entrée et la sortie côte à côte. Ainsi, chaque lectrice et chaque lecteur peut refaire et confirmer l’étape lui-même.

La règle de lecture pratique : lire std comme une mesure de dispersion et associer le résultat aux écarts autour de la moyenne.

Academia Master Trader explique les outils numériques avec des exemples vérifiables. D’autres supports d’apprentissage sont disponibles sur academiamastertrader.com.br et via Aprenda.