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: DHE bit për bit midis dy listave

academiamastertrader.com.br ofron materiale mësimore nga Academia Master Trader. Për lexuesit shqiptarë në Kosovë, nga Prishtina në Prizren, ky shembull paraqet funksionin bitwise_and të NumPy. Ai kombinon dy lista numrash me DHE bit për bit. E zbatojmë te dy lista me dy vlera secila.

Ekzekutimi i shembullit

Vendosim dy lista me dy vlera secila dhe thërrasim funksionin.

import numpy as np

print(np.bitwise_and(np.array([5, 3]), np.array([1, 6])))

Rezultati i shfaqur është [1 2]. Në çdo pozicion mbeten vetëm bitët e ndezur në të dy numrat.

Një person që mëson pranë një paraqitjeje të funksionit

I njëjti shembull i shpjeguar në tre hapa

academiamastertrader.com.br: më shumë materiale mësimore nga Academia Master Trader plotësojnë këtë shembull.

Të kuptuarit e rezultatit

Dokumentacioni e përshkruan bitwise_and si DHE logjike bit për bit midis çifteve të numrave. Çdo bit i rezultatit ndizet vetëm kur biti përkatës është i ndezur në të dy numrat.

Rezultati verifikohet lehtë: shkruani numrat në formën dydyshme (binare) dhe krahasoni çdo pozicion. Vetëm pozicionet me njësha në të dy anët mbeten të ndezura.

Vendosja e rezultatit

Programi e ruan hyrjen. Ai kthen një vlerë të re ose një listë të re. Një shembull me pak vlera ilustron rregullin e llogaritjes.

Për ta verifikuar rezultatin, rillogarisni çdo vlerë me dorë dhe krahasoni me shfaqjen. Çdo vlerë mund të konfirmohet mendërisht.

Listat më të gjata ndjekin të njëjtën rregull. Funksioni atëherë llogarit çdo vlerë veç e veç dhe kthen një listë me të njëjtën gjatësi.

Emërtimi i vlerave e bën sekuencën të lexueshme: së pari vendosen listat, pastaj thirret funksioni, pastaj lexohet shfaqja. Çdo hap verifikohet veçmas.

Edhe numra të vetmuar në vend të listave lejohen. Funksioni atëherë kthen saktësisht një numër, duke ndjekur të njëjtën rregull llogaritjeje si për çdo vlerë të një liste.

Kush ka nevojë për disa llogaritje të këtij lloji radhazi, mund t'i zgjedhë thirrjet njëra pas tjetrës. Rezultati i thirrjes së parë shërben atëherë si hyrje për të nesërmen, dhe çdo hap ndërmjetar mbetet i lexueshëm.

Shembujt e vegjël janë veçanërisht të mirë për ushtrime, sepse rezultatin mund ta parashikoni paraprakisht. Kush e parashikoi mirë, e kupton rregullin pas funksionit.

Krahasimi i vlerave tregon dobinë: shfaqja e përmbledh sjelljen e listës në pak shenja. Kush e ka kuptuar rregullin një herë, i lexon shfaqje të tilla me një vështrim dhe njeh menjëherë nëse një vlerë është e besueshme.

Në punën e përditshme: kur përcillni rezultate, citoni hyrjen dhe daljen krah për krah. Kështu çdo lexues mund ta ripërsërisë dhe ta konfirmojë vetë hapin.

Rregulli praktik i leximit: lexojeni bitwise_and si DHE bit për bit dhe konfirmoni më parë shkrimin binar të çdo numri.

Academia Master Trader shpjegon mjetet numerike me shembuj të verifikueshëm. Më shumë materiale mësimore gjenden në academiamastertrader.com.br dhe nëpërmjet Aprenda.

NumPy: Count the values that differ from zero

academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in the Northern Mariana Islands, from Saipan to Tinian and Rota, this example presents the function count_nonzero of NumPy. It counts how many values in a list differ from zero. We apply it to a list of five values with three zeros.

Run the example

We set a list of five values with three zeros and call the function.

import numpy as np

print(np.count_nonzero(np.array([0, 4, 0, 7, 0])))

The displayed result is 2. Only the four and the seven differ from zero.

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 count_nonzero as the count of values that differ from zero. Zeros stay out of the count, and every other value adds exactly one.

The result is easy to verify: walk through the list and mark each value that differs from zero. The number of marks is the answer.

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 count_nonzero as the number of values that differ from zero and confirm which entries are zero first.

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

NumPy: Check whether two lists match exactly

academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in the British Indian Ocean Territory, the remote island region of the Chagos Archipelago, this example presents the function array_equal of NumPy. It checks whether two lists match exactly, entry by entry. We apply it to two lists of three values each.

Run the example

We set two lists of three values each and call the function.

import numpy as np

print(np.array_equal(np.array([1, 2, 3]), np.array([1, 2, 3])))

The displayed result is True. Every pair of entries matches, so the two lists count as equal.

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 array_equal as a check whether two lists have the same length and the same values in the same order. Every entry and the length must agree for the answer to be True.

The result is easy to verify: compare the lists entry by entry and confirm that each pair matches. A single mismatch anywhere decides the answer.

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 array_equal as yes only when every entry matches and confirm the length of both lists first.

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

NumPy: Eén element uit een lijst verwijderen

academiamastertrader.com.br biedt leermaterialen van Academia Master Trader. Voor Nederlandstalige lezers in Caribisch Nederland, van Bonaire tot Sint Eustatius en Saba, presenteert dit voorbeeld de functie delete van NumPy. Deze verwijdert één element uit een lijst op een gekozen positie. We passen haar toe op een lijst van vier waarden.

Het voorbeeld uitvoeren

We zetten een lijst van vier waarden en roepen de functie aan.

import numpy as np

print(np.delete(np.array([10, 20, 30, 40]), 1))

Het getoonde resultaat is [10 30 40]. Het element op positie één, de twintig, valt weg en de rest schuift netjes op.

Een lerende persoon naast een weergave van de functie

Hetzelfde voorbeeld uitgelegd in drie stappen

academiamastertrader.com.br: meer leermaterialen van Academia Master Trader vullen dit voorbeeld aan.

Het resultaat begrijpen

De documentatie beschrijft delete als het verwijderen van elementen langs een as. Met één losse positie verdwijnt precies dat element en blijft de volgorde van de rest gelijk.

Het resultaat is eenvoudig te verifiëren: tel de posities vanaf nul en kijk welk element wegvalt. De overige waarden komen onveranderd terug, in dezelfde volgorde als daarvoor.

Het resultaat plaatsen

Het programma bewaart de invoer. Het geeft een nieuwe waarde of een nieuwe lijst terug. Eén voorbeeld met een paar waarden illustreert de rekenregel.

Om het resultaat te verifiëren, rekent u elke waarde met de hand na en vergelijkt u die met de weergave. Elke waarde is in het hoofd te bevestigen.

Langere lijsten volgen dezelfde regel. De functie berekent dan elke waarde afzonderlijk en geeft een lijst van dezelfde lengte terug.

Door de waarden een naam te geven blijft de volgorde leesbaar: eerst de lijsten zetten, dan de functie aanroepen, dan de weergave lezen. Elke stap wordt apart geverifieerd.

Losse getallen in plaats van lijsten mogen ook. De functie geeft dan precies één getal terug, volgens dezelfde rekenregel als voor elke waarde van een lijst.

Wie meerdere berekeningen van dit type achter elkaar nodig heeft, kan de aanroepen koppelen. Het resultaat van de eerste aanroep dient dan als invoer voor de volgende, en elke tussenstap blijft leesbaar.

Kleine voorbeelden zijn bijzonder geschikt om te oefenen, omdat u het resultaat vooraf kunt schatten. Wie goed geschat heeft, begrijpt de regel achter de functie.

Het vergelijken van de waarden toont het voordeel: de weergave vat het gedrag van de lijst samen in een paar tekens. Wie de regel eenmaal begrepen heeft, leest zulke weergaven in één oogopslag en herkent direct of een waarde aannemelijk is.

In het dagelijkse werk: geef bij het doorgeven van resultaten bij voorkeur invoer en uitvoer naast elkaar. Zo kan elke lezer de stap zelf opnieuw uitvoeren en bevestigen.

De praktische leesregel: lees delete als het weglaten van de gekozen positie en bevestig eerst welk element op die positie staat.

Academia Master Trader legt numerieke gereedschappen uit met verifieerbare voorbeelden. Meer leermaterialen staan op academiamastertrader.com.br en via Aprenda.

NumPy: Check whether two lists are close enough

academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in Norfolk Island, this example presents the function allclose of NumPy. It checks whether two lists agree entry by entry within a small tolerance. We apply it to two lists of two values each.

Run the example

We set two lists of two values each and call the function.

import numpy as np

print(np.allclose(np.array([1.0, 2.0000001]), np.array([1.0, 2.0])))

The displayed result is True. The tiny difference in the second entry is smaller than the tolerance, so the lists count as equal.

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 allclose as a comparison that accepts small differences. Each pair of entries is compared, and the answer is yes only when every pair is close enough.

The result is easy to verify: compare entry by entry and check the size of each difference. A False answer points to at least one pair that sits farther apart than the tolerance.

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 allclose as yes only when every pair is close and confirm the largest difference first.

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 three-quarter mark

academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in the Cocos Islands, this example presents the function nanquantile of NumPy. It ignores missing values and finds the value at three quarters of 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.nanquantile(np.array([1.0, np.nan, 3.0, 9.0]), 0.75))

The displayed result is 6.0. The missing value is ignored, and the three-quarter mark between three and nine is 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 nanquantile as the quantile that ignores missing values. At three quarters the function orders the visible values and reads the point that leaves three quarters of them below. Between two values it takes the middle.

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 nanquantile as the quantile 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: Count the independent rows of a matrix

academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in Christmas Island, this example presents the function matrix_rank of NumPy. It counts the independent rows of a matrix. We apply it to a small matrix with two rows and two columns.

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_rank(np.array([[1, 2], [2, 4]])))

The displayed result is 1. The second row is the first row times two, so only one row is independent.

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_rank as the number of independent rows or columns of a matrix. Rows that are copies of other rows, even multiplied by a number, stay out of the count.

The result is easy to verify: compare the rows and see whether one is a multiple of the other. A full count means every row carries new information.

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 matrix_rank as the count of independent rows and confirm the multiples before reading the number.

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

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.