<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Academia Master Trader</title>
    <link>https://paper.wf/academiamastertrader/</link>
    <description>Laboratórios de leitura de gráficos e conceitos financeiros. Projeto educacional brasileiro. Exemplos fictícios, sem recomendação de investimento.</description>
    <pubDate>Sun, 29 Nov 2026 03:02:49 +0000</pubDate>
    <item>
      <title>NumPy rot90 turns an array in quarter rotations within a chosen pair of axes</title>
      <link>https://paper.wf/academiamastertrader/numpy-rot90-turns-an-array-in-quarter-rotations-within-a-chosen-pair-of-axes</link>
      <description>&lt;![CDATA[NumPy rot90 turns an array in quarter rotations within a chosen pair of axes&#xA;&#xA;A quarter turn rearranges positions across two axes. It does not multiply values by ninety or calculate an angle for every entry. NumPy rot90 expresses that rearrangement with a rotation count and a pair of axes. Academia Master Trader presents this English lesson for readers in Thailand, using a small constructed matrix to make each moved position and each resulting shape easy to follow.&#xA;&#xA;Follow the first quarter turn&#xA;&#xA;After import numpy as np, define m = np.array([[1,4,7],[2,5,8]]). This matrix has two rows and three columns, so its shape is (2,3). The call np.rot90(m) returns [[7,8],[4,5],[1,2]]. With the default axis pair and rotation count, the two dimensional arrangement turns counterclockwise by ninety degrees.&#xA;&#xA;The final source column, containing seven and eight, becomes the first output row. The first source column, containing one and two, becomes the final output row. There are still six entries, but the resulting shape is (3,2). A quarter turn can change an array&#39;s shape without adding or removing entries.&#xA;&#xA;NumPy rot90&#xA;&#xA;Count quarter turns rather than degrees&#xA;&#xA;The argument k counts ninety degree turns. The call np.rot90(m,k=2) returns [[8,5,2],[7,4,1]], which is a half turn of the original arrangement. Its shape is (2,3), the same as the input. The values have moved even though the shape has returned to the original pair of lengths.&#xA;&#xA;The call np.rot90(m,k=4) restores the original arrangement after four quarter turns. Passing k=90 does not request a ninety degree turn. It requests ninety quarter turns. Keeping the unit of the argument explicit prevents a number that looks familiar from expressing a different operation.&#xA;&#xA;Reverse the direction with a negative count&#xA;&#xA;The call np.rot90(m,k=-1) returns [[2,1],[5,4],[8,7]]. For this default plane, a negative quarter turn goes clockwise. Its output also has shape (3,2), but its entries differ from the positive quarter turn.&#xA;&#xA;Shape alone cannot identify the direction used. Compare a known corner or a complete row with the source when explaining the result. In this example, two moves from the lower left source corner to the upper left output corner under the clockwise turn.&#xA;&#xA;Keep the axis order explicit&#xA;&#xA;The default axis pair is (0,1). Reversing that pair reverses the direction: np.rot90(m,axes=(1,0)) gives the same arrangement as np.rot90(m,k=-1). Both calls make the clockwise quarter turn shown above.&#xA;&#xA;The two axes must be different. For an array with more than two dimensions, the selected pair defines the plane of the turn. Name those dimensions before using the operation, because an axis number does not explain whether it represents rows, columns, layers or another recorded dimension.&#xA;&#xA;A rotated view can share the original data&#xA;&#xA;The documentation describes the result as a rotated view. With an ordinary NumPy array, that means the result can share underlying data with its source rather than hold a separate set of entries. The rearrangement itself does not replace the input values, but writing through the returned view can affect the original array.&#xA;&#xA;Starting again from m, set r = np.rot90(m). Writing r0,0] = 99 also changes m[0,2] to ninety nine. Use an explicit copy when independent editing is required. Continue learning with Academia Master Trader at academiamastertrader.com.br and in [Aprenda. Record the axis pair, quarter turn count and resulting shape alongside the rearranged entries.]]&gt;</description>
      <content:encoded><![CDATA[<p>NumPy rot90 turns an array in quarter rotations within a chosen pair of axes</p>

<p>A quarter turn rearranges positions across two axes. It does not multiply values by ninety or calculate an angle for every entry. NumPy rot90 expresses that rearrangement with a rotation count and a pair of axes. Academia Master Trader presents this English lesson for readers in Thailand, using a small constructed matrix to make each moved position and each resulting shape easy to follow.</p>

<h2 id="follow-the-first-quarter-turn">Follow the first quarter turn</h2>

<p>After <code>import numpy as np</code>, define <code>m = np.array([[1,4,7],[2,5,8]])</code>. This matrix has two rows and three columns, so its shape is <code>(2,3)</code>. The call <code>np.rot90(m)</code> returns <code>[[7,8],[4,5],[1,2]]</code>. With the default axis pair and rotation count, the two dimensional arrangement turns counterclockwise by ninety degrees.</p>

<p>The final source column, containing seven and eight, becomes the first output row. The first source column, containing one and two, becomes the final output row. There are still six entries, but the resulting shape is <code>(3,2)</code>. A quarter turn can change an array&#39;s shape without adding or removing entries.</p>

<p><img src="https://academiamastertrader.com.br/materiais/img/aula1460.png" alt="NumPy rot90"></p>

<h2 id="count-quarter-turns-rather-than-degrees">Count quarter turns rather than degrees</h2>

<p>The argument k counts ninety degree turns. The call <code>np.rot90(m,k=2)</code> returns <code>[[8,5,2],[7,4,1]]</code>, which is a half turn of the original arrangement. Its shape is <code>(2,3)</code>, the same as the input. The values have moved even though the shape has returned to the original pair of lengths.</p>

<p>The call <code>np.rot90(m,k=4)</code> restores the original arrangement after four quarter turns. Passing <code>k=90</code> does not request a ninety degree turn. It requests ninety quarter turns. Keeping the unit of the argument explicit prevents a number that looks familiar from expressing a different operation.</p>

<h2 id="reverse-the-direction-with-a-negative-count">Reverse the direction with a negative count</h2>

<p>The call <code>np.rot90(m,k=-1)</code> returns <code>[[2,1],[5,4],[8,7]]</code>. For this default plane, a negative quarter turn goes clockwise. Its output also has shape <code>(3,2)</code>, but its entries differ from the positive quarter turn.</p>

<p>Shape alone cannot identify the direction used. Compare a known corner or a complete row with the source when explaining the result. In this example, two moves from the lower left source corner to the upper left output corner under the clockwise turn.</p>

<h2 id="keep-the-axis-order-explicit">Keep the axis order explicit</h2>

<p>The default axis pair is <code>(0,1)</code>. Reversing that pair reverses the direction: <code>np.rot90(m,axes=(1,0))</code> gives the same arrangement as <code>np.rot90(m,k=-1)</code>. Both calls make the clockwise quarter turn shown above.</p>

<p>The two axes must be different. For an array with more than two dimensions, the selected pair defines the plane of the turn. Name those dimensions before using the operation, because an axis number does not explain whether it represents rows, columns, layers or another recorded dimension.</p>

<h2 id="a-rotated-view-can-share-the-original-data">A rotated view can share the original data</h2>

<p>The documentation describes the result as a rotated view. With an ordinary NumPy array, that means the result can share underlying data with its source rather than hold a separate set of entries. The rearrangement itself does not replace the input values, but writing through the returned view can affect the original array.</p>

<p>Starting again from m, set <code>r = np.rot90(m)</code>. Writing <code>r[0,0] = 99</code> also changes <code>m[0,2]</code> to ninety nine. Use an explicit copy when independent editing is required. Continue learning with Academia Master Trader at academiamastertrader.com.br and in <a href="https://academiamastertrader.com.br/materiais/aprenda/" rel="nofollow">Aprenda</a>. Record the axis pair, quarter turn count and resulting shape alongside the rearranged entries.</p>
]]></content:encoded>
      <guid>https://paper.wf/academiamastertrader/numpy-rot90-turns-an-array-in-quarter-rotations-within-a-chosen-pair-of-axes</guid>
      <pubDate>Sun, 29 Nov 2026 03:00:18 +0000</pubDate>
    </item>
    <item>
      <title>NumPy roll shifts array entries with wraparound while keeping their original...</title>
      <link>https://paper.wf/academiamastertrader/numpy-roll-shifts-array-entries-with-wraparound-while-keeping-their-original</link>
      <description>&lt;![CDATA[NumPy roll shifts array entries with wraparound while keeping their original shape&#xA;&#xA;A circular shift moves entries through an array and brings the entries that cross one end back at the other end. NumPy roll performs that wraparound rearrangement. Academia Master Trader presents this English lesson for readers in Indonesia. Constructed examples explain positive and negative shifts, matrix axes and the default flattened path, without confusing wraparound with a time lag that introduces empty positions.&#xA;&#xA;Move entries by a stated number of places&#xA;&#xA;After import numpy as np, define a = np.array([2,5,8,11]). The call np.roll(a,1) returns [11,2,5,8]. Each entry moves one position toward a higher index, and eleven wraps from the final position to the first. The four entry shape (4,) is preserved.&#xA;&#xA;The call np.roll(a,2) returns [8,11,2,5]. Two entries wrap around rather than disappearing. No new zero or missing value is inserted. The output contains the original entries in a circularly shifted arrangement, not their arithmetic differences or a new set of measured values.&#xA;&#xA;NumPy roll&#xA;&#xA;A negative shift moves the opposite way&#xA;&#xA;The call np.roll(a,-1) returns [5,8,11,2]. Five moves into the first position, and two wraps from the beginning to the end. The sign of the shift controls the direction of movement; it does not negate the input values.&#xA;&#xA;For this four entry vector, a shift of four returns the same arrangement as the input. A shift of five gives the same arrangement as a shift of one. Circular movement repeats after a complete turn through the selected length. Record the shift and the axis length when explaining equivalent arrangements.&#xA;&#xA;An explicit axis keeps matrix boundaries clear&#xA;&#xA;Define m = np.array([[1,4,7],[2,5,8]]). The call np.roll(m,1,axis=0) returns [[2,5,8],[1,4,7]]. Each row moves one row position, with the final row returning at the beginning. The entries inside each row keep their order.&#xA;&#xA;The call np.roll(m,1,axis=1) returns [[7,1,4],[8,2,5]]. Each row is shifted across its columns, and its last entry returns at the start of that same row. The matrix retains shape (2,3), but the two axis choices describe different rearrangements.&#xA;&#xA;Name the data meaning of each axis before choosing one. A row might represent a category, an observation or something else entirely. Roll does not inspect those meanings and does not automatically move separately stored labels with the numeric entries.&#xA;&#xA;The default uses a flattened path&#xA;&#xA;The call np.roll(m,1) returns [[8,1,4],[7,2,5]]. Without an axis argument, NumPy flattens the array before shifting and restores the original shape afterward. The shape remains (2,3), but entries can cross the old row boundary during the flattened movement.&#xA;&#xA;The final source entry, eight, becomes the first output entry. Seven crosses from the end of the first source row into the beginning of the second output row. This is different from shifting each row independently. An unchanged matrix shape does not prove that its original row groups were kept together.&#xA;&#xA;Wraparound is a choice about the boundary&#xA;&#xA;A circular shift is appropriate only when that boundary behavior matches the intended calculation. If the goal is a previous observation column with an empty first position, roll alone does not supply it. Its first output can contain the final observation, which came from the other end of the sequence.&#xA;&#xA;Keep the transformation distinct from any interpretation of cause, prediction or chronological availability. Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. State the shift, selected axis and wraparound rule so every relocated entry can be traced to its source position.]]&gt;</description>
      <content:encoded><![CDATA[<p>NumPy roll shifts array entries with wraparound while keeping their original shape</p>

<p>A circular shift moves entries through an array and brings the entries that cross one end back at the other end. NumPy roll performs that wraparound rearrangement. Academia Master Trader presents this English lesson for readers in Indonesia. Constructed examples explain positive and negative shifts, matrix axes and the default flattened path, without confusing wraparound with a time lag that introduces empty positions.</p>

<h2 id="move-entries-by-a-stated-number-of-places">Move entries by a stated number of places</h2>

<p>After <code>import numpy as np</code>, define <code>a = np.array([2,5,8,11])</code>. The call <code>np.roll(a,1)</code> returns <code>[11,2,5,8]</code>. Each entry moves one position toward a higher index, and eleven wraps from the final position to the first. The four entry shape <code>(4,)</code> is preserved.</p>

<p>The call <code>np.roll(a,2)</code> returns <code>[8,11,2,5]</code>. Two entries wrap around rather than disappearing. No new zero or missing value is inserted. The output contains the original entries in a circularly shifted arrangement, not their arithmetic differences or a new set of measured values.</p>

<p><img src="https://academiamastertrader.com.br/materiais/img/aula1459.png" alt="NumPy roll"></p>

<h2 id="a-negative-shift-moves-the-opposite-way">A negative shift moves the opposite way</h2>

<p>The call <code>np.roll(a,-1)</code> returns <code>[5,8,11,2]</code>. Five moves into the first position, and two wraps from the beginning to the end. The sign of the shift controls the direction of movement; it does not negate the input values.</p>

<p>For this four entry vector, a shift of four returns the same arrangement as the input. A shift of five gives the same arrangement as a shift of one. Circular movement repeats after a complete turn through the selected length. Record the shift and the axis length when explaining equivalent arrangements.</p>

<h2 id="an-explicit-axis-keeps-matrix-boundaries-clear">An explicit axis keeps matrix boundaries clear</h2>

<p>Define <code>m = np.array([[1,4,7],[2,5,8]])</code>. The call <code>np.roll(m,1,axis=0)</code> returns <code>[[2,5,8],[1,4,7]]</code>. Each row moves one row position, with the final row returning at the beginning. The entries inside each row keep their order.</p>

<p>The call <code>np.roll(m,1,axis=1)</code> returns <code>[[7,1,4],[8,2,5]]</code>. Each row is shifted across its columns, and its last entry returns at the start of that same row. The matrix retains shape <code>(2,3)</code>, but the two axis choices describe different rearrangements.</p>

<p>Name the data meaning of each axis before choosing one. A row might represent a category, an observation or something else entirely. Roll does not inspect those meanings and does not automatically move separately stored labels with the numeric entries.</p>

<h2 id="the-default-uses-a-flattened-path">The default uses a flattened path</h2>

<p>The call <code>np.roll(m,1)</code> returns <code>[[8,1,4],[7,2,5]]</code>. Without an axis argument, NumPy flattens the array before shifting and restores the original shape afterward. The shape remains <code>(2,3)</code>, but entries can cross the old row boundary during the flattened movement.</p>

<p>The final source entry, eight, becomes the first output entry. Seven crosses from the end of the first source row into the beginning of the second output row. This is different from shifting each row independently. An unchanged matrix shape does not prove that its original row groups were kept together.</p>

<h2 id="wraparound-is-a-choice-about-the-boundary">Wraparound is a choice about the boundary</h2>

<p>A circular shift is appropriate only when that boundary behavior matches the intended calculation. If the goal is a previous observation column with an empty first position, roll alone does not supply it. Its first output can contain the final observation, which came from the other end of the sequence.</p>

<p>Keep the transformation distinct from any interpretation of cause, prediction or chronological availability. Continue learning with Academia Master Trader at academiamastertrader.com.br and in <a href="https://academiamastertrader.com.br/materiais/aprenda/" rel="nofollow">Aprenda</a>. State the shift, selected axis and wraparound rule so every relocated entry can be traced to its source position.</p>
]]></content:encoded>
      <guid>https://paper.wf/academiamastertrader/numpy-roll-shifts-array-entries-with-wraparound-while-keeping-their-original</guid>
      <pubDate>Sun, 29 Nov 2026 02:55:22 +0000</pubDate>
    </item>
    <item>
      <title>NumPy flip reverses array positions along selected axes while preserving shape</title>
      <link>https://paper.wf/academiamastertrader/numpy-flip-reverses-array-positions-along-selected-axes-while-preserving-shape</link>
      <description>&lt;![CDATA[NumPy flip reverses array positions along selected axes while preserving shape&#xA;&#xA;Reversing an array changes where its entries appear without sorting their numeric values. NumPy flip reverses the order along one or more selected axes and preserves the array shape. Academia Master Trader presents this English lesson for readers in Vietnam. Constructed examples distinguish a reversed vector, a matrix with reversed rows, and a matrix with reversed columns, while explaining why the returned view needs careful handling.&#xA;&#xA;Reverse a vector in its existing order&#xA;&#xA;After import numpy as np, define a = np.array([4,1,9,2]). The call np.flip(a) returns [2,9,1,4]. The final input entry becomes the first output entry, and the first becomes the last. All four entries are retained, so the shape remains (4,).&#xA;&#xA;The output is not sorted from smallest to largest or largest to smallest. Nine stays ahead of one because their positions were reversed together with the rest of the sequence. Flip uses the supplied arrangement as its starting point. If the vector represents observations over time, reversing it also reverses their positional order; it does not change the observation dates themselves.&#xA;&#xA;NumPy flip&#xA;&#xA;Axis zero reverses the row order&#xA;&#xA;Define m = np.array([[1,4,7],[2,5,8]]). The call np.flip(m,axis=0) returns [[2,5,8],[1,4,7]]. The second row now appears first, while the entries within each row retain their original order. The matrix shape stays (2,3).&#xA;&#xA;The values one, four and seven still belong to the same row as one another. The operation changes the row positions, not the column positions inside each row. Keep any corresponding row labels aligned with the same reversal if those labels are stored separately from the numeric matrix.&#xA;&#xA;Axis one reverses entries across each row&#xA;&#xA;The call np.flip(m,axis=1) returns [[7,4,1],[8,5,2]]. Each row remains in its original row position, but the columns appear in the opposite order. The first column becomes the last, and the last becomes the first. Shape (2,3) is preserved again.&#xA;&#xA;For this matrix, axis=-1 refers to the last axis and gives the same result as axis one. A negative axis number is a way to name an axis from the end, not a request to negate the numeric entries. Values retain their signs unless another operation changes them.&#xA;&#xA;The default reverses every axis&#xA;&#xA;The call np.flip(m) returns [[8,5,2],[7,4,1]]. With no axis specified, flip reverses all axes. Here that means reversing both the row order and the column order. It is different from reversing only the rows or only the columns.&#xA;&#xA;The explicit call np.flip(m,axis=(0,1)) gives the same result for this two dimensional matrix. Flip does not exchange the meanings of rows and columns as a transpose would. A two by three matrix stays two by three, even when all of its axes are reversed.&#xA;&#xA;The result is a view of the source&#xA;&#xA;The documentation describes the returned result as a view. With a normal NumPy array, that means the reversed arrangement can share its underlying data with the original rather than holding an independent set of values. The reversal itself does not assign new numbers into m, but later writes through the view can affect the source.&#xA;&#xA;For example, set v = np.flip(m,axis=1). Writing v0,0] = 99 also changes m[0,2] to ninety nine. Use an explicit copy when an independently editable result is required. Continue learning with Academia Master Trader at academiamastertrader.com.br and in [Aprenda. Record the selected axes, preserved shape and whether later work will edit a shared view or a separate copy.]]&gt;</description>
      <content:encoded><![CDATA[<p>NumPy flip reverses array positions along selected axes while preserving shape</p>

<p>Reversing an array changes where its entries appear without sorting their numeric values. NumPy flip reverses the order along one or more selected axes and preserves the array shape. Academia Master Trader presents this English lesson for readers in Vietnam. Constructed examples distinguish a reversed vector, a matrix with reversed rows, and a matrix with reversed columns, while explaining why the returned view needs careful handling.</p>

<h2 id="reverse-a-vector-in-its-existing-order">Reverse a vector in its existing order</h2>

<p>After <code>import numpy as np</code>, define <code>a = np.array([4,1,9,2])</code>. The call <code>np.flip(a)</code> returns <code>[2,9,1,4]</code>. The final input entry becomes the first output entry, and the first becomes the last. All four entries are retained, so the shape remains <code>(4,)</code>.</p>

<p>The output is not sorted from smallest to largest or largest to smallest. Nine stays ahead of one because their positions were reversed together with the rest of the sequence. Flip uses the supplied arrangement as its starting point. If the vector represents observations over time, reversing it also reverses their positional order; it does not change the observation dates themselves.</p>

<p><img src="https://academiamastertrader.com.br/materiais/img/aula1458.png" alt="NumPy flip"></p>

<h2 id="axis-zero-reverses-the-row-order">Axis zero reverses the row order</h2>

<p>Define <code>m = np.array([[1,4,7],[2,5,8]])</code>. The call <code>np.flip(m,axis=0)</code> returns <code>[[2,5,8],[1,4,7]]</code>. The second row now appears first, while the entries within each row retain their original order. The matrix shape stays <code>(2,3)</code>.</p>

<p>The values one, four and seven still belong to the same row as one another. The operation changes the row positions, not the column positions inside each row. Keep any corresponding row labels aligned with the same reversal if those labels are stored separately from the numeric matrix.</p>

<h2 id="axis-one-reverses-entries-across-each-row">Axis one reverses entries across each row</h2>

<p>The call <code>np.flip(m,axis=1)</code> returns <code>[[7,4,1],[8,5,2]]</code>. Each row remains in its original row position, but the columns appear in the opposite order. The first column becomes the last, and the last becomes the first. Shape <code>(2,3)</code> is preserved again.</p>

<p>For this matrix, <code>axis=-1</code> refers to the last axis and gives the same result as axis one. A negative axis number is a way to name an axis from the end, not a request to negate the numeric entries. Values retain their signs unless another operation changes them.</p>

<h2 id="the-default-reverses-every-axis">The default reverses every axis</h2>

<p>The call <code>np.flip(m)</code> returns <code>[[8,5,2],[7,4,1]]</code>. With no axis specified, flip reverses all axes. Here that means reversing both the row order and the column order. It is different from reversing only the rows or only the columns.</p>

<p>The explicit call <code>np.flip(m,axis=(0,1))</code> gives the same result for this two dimensional matrix. Flip does not exchange the meanings of rows and columns as a transpose would. A two by three matrix stays two by three, even when all of its axes are reversed.</p>

<h2 id="the-result-is-a-view-of-the-source">The result is a view of the source</h2>

<p>The documentation describes the returned result as a view. With a normal NumPy array, that means the reversed arrangement can share its underlying data with the original rather than holding an independent set of values. The reversal itself does not assign new numbers into m, but later writes through the view can affect the source.</p>

<p>For example, set <code>v = np.flip(m,axis=1)</code>. Writing <code>v[0,0] = 99</code> also changes <code>m[0,2]</code> to ninety nine. Use an explicit copy when an independently editable result is required. Continue learning with Academia Master Trader at academiamastertrader.com.br and in <a href="https://academiamastertrader.com.br/materiais/aprenda/" rel="nofollow">Aprenda</a>. Record the selected axes, preserved shape and whether later work will edit a shared view or a separate copy.</p>
]]></content:encoded>
      <guid>https://paper.wf/academiamastertrader/numpy-flip-reverses-array-positions-along-selected-axes-while-preserving-shape</guid>
      <pubDate>Sun, 29 Nov 2026 02:51:54 +0000</pubDate>
    </item>
    <item>
      <title>NumPy tile repeats an array as blocks according to repetition counts by axis</title>
      <link>https://paper.wf/academiamastertrader/numpy-tile-repeats-an-array-as-blocks-according-to-repetition-counts-by-axis</link>
      <description>&lt;![CDATA[NumPy tile repeats an array as blocks according to repetition counts by axis&#xA;&#xA;Some array layouts require a whole pattern to appear several times. NumPy tile constructs such a layout by repeating an array as blocks. Academia Master Trader presents this English lesson for readers in Cambodia. Constructed examples explain how repetition counts relate to axes, why a vector can become a matrix, and how block repetition differs from making consecutive copies of each individual entry.&#xA;&#xA;Repeat the complete vector pattern&#xA;&#xA;After import numpy as np, define a = np.array([2,5,8]). The call np.tile(a,2) returns [2,5,8,2,5,8]. The original three entry pattern appears twice in sequence, producing six output entries. The order inside each block stays two, five, eight.&#xA;&#xA;This differs from [2,2,5,5,8,8], where each entry appears twice consecutively. Both arrangements contain two copies of each value, but their positions differ. A later calculation that depends on neighboring values can therefore receive a different arrangement. Choose the intended layout before deciding whether to repeat blocks or individual entries.&#xA;&#xA;NumPy tile&#xA;&#xA;Two repetition counts can create a matrix&#xA;&#xA;The call np.tile(a,(2,1)) returns [[2,5,8],[2,5,8]]. The output has shape (2,3). NumPy treats the vector as shape (1,3) for this two dimensional replication, then repeats that row twice. The second repetition count, one, keeps the three entry pattern once across each row.&#xA;&#xA;The call np.tile(a,(2,2)) returns [[2,5,8,2,5,8],[2,5,8,2,5,8]]. Its shape is (2,6): two rows, each containing two blocks of the vector. The repetition counts are not the requested final shape. They describe how many times the input layout is replicated along each corresponding axis.&#xA;&#xA;A matrix keeps its internal block layout&#xA;&#xA;Define m = np.array([[1,4],[7,9]]). The call np.tile(m,(2,1)) returns [[1,4],[7,9],[1,4],[7,9]]. It stacks two copies of the whole matrix block in the first axis direction. The result has shape (4,2).&#xA;&#xA;Notice the row order: first one and four, then seven and nine, followed by the same two rows again. Tile has not duplicated the first row consecutively before duplicating the second row. The original two row block is the repeated pattern, so its internal row order remains visible in every copy.&#xA;&#xA;A scalar count applies to the last matrix axis&#xA;&#xA;The call np.tile(m,2) returns [[1,4,1,4],[7,9,7,9]]. For a two dimensional input, this single repetition count is treated as (1,2). The first axis is repeated once and the last axis twice, producing shape (2,4).&#xA;&#xA;It does not create a flat vector and does not repeat the matrix twice along every axis. If the desired repetition is in the row direction, write (2,1) explicitly. Supplying one count can be concise, but naming both counts makes the intended matrix layout easier to inspect and explain.&#xA;&#xA;Shape promotion is part of the rule&#xA;&#xA;When the repetition count sequence has more dimensions than the input, NumPy adds leading axes to the input shape. When the input has more dimensions than the count sequence, leading ones are added to the counts. These rules align the shapes before constructing the repeated blocks.&#xA;&#xA;The documentation recommends broadcasting operations rather than tile when broadcasting is the actual purpose. Repeated storage is not automatically necessary merely because an arithmetic operation combines different compatible shapes. Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the input shape, repetition counts and output shape so each copied block has a clear place in the result.]]&gt;</description>
      <content:encoded><![CDATA[<p>NumPy tile repeats an array as blocks according to repetition counts by axis</p>

<p>Some array layouts require a whole pattern to appear several times. NumPy tile constructs such a layout by repeating an array as blocks. Academia Master Trader presents this English lesson for readers in Cambodia. Constructed examples explain how repetition counts relate to axes, why a vector can become a matrix, and how block repetition differs from making consecutive copies of each individual entry.</p>

<h2 id="repeat-the-complete-vector-pattern">Repeat the complete vector pattern</h2>

<p>After <code>import numpy as np</code>, define <code>a = np.array([2,5,8])</code>. The call <code>np.tile(a,2)</code> returns <code>[2,5,8,2,5,8]</code>. The original three entry pattern appears twice in sequence, producing six output entries. The order inside each block stays two, five, eight.</p>

<p>This differs from <code>[2,2,5,5,8,8]</code>, where each entry appears twice consecutively. Both arrangements contain two copies of each value, but their positions differ. A later calculation that depends on neighboring values can therefore receive a different arrangement. Choose the intended layout before deciding whether to repeat blocks or individual entries.</p>

<p><img src="https://academiamastertrader.com.br/materiais/img/aula1457.png" alt="NumPy tile"></p>

<h2 id="two-repetition-counts-can-create-a-matrix">Two repetition counts can create a matrix</h2>

<p>The call <code>np.tile(a,(2,1))</code> returns <code>[[2,5,8],[2,5,8]]</code>. The output has shape <code>(2,3)</code>. NumPy treats the vector as shape <code>(1,3)</code> for this two dimensional replication, then repeats that row twice. The second repetition count, one, keeps the three entry pattern once across each row.</p>

<p>The call <code>np.tile(a,(2,2))</code> returns <code>[[2,5,8,2,5,8],[2,5,8,2,5,8]]</code>. Its shape is <code>(2,6)</code>: two rows, each containing two blocks of the vector. The repetition counts are not the requested final shape. They describe how many times the input layout is replicated along each corresponding axis.</p>

<h2 id="a-matrix-keeps-its-internal-block-layout">A matrix keeps its internal block layout</h2>

<p>Define <code>m = np.array([[1,4],[7,9]])</code>. The call <code>np.tile(m,(2,1))</code> returns <code>[[1,4],[7,9],[1,4],[7,9]]</code>. It stacks two copies of the whole matrix block in the first axis direction. The result has shape <code>(4,2)</code>.</p>

<p>Notice the row order: first one and four, then seven and nine, followed by the same two rows again. Tile has not duplicated the first row consecutively before duplicating the second row. The original two row block is the repeated pattern, so its internal row order remains visible in every copy.</p>

<h2 id="a-scalar-count-applies-to-the-last-matrix-axis">A scalar count applies to the last matrix axis</h2>

<p>The call <code>np.tile(m,2)</code> returns <code>[[1,4,1,4],[7,9,7,9]]</code>. For a two dimensional input, this single repetition count is treated as <code>(1,2)</code>. The first axis is repeated once and the last axis twice, producing shape <code>(2,4)</code>.</p>

<p>It does not create a flat vector and does not repeat the matrix twice along every axis. If the desired repetition is in the row direction, write <code>(2,1)</code> explicitly. Supplying one count can be concise, but naming both counts makes the intended matrix layout easier to inspect and explain.</p>

<h2 id="shape-promotion-is-part-of-the-rule">Shape promotion is part of the rule</h2>

<p>When the repetition count sequence has more dimensions than the input, NumPy adds leading axes to the input shape. When the input has more dimensions than the count sequence, leading ones are added to the counts. These rules align the shapes before constructing the repeated blocks.</p>

<p>The documentation recommends broadcasting operations rather than tile when broadcasting is the actual purpose. Repeated storage is not automatically necessary merely because an arithmetic operation combines different compatible shapes. Continue learning with Academia Master Trader at academiamastertrader.com.br and in <a href="https://academiamastertrader.com.br/materiais/aprenda/" rel="nofollow">Aprenda</a>. Record the input shape, repetition counts and output shape so each copied block has a clear place in the result.</p>
]]></content:encoded>
      <guid>https://paper.wf/academiamastertrader/numpy-tile-repeats-an-array-as-blocks-according-to-repetition-counts-by-axis</guid>
      <pubDate>Sun, 29 Nov 2026 02:48:34 +0000</pubDate>
    </item>
    <item>
      <title>NumPy repeat duplicates entries consecutively along a selected array axis</title>
      <link>https://paper.wf/academiamastertrader/numpy-repeat-duplicates-entries-consecutively-along-a-selected-array-axis</link>
      <description>&lt;![CDATA[NumPy repeat duplicates entries consecutively along a selected array axis&#xA;&#xA;Repeating entries changes the arrangement and size of an array without creating new observations. NumPy repeat places copies of each entry consecutively along a selected axis. Academia Master Trader presents this English lesson for readers in Laos. Constructed examples distinguish element repetition, row repetition and a flattened result, so the returned values can be connected to the exact rule that created them.&#xA;&#xA;Repeat each entry before moving on&#xA;&#xA;After import numpy as np, define a = np.array([2,5,8]). The call np.repeat(a,2) returns [2,2,5,5,8,8]. Two appears twice, then five appears twice, then eight appears twice. The count two applies to each input entry, giving six output entries from three source entries.&#xA;&#xA;This is not the arrangement [2,5,8,2,5,8]. That arrangement repeats the whole sequence as a block. Repeat instead places the copies of each entry together before moving to the next entry. State which arrangement is needed before choosing an operation, particularly when both arrangements contain the same collection of values.&#xA;&#xA;NumPy repeat&#xA;&#xA;Counts can differ by position&#xA;&#xA;The call np.repeat(a,[1,3,2]) returns [2,5,5,5,8,8]. The first entry appears once, the second appears three times, and the third appears twice. The count array specifies repetitions associated with input positions, not output values to insert.&#xA;&#xA;A zero count leaves no copies of that entry in the result. For example, np.repeat(a,[1,0,2]) returns [2,8,8]. Five remains in the original a but contributes no output entry in this call. Track the count rule alongside the source if later work must explain why some entries appear more often than others.&#xA;&#xA;No axis means a flat output&#xA;&#xA;Define m = np.array([[1,4],[7,9]]). The default call np.repeat(m,2) returns [1,1,4,4,7,7,9,9]. Without an axis argument, NumPy uses the flattened input and returns a one dimensional array. The original matrix shape (2,2) is not retained in that result.&#xA;&#xA;The values follow the flattened arrangement: one and four from the first row, then seven and nine from the second. Each value is repeated in its turn. A flat output does not, by itself, preserve a separate row boundary. Keep the original shape when those boundaries carry meaning.&#xA;&#xA;An explicit axis repeats rows or columns&#xA;&#xA;The call np.repeat(m,2,axis=0) returns [[1,4],[1,4],[7,9],[7,9]]. It repeats each row consecutively, so the shape changes from (2,2) to (4,2). The columns remain paired within their corresponding rows.&#xA;&#xA;The call np.repeat(m,2,axis=1) returns [[1,1,4,4],[7,7,9,9]]. This repeats the entries along the column direction within each row, producing shape (2,4). Axis zero and axis one therefore create different layouts even when the repetition count is the same.&#xA;&#xA;Counts can also vary along the chosen axis. The call np.repeat(m,[1,2],axis=0) returns [[1,4],[7,9],[7,9]]. The first row appears once and the second twice. Check that the count arrangement fits the selected axis rather than assuming it describes every individual matrix entry.&#xA;&#xA;Copies do not add independent evidence&#xA;&#xA;Repeated values may help construct a required layout, but their presence does not establish additional measurements or independent cases. A longer array can still come entirely from the same small source. Keep the transformation separate from any interpretation of sample size or frequency.&#xA;&#xA;Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the source shape, chosen axis, repetition counts and output shape. Those details explain how the copies were arranged without assigning new meaning to duplicated values.]]&gt;</description>
      <content:encoded><![CDATA[<p>NumPy repeat duplicates entries consecutively along a selected array axis</p>

<p>Repeating entries changes the arrangement and size of an array without creating new observations. NumPy repeat places copies of each entry consecutively along a selected axis. Academia Master Trader presents this English lesson for readers in Laos. Constructed examples distinguish element repetition, row repetition and a flattened result, so the returned values can be connected to the exact rule that created them.</p>

<h2 id="repeat-each-entry-before-moving-on">Repeat each entry before moving on</h2>

<p>After <code>import numpy as np</code>, define <code>a = np.array([2,5,8])</code>. The call <code>np.repeat(a,2)</code> returns <code>[2,2,5,5,8,8]</code>. Two appears twice, then five appears twice, then eight appears twice. The count two applies to each input entry, giving six output entries from three source entries.</p>

<p>This is not the arrangement <code>[2,5,8,2,5,8]</code>. That arrangement repeats the whole sequence as a block. Repeat instead places the copies of each entry together before moving to the next entry. State which arrangement is needed before choosing an operation, particularly when both arrangements contain the same collection of values.</p>

<p><img src="https://academiamastertrader.com.br/materiais/img/aula1456.png" alt="NumPy repeat"></p>

<h2 id="counts-can-differ-by-position">Counts can differ by position</h2>

<p>The call <code>np.repeat(a,[1,3,2])</code> returns <code>[2,5,5,5,8,8]</code>. The first entry appears once, the second appears three times, and the third appears twice. The count array specifies repetitions associated with input positions, not output values to insert.</p>

<p>A zero count leaves no copies of that entry in the result. For example, <code>np.repeat(a,[1,0,2])</code> returns <code>[2,8,8]</code>. Five remains in the original a but contributes no output entry in this call. Track the count rule alongside the source if later work must explain why some entries appear more often than others.</p>

<h2 id="no-axis-means-a-flat-output">No axis means a flat output</h2>

<p>Define <code>m = np.array([[1,4],[7,9]])</code>. The default call <code>np.repeat(m,2)</code> returns <code>[1,1,4,4,7,7,9,9]</code>. Without an axis argument, NumPy uses the flattened input and returns a one dimensional array. The original matrix shape <code>(2,2)</code> is not retained in that result.</p>

<p>The values follow the flattened arrangement: one and four from the first row, then seven and nine from the second. Each value is repeated in its turn. A flat output does not, by itself, preserve a separate row boundary. Keep the original shape when those boundaries carry meaning.</p>

<h2 id="an-explicit-axis-repeats-rows-or-columns">An explicit axis repeats rows or columns</h2>

<p>The call <code>np.repeat(m,2,axis=0)</code> returns <code>[[1,4],[1,4],[7,9],[7,9]]</code>. It repeats each row consecutively, so the shape changes from <code>(2,2)</code> to <code>(4,2)</code>. The columns remain paired within their corresponding rows.</p>

<p>The call <code>np.repeat(m,2,axis=1)</code> returns <code>[[1,1,4,4],[7,7,9,9]]</code>. This repeats the entries along the column direction within each row, producing shape <code>(2,4)</code>. Axis zero and axis one therefore create different layouts even when the repetition count is the same.</p>

<p>Counts can also vary along the chosen axis. The call <code>np.repeat(m,[1,2],axis=0)</code> returns <code>[[1,4],[7,9],[7,9]]</code>. The first row appears once and the second twice. Check that the count arrangement fits the selected axis rather than assuming it describes every individual matrix entry.</p>

<h2 id="copies-do-not-add-independent-evidence">Copies do not add independent evidence</h2>

<p>Repeated values may help construct a required layout, but their presence does not establish additional measurements or independent cases. A longer array can still come entirely from the same small source. Keep the transformation separate from any interpretation of sample size or frequency.</p>

<p>Continue learning with Academia Master Trader at academiamastertrader.com.br and in <a href="https://academiamastertrader.com.br/materiais/aprenda/" rel="nofollow">Aprenda</a>. Record the source shape, chosen axis, repetition counts and output shape. Those details explain how the copies were arranged without assigning new meaning to duplicated values.</p>
]]></content:encoded>
      <guid>https://paper.wf/academiamastertrader/numpy-repeat-duplicates-entries-consecutively-along-a-selected-array-axis</guid>
      <pubDate>Sun, 29 Nov 2026 02:43:37 +0000</pubDate>
    </item>
    <item>
      <title>NumPy cumprod records successive products along an array in its supplied order</title>
      <link>https://paper.wf/academiamastertrader/numpy-cumprod-records-successive-products-along-an-array-in-its-supplied-order</link>
      <description>&lt;![CDATA[NumPy cumprod records successive products along an array in its supplied order&#xA;&#xA;Multiplication can be recorded as a sequence of intermediate results rather than only as a final product. NumPy cumprod returns those successive products along a chosen axis. Academia Master Trader presents this English lesson for readers in Mongolia. Constructed numerical examples explain the accumulation rule, the effect of zero, and the difference between flattening a matrix and working along one of its axes.&#xA;&#xA;Multiply through the current position&#xA;&#xA;After import numpy as np, define a = np.array([2,3,4,2]). The call np.cumprod(a) returns [2,6,24,48]. The first output is two. The next output is two times three. The third includes four as well, producing twenty four, and the last includes the final two to produce forty eight.&#xA;&#xA;There are four output entries, matching the number of input entries. Cumprod does not insert a separate initial one before the sequence. It does not add the values or multiply each entry by its numeric position. Each output includes every input from the beginning of this accumulation through the corresponding current position.&#xA;&#xA;NumPy cumprod&#xA;&#xA;Intermediate products depend on order&#xA;&#xA;Define b = np.array([4,2,2,3]). The call np.cumprod(b) returns [4,8,16,48]. These exact integer examples use the same factors and reach the same final product, but their intermediate results differ. The running sequence therefore describes the supplied arrangement, not only the collection of factors.&#xA;&#xA;Keep that order explicit when factors represent successive stages in a calculation. A cumulative product does not decide whether an arrangement follows time, category or another coordinate. Nor does it establish that multiplying the supplied quantities is appropriate. Record what each factor means before assigning an interpretation to the returned numbers.&#xA;&#xA;Zero carries through later finite products&#xA;&#xA;For z = np.array([2,0,5,3]), the call np.cumprod(z) returns [2,0,0,0]. Once zero has entered this ordinary finite integer example, each later multiplication remains zero. Five and three are still present in the input, but the cumulative result no longer reveals their individual values.&#xA;&#xA;A negative factor can change the sign of a nonzero running product. For example, np.cumprod([2,-3,4]) returns [2,-6,-24]. The result is a sequence of signed products, not absolute magnitudes. Keep the original factors if later work needs to distinguish the individual contributions that produced a total.&#xA;&#xA;The default combines a flattened matrix&#xA;&#xA;Define m = np.array([[2,3,2],[4,2,3]]). The default call np.cumprod(m) returns [2,6,12,48,96,288]. With no axis supplied, the input is flattened before accumulation. The result is a vector with six entries instead of a matrix shaped (2,3).&#xA;&#xA;The first factor of the second row multiplies the product already reached at the end of the first row. Thus the fourth output is forty eight, not four. That default behavior is useful only when one continuous sequence across the flattened layout matches the intended calculation.&#xA;&#xA;Choose an axis and accumulator type&#xA;&#xA;The call np.cumprod(m,axis=1) returns [[2,6,12],[4,8,24]]. Each row accumulates independently. The call np.cumprod(m,axis=0) returns [[2,3,2],[8,6,6]], accumulating down each column instead. Both explicit axis results preserve the matrix shape, but they describe different groups of factors.&#xA;&#xA;The dtype argument controls the output and accumulator type. Fixed width integer multiplication can overflow without raising an error, so choose a suitable type for the expected products. Changing the type does not decide the data meaning or guarantee exact arithmetic for every quantity. Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. State the factor order, axis and numeric type with every cumulative product.]]&gt;</description>
      <content:encoded><![CDATA[<p>NumPy cumprod records successive products along an array in its supplied order</p>

<p>Multiplication can be recorded as a sequence of intermediate results rather than only as a final product. NumPy cumprod returns those successive products along a chosen axis. Academia Master Trader presents this English lesson for readers in Mongolia. Constructed numerical examples explain the accumulation rule, the effect of zero, and the difference between flattening a matrix and working along one of its axes.</p>

<h2 id="multiply-through-the-current-position">Multiply through the current position</h2>

<p>After <code>import numpy as np</code>, define <code>a = np.array([2,3,4,2])</code>. The call <code>np.cumprod(a)</code> returns <code>[2,6,24,48]</code>. The first output is two. The next output is two times three. The third includes four as well, producing twenty four, and the last includes the final two to produce forty eight.</p>

<p>There are four output entries, matching the number of input entries. Cumprod does not insert a separate initial one before the sequence. It does not add the values or multiply each entry by its numeric position. Each output includes every input from the beginning of this accumulation through the corresponding current position.</p>

<p><img src="https://academiamastertrader.com.br/materiais/img/aula1455.png" alt="NumPy cumprod"></p>

<h2 id="intermediate-products-depend-on-order">Intermediate products depend on order</h2>

<p>Define <code>b = np.array([4,2,2,3])</code>. The call <code>np.cumprod(b)</code> returns <code>[4,8,16,48]</code>. These exact integer examples use the same factors and reach the same final product, but their intermediate results differ. The running sequence therefore describes the supplied arrangement, not only the collection of factors.</p>

<p>Keep that order explicit when factors represent successive stages in a calculation. A cumulative product does not decide whether an arrangement follows time, category or another coordinate. Nor does it establish that multiplying the supplied quantities is appropriate. Record what each factor means before assigning an interpretation to the returned numbers.</p>

<h2 id="zero-carries-through-later-finite-products">Zero carries through later finite products</h2>

<p>For <code>z = np.array([2,0,5,3])</code>, the call <code>np.cumprod(z)</code> returns <code>[2,0,0,0]</code>. Once zero has entered this ordinary finite integer example, each later multiplication remains zero. Five and three are still present in the input, but the cumulative result no longer reveals their individual values.</p>

<p>A negative factor can change the sign of a nonzero running product. For example, <code>np.cumprod([2,-3,4])</code> returns <code>[2,-6,-24]</code>. The result is a sequence of signed products, not absolute magnitudes. Keep the original factors if later work needs to distinguish the individual contributions that produced a total.</p>

<h2 id="the-default-combines-a-flattened-matrix">The default combines a flattened matrix</h2>

<p>Define <code>m = np.array([[2,3,2],[4,2,3]])</code>. The default call <code>np.cumprod(m)</code> returns <code>[2,6,12,48,96,288]</code>. With no axis supplied, the input is flattened before accumulation. The result is a vector with six entries instead of a matrix shaped <code>(2,3)</code>.</p>

<p>The first factor of the second row multiplies the product already reached at the end of the first row. Thus the fourth output is forty eight, not four. That default behavior is useful only when one continuous sequence across the flattened layout matches the intended calculation.</p>

<h2 id="choose-an-axis-and-accumulator-type">Choose an axis and accumulator type</h2>

<p>The call <code>np.cumprod(m,axis=1)</code> returns <code>[[2,6,12],[4,8,24]]</code>. Each row accumulates independently. The call <code>np.cumprod(m,axis=0)</code> returns <code>[[2,3,2],[8,6,6]]</code>, accumulating down each column instead. Both explicit axis results preserve the matrix shape, but they describe different groups of factors.</p>

<p>The dtype argument controls the output and accumulator type. Fixed width integer multiplication can overflow without raising an error, so choose a suitable type for the expected products. Changing the type does not decide the data meaning or guarantee exact arithmetic for every quantity. Continue learning with Academia Master Trader at academiamastertrader.com.br and in <a href="https://academiamastertrader.com.br/materiais/aprenda/" rel="nofollow">Aprenda</a>. State the factor order, axis and numeric type with every cumulative product.</p>
]]></content:encoded>
      <guid>https://paper.wf/academiamastertrader/numpy-cumprod-records-successive-products-along-an-array-in-its-supplied-order</guid>
      <pubDate>Sun, 29 Nov 2026 02:39:43 +0000</pubDate>
    </item>
    <item>
      <title>NumPy cumsum records running totals in the order an array is supplied</title>
      <link>https://paper.wf/academiamastertrader/numpy-cumsum-records-running-totals-in-the-order-an-array-is-supplied</link>
      <description>&lt;![CDATA[NumPy cumsum records running totals in the order an array is supplied&#xA;&#xA;A final total compresses a whole sequence into one number. A cumulative sum records the total reached at each position along that sequence. Academia Master Trader presents this English lesson for readers in Turkmenistan. NumPy cumsum provides the running totals, while the analyst remains responsible for choosing a meaningful order, axis and numeric type. Constructed examples show what each returned entry includes.&#xA;&#xA;Each output includes the current entry&#xA;&#xA;After import numpy as np, define a = np.array([3,2,-1,5]). The call np.cumsum(a) returns [3,5,4,9]. The first output is three. The second is three plus two. The third includes the next entry, minus one, so the running total becomes four. The last output includes all four entries and equals nine.&#xA;&#xA;The output has four entries rather than one. It does not automatically begin with a separate zero, and it is not an average. A negative input can make the cumulative sum decrease. The operation follows the sequence as supplied; it does not reorder values or infer which observation should come first.&#xA;&#xA;NumPy cumsum&#xA;&#xA;The path depends on the input order&#xA;&#xA;Reorder the same numbers as b = np.array([5,-1,2,3]). The call np.cumsum(b) returns [5,4,6,9]. The last value is again nine in these exact integer examples, but the intermediate totals differ. A running total therefore carries information about the chosen arrangement, not merely about the collection of values.&#xA;&#xA;If entries represent observations over time, keep the time coordinates and confirm their order separately. Cumsum does not inspect labels or decide whether the sequence is chronological. If entries belong to several unrelated groups, decide where accumulation should restart rather than treating a flattened collection as one continuous sequence without explanation.&#xA;&#xA;The default flattens a matrix&#xA;&#xA;Define m = np.array([[2,4,1],[3,5,2]]). The default call np.cumsum(m) returns [2,6,7,10,15,17]. With no axis specified, NumPy accumulates over the flattened array. The result is a one dimensional vector of six totals, even though the input has shape (2,3).&#xA;&#xA;Here the first row contributes two, four and one before the second row contributes three, five and two. The first total associated with the second row is ten, not three, because the default accumulation continues from the first row. Keep that boundary visible when interpreting a flattened result.&#xA;&#xA;An explicit axis preserves the matrix shape&#xA;&#xA;The call np.cumsum(m,axis=1) returns [[2,6,7],[3,8,10]]. It accumulates across each row independently. The second row begins at three because its running total does not include entries from the first row. Both input and output have shape (2,3).&#xA;&#xA;The call np.cumsum(m,axis=0) instead returns [[2,4,1],[5,9,3]]. It accumulates down each column. At the second row, five comes from two plus three, nine from four plus five, and three from one plus two. Name the data meaning of each axis before choosing the direction of accumulation.&#xA;&#xA;Choose a suitable numeric type&#xA;&#xA;The dtype argument controls the output and accumulator type. For example, np.cumsum(a,dtype=np.float64) returns floating point totals [3.,5.,4.,9.]. This changes their numeric representation, not the interpretation of the underlying entries.&#xA;&#xA;Fixed width integer arithmetic can overflow without raising an error, so choose a type suitable for the expected totals. Floating point accumulation can also round, and its last entry may differ from a separate sum calculation. Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the order, axis and accumulator type with the running totals.]]&gt;</description>
      <content:encoded><![CDATA[<p>NumPy cumsum records running totals in the order an array is supplied</p>

<p>A final total compresses a whole sequence into one number. A cumulative sum records the total reached at each position along that sequence. Academia Master Trader presents this English lesson for readers in Turkmenistan. NumPy cumsum provides the running totals, while the analyst remains responsible for choosing a meaningful order, axis and numeric type. Constructed examples show what each returned entry includes.</p>

<h2 id="each-output-includes-the-current-entry">Each output includes the current entry</h2>

<p>After <code>import numpy as np</code>, define <code>a = np.array([3,2,-1,5])</code>. The call <code>np.cumsum(a)</code> returns <code>[3,5,4,9]</code>. The first output is three. The second is three plus two. The third includes the next entry, minus one, so the running total becomes four. The last output includes all four entries and equals nine.</p>

<p>The output has four entries rather than one. It does not automatically begin with a separate zero, and it is not an average. A negative input can make the cumulative sum decrease. The operation follows the sequence as supplied; it does not reorder values or infer which observation should come first.</p>

<p><img src="https://academiamastertrader.com.br/materiais/img/aula1454.png" alt="NumPy cumsum"></p>

<h2 id="the-path-depends-on-the-input-order">The path depends on the input order</h2>

<p>Reorder the same numbers as <code>b = np.array([5,-1,2,3])</code>. The call <code>np.cumsum(b)</code> returns <code>[5,4,6,9]</code>. The last value is again nine in these exact integer examples, but the intermediate totals differ. A running total therefore carries information about the chosen arrangement, not merely about the collection of values.</p>

<p>If entries represent observations over time, keep the time coordinates and confirm their order separately. Cumsum does not inspect labels or decide whether the sequence is chronological. If entries belong to several unrelated groups, decide where accumulation should restart rather than treating a flattened collection as one continuous sequence without explanation.</p>

<h2 id="the-default-flattens-a-matrix">The default flattens a matrix</h2>

<p>Define <code>m = np.array([[2,4,1],[3,5,2]])</code>. The default call <code>np.cumsum(m)</code> returns <code>[2,6,7,10,15,17]</code>. With no axis specified, NumPy accumulates over the flattened array. The result is a one dimensional vector of six totals, even though the input has shape <code>(2,3)</code>.</p>

<p>Here the first row contributes two, four and one before the second row contributes three, five and two. The first total associated with the second row is ten, not three, because the default accumulation continues from the first row. Keep that boundary visible when interpreting a flattened result.</p>

<h2 id="an-explicit-axis-preserves-the-matrix-shape">An explicit axis preserves the matrix shape</h2>

<p>The call <code>np.cumsum(m,axis=1)</code> returns <code>[[2,6,7],[3,8,10]]</code>. It accumulates across each row independently. The second row begins at three because its running total does not include entries from the first row. Both input and output have shape <code>(2,3)</code>.</p>

<p>The call <code>np.cumsum(m,axis=0)</code> instead returns <code>[[2,4,1],[5,9,3]]</code>. It accumulates down each column. At the second row, five comes from two plus three, nine from four plus five, and three from one plus two. Name the data meaning of each axis before choosing the direction of accumulation.</p>

<h2 id="choose-a-suitable-numeric-type">Choose a suitable numeric type</h2>

<p>The dtype argument controls the output and accumulator type. For example, <code>np.cumsum(a,dtype=np.float64)</code> returns floating point totals <code>[3.,5.,4.,9.]</code>. This changes their numeric representation, not the interpretation of the underlying entries.</p>

<p>Fixed width integer arithmetic can overflow without raising an error, so choose a type suitable for the expected totals. Floating point accumulation can also round, and its last entry may differ from a separate sum calculation. Continue learning with Academia Master Trader at academiamastertrader.com.br and in <a href="https://academiamastertrader.com.br/materiais/aprenda/" rel="nofollow">Aprenda</a>. Record the order, axis and accumulator type with the running totals.</p>
]]></content:encoded>
      <guid>https://paper.wf/academiamastertrader/numpy-cumsum-records-running-totals-in-the-order-an-array-is-supplied</guid>
      <pubDate>Sun, 29 Nov 2026 02:36:17 +0000</pubDate>
    </item>
    <item>
      <title>NumPy diff calculates differences between adjacent entries along a chosen axis</title>
      <link>https://paper.wf/academiamastertrader/numpy-diff-calculates-differences-between-adjacent-entries-along-a-chosen-axis</link>
      <description>&lt;![CDATA[NumPy diff calculates differences between adjacent entries along a chosen axis&#xA;&#xA;A sequence of values and the differences between those values answer different questions. NumPy diff calculates the change from each entry to the next along a selected axis. Academia Master Trader explains the operation in English for readers in Kyrgyzstan. Constructed examples connect the subtraction rule, output length and axis choice without treating a difference as a percentage, a forecast or an independent measurement.&#xA;&#xA;Subtract the earlier entry from the next&#xA;&#xA;After import numpy as np, define a = np.array([3,7,6,12]). The call np.diff(a) returns [4,-1,6]. Seven minus three gives four. Six minus seven gives minus one. Twelve minus six gives six. The subtraction follows the supplied array order, not a separate chronological interpretation.&#xA;&#xA;Four source entries produce three adjacent differences. Each output entry belongs to a pair of neighboring input positions. A positive result means that the later position has a larger value; a negative result means it has a smaller value. This describes the pair, not the reason for its change.&#xA;&#xA;NumPy diff&#xA;&#xA;A difference is not automatically a rate&#xA;&#xA;The first result, four, is an absolute difference in the units of the input. It is not four percent. Computing a relative change would require a separately chosen denominator and a rule for cases where that denominator is zero. Likewise, a rate per hour requires information about the time between observations.&#xA;&#xA;Diff does not inspect dates or infer equal time spacing from the order of an ordinary numeric vector. Keep any time coordinates with the source and state their meaning. If the array has been sorted by value rather than observation time, the neighboring pairs describe that sorted arrangement instead.&#xA;&#xA;Higher order means differences of differences&#xA;&#xA;The call np.diff(a,n=2) returns [-5,7]. It first forms [4,-1,6], then calculates minus one minus four and six minus minus one. These are second differences. They are not the changes between every second original entry, and they are not the first differences multiplied by two.&#xA;&#xA;In this four entry example, one difference reduces the length to three and a second reduces it to two. The parameter n states how many times the differencing operation is applied. With n=0, the input is returned as it is. Keep the order visible when documenting a derived array.&#xA;&#xA;The axis chooses the neighboring positions&#xA;&#xA;Define m = np.array([[2,5,9],[4,10,15]]). The default call np.diff(m) returns [[3,4],[6,5]], because the default axis is the last one. Here that means moving across each row. The input shape (2,3) becomes (2,2).&#xA;&#xA;By contrast, np.diff(m,axis=0) returns [[2,5,6]]. It subtracts the first row from the second at each column, producing shape (1,3). Neither result is more correct without knowing what rows and columns represent. Name the axis by its data meaning as well as its numeric label.&#xA;&#xA;Boundary values and data types matter&#xA;&#xA;The call np.diff(a,prepend=0) returns [3,4,-1,6]. Zero is added before the first input entry for the calculation, so the new first difference is three minus zero. The output has four entries, but its first pair includes an explicitly supplied boundary value rather than two original observations.&#xA;&#xA;Unsigned integer arrays also need attention. An unsigned eight bit array containing 1,0] produces [255] under diff, rather than a signed minus one. Convert to a suitable signed type before subtraction when negative results are intended. Continue learning with Academia Master Trader at academiamastertrader.com.br and in [Aprenda. Record the order, axis, difference order and any boundary value alongside the result.]]&gt;</description>
      <content:encoded><![CDATA[<p>NumPy diff calculates differences between adjacent entries along a chosen axis</p>

<p>A sequence of values and the differences between those values answer different questions. NumPy diff calculates the change from each entry to the next along a selected axis. Academia Master Trader explains the operation in English for readers in Kyrgyzstan. Constructed examples connect the subtraction rule, output length and axis choice without treating a difference as a percentage, a forecast or an independent measurement.</p>

<h2 id="subtract-the-earlier-entry-from-the-next">Subtract the earlier entry from the next</h2>

<p>After <code>import numpy as np</code>, define <code>a = np.array([3,7,6,12])</code>. The call <code>np.diff(a)</code> returns <code>[4,-1,6]</code>. Seven minus three gives four. Six minus seven gives minus one. Twelve minus six gives six. The subtraction follows the supplied array order, not a separate chronological interpretation.</p>

<p>Four source entries produce three adjacent differences. Each output entry belongs to a pair of neighboring input positions. A positive result means that the later position has a larger value; a negative result means it has a smaller value. This describes the pair, not the reason for its change.</p>

<p><img src="https://academiamastertrader.com.br/materiais/img/aula1453.png" alt="NumPy diff"></p>

<h2 id="a-difference-is-not-automatically-a-rate">A difference is not automatically a rate</h2>

<p>The first result, four, is an absolute difference in the units of the input. It is not four percent. Computing a relative change would require a separately chosen denominator and a rule for cases where that denominator is zero. Likewise, a rate per hour requires information about the time between observations.</p>

<p>Diff does not inspect dates or infer equal time spacing from the order of an ordinary numeric vector. Keep any time coordinates with the source and state their meaning. If the array has been sorted by value rather than observation time, the neighboring pairs describe that sorted arrangement instead.</p>

<h2 id="higher-order-means-differences-of-differences">Higher order means differences of differences</h2>

<p>The call <code>np.diff(a,n=2)</code> returns <code>[-5,7]</code>. It first forms <code>[4,-1,6]</code>, then calculates minus one minus four and six minus minus one. These are second differences. They are not the changes between every second original entry, and they are not the first differences multiplied by two.</p>

<p>In this four entry example, one difference reduces the length to three and a second reduces it to two. The parameter n states how many times the differencing operation is applied. With <code>n=0</code>, the input is returned as it is. Keep the order visible when documenting a derived array.</p>

<h2 id="the-axis-chooses-the-neighboring-positions">The axis chooses the neighboring positions</h2>

<p>Define <code>m = np.array([[2,5,9],[4,10,15]])</code>. The default call <code>np.diff(m)</code> returns <code>[[3,4],[6,5]]</code>, because the default axis is the last one. Here that means moving across each row. The input shape <code>(2,3)</code> becomes <code>(2,2)</code>.</p>

<p>By contrast, <code>np.diff(m,axis=0)</code> returns <code>[[2,5,6]]</code>. It subtracts the first row from the second at each column, producing shape <code>(1,3)</code>. Neither result is more correct without knowing what rows and columns represent. Name the axis by its data meaning as well as its numeric label.</p>

<h2 id="boundary-values-and-data-types-matter">Boundary values and data types matter</h2>

<p>The call <code>np.diff(a,prepend=0)</code> returns <code>[3,4,-1,6]</code>. Zero is added before the first input entry for the calculation, so the new first difference is three minus zero. The output has four entries, but its first pair includes an explicitly supplied boundary value rather than two original observations.</p>

<p>Unsigned integer arrays also need attention. An unsigned eight bit array containing <code>[1,0]</code> produces <code>[255]</code> under diff, rather than a signed minus one. Convert to a suitable signed type before subtraction when negative results are intended. Continue learning with Academia Master Trader at academiamastertrader.com.br and in <a href="https://academiamastertrader.com.br/materiais/aprenda/" rel="nofollow">Aprenda</a>. Record the order, axis, difference order and any boundary value alongside the result.</p>
]]></content:encoded>
      <guid>https://paper.wf/academiamastertrader/numpy-diff-calculates-differences-between-adjacent-entries-along-a-chosen-axis</guid>
      <pubDate>Sun, 29 Nov 2026 02:32:20 +0000</pubDate>
    </item>
    <item>
      <title>NumPy clip limits array values at chosen edges without removing positions</title>
      <link>https://paper.wf/academiamastertrader/numpy-clip-limits-array-values-at-chosen-edges-without-removing-positions</link>
      <description>&lt;![CDATA[NumPy clip limits array values at chosen edges without removing positions&#xA;&#xA;An array can keep its layout while selected values are limited to a chosen interval. NumPy clip replaces values below a lower edge with that edge and values above an upper edge with the upper edge. Academia Master Trader presents this English lesson for readers in Tajikistan. Constructed examples explain how clipping differs from filtering, rescaling and changing the source array in place.&#xA;&#xA;Keep the values already inside the interval&#xA;&#xA;After import numpy as np, define a = np.array([-3,1,4,9,12]). The call np.clip(a,0,10) returns [0,1,4,9,10]. Minus three becomes zero because it is below the lower edge. Twelve becomes ten because it is above the upper edge. One, four and nine stay unchanged.&#xA;&#xA;The result has five entries, just like the input. Clipping does not remove the values outside the interval or shorten the array. Nor does it stretch all values onto a new scale. It only applies the specified limits. A value equal to an edge remains equal to that edge.&#xA;&#xA;NumPy clip&#xA;&#xA;A limited value does not identify its original&#xA;&#xA;In the output, zero could have come from an original zero or from any value below zero. Ten could have come from an original ten or from a larger value. Once those distinctions are replaced by the edges, the clipped output alone cannot reconstruct the original entries.&#xA;&#xA;Keep the source when those distinctions matter. In the call above, a is unchanged because no output destination was specified. Store the result under a separate name, such as limited = np.clip(a,0,10), when both the original and the limited representation are useful. The new name describes the transformation without suggesting that the original measurements were incorrect.&#xA;&#xA;Use None for an unlimited edge&#xA;&#xA;A bound can be None when clipping should not apply on that side. For the same a, np.clip(a,None,8) returns [-3,1,4,8,8]. The upper edge becomes eight, while negative values stay untouched because there is no lower limit in this call.&#xA;&#xA;Conversely, np.clip(a,2,None) returns [2,2,4,9,12]. Only the lower edge applies. Twelve remains twelve. This is different from supplying zero as a bound: zero is an actual numeric limit, while None means that the corresponding edge does not perform clipping.&#xA;&#xA;Array bounds can vary by position&#xA;&#xA;The bounds can be arrays that broadcast against the input. Define lower = np.array([0,2,3,4,5]). The call np.clip(a,lower,10) returns [0,2,4,9,10]. Each input entry uses the lower edge at the corresponding position, while the scalar upper edge ten applies throughout.&#xA;&#xA;The lower array is not a second set of observations to concatenate with a. It supplies limits. Check the shapes and the meaning of every bound before applying a position dependent rule. Broadcasting must produce compatible positions for the values and bounds; unrelated lengths do not automatically define a valid arrangement.&#xA;&#xA;Check edge order before clipping&#xA;&#xA;NumPy does not check that the lower edge is less than the upper edge. With reversed scalar edges, np.clip(a,10,0) returns [0,0,0,0,0]. The documented behavior makes every entry equal to the upper edge in this case. Do not expect the function to swap the two numbers or report an interval ordering error.&#xA;&#xA;The optional output argument also changes how the result is stored. The call np.clip(a,0,10,out=a) writes the clipped values into a itself. This deliberately replaces the original entries, unlike the earlier calls. Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. State the bounds, confirm their order and choose the output destination explicitly.]]&gt;</description>
      <content:encoded><![CDATA[<p>NumPy clip limits array values at chosen edges without removing positions</p>

<p>An array can keep its layout while selected values are limited to a chosen interval. NumPy clip replaces values below a lower edge with that edge and values above an upper edge with the upper edge. Academia Master Trader presents this English lesson for readers in Tajikistan. Constructed examples explain how clipping differs from filtering, rescaling and changing the source array in place.</p>

<h2 id="keep-the-values-already-inside-the-interval">Keep the values already inside the interval</h2>

<p>After <code>import numpy as np</code>, define <code>a = np.array([-3,1,4,9,12])</code>. The call <code>np.clip(a,0,10)</code> returns <code>[0,1,4,9,10]</code>. Minus three becomes zero because it is below the lower edge. Twelve becomes ten because it is above the upper edge. One, four and nine stay unchanged.</p>

<p>The result has five entries, just like the input. Clipping does not remove the values outside the interval or shorten the array. Nor does it stretch all values onto a new scale. It only applies the specified limits. A value equal to an edge remains equal to that edge.</p>

<p><img src="https://academiamastertrader.com.br/materiais/img/aula1452.png" alt="NumPy clip"></p>

<h2 id="a-limited-value-does-not-identify-its-original">A limited value does not identify its original</h2>

<p>In the output, zero could have come from an original zero or from any value below zero. Ten could have come from an original ten or from a larger value. Once those distinctions are replaced by the edges, the clipped output alone cannot reconstruct the original entries.</p>

<p>Keep the source when those distinctions matter. In the call above, a is unchanged because no output destination was specified. Store the result under a separate name, such as <code>limited = np.clip(a,0,10)</code>, when both the original and the limited representation are useful. The new name describes the transformation without suggesting that the original measurements were incorrect.</p>

<h2 id="use-none-for-an-unlimited-edge">Use None for an unlimited edge</h2>

<p>A bound can be None when clipping should not apply on that side. For the same a, <code>np.clip(a,None,8)</code> returns <code>[-3,1,4,8,8]</code>. The upper edge becomes eight, while negative values stay untouched because there is no lower limit in this call.</p>

<p>Conversely, <code>np.clip(a,2,None)</code> returns <code>[2,2,4,9,12]</code>. Only the lower edge applies. Twelve remains twelve. This is different from supplying zero as a bound: zero is an actual numeric limit, while None means that the corresponding edge does not perform clipping.</p>

<h2 id="array-bounds-can-vary-by-position">Array bounds can vary by position</h2>

<p>The bounds can be arrays that broadcast against the input. Define <code>lower = np.array([0,2,3,4,5])</code>. The call <code>np.clip(a,lower,10)</code> returns <code>[0,2,4,9,10]</code>. Each input entry uses the lower edge at the corresponding position, while the scalar upper edge ten applies throughout.</p>

<p>The lower array is not a second set of observations to concatenate with a. It supplies limits. Check the shapes and the meaning of every bound before applying a position dependent rule. Broadcasting must produce compatible positions for the values and bounds; unrelated lengths do not automatically define a valid arrangement.</p>

<h2 id="check-edge-order-before-clipping">Check edge order before clipping</h2>

<p>NumPy does not check that the lower edge is less than the upper edge. With reversed scalar edges, <code>np.clip(a,10,0)</code> returns <code>[0,0,0,0,0]</code>. The documented behavior makes every entry equal to the upper edge in this case. Do not expect the function to swap the two numbers or report an interval ordering error.</p>

<p>The optional output argument also changes how the result is stored. The call <code>np.clip(a,0,10,out=a)</code> writes the clipped values into a itself. This deliberately replaces the original entries, unlike the earlier calls. Continue learning with Academia Master Trader at academiamastertrader.com.br and in <a href="https://academiamastertrader.com.br/materiais/aprenda/" rel="nofollow">Aprenda</a>. State the bounds, confirm their order and choose the output destination explicitly.</p>
]]></content:encoded>
      <guid>https://paper.wf/academiamastertrader/numpy-clip-limits-array-values-at-chosen-edges-without-removing-positions</guid>
      <pubDate>Sun, 29 Nov 2026 02:27:39 +0000</pubDate>
    </item>
    <item>
      <title>NumPy where chooses between two alternatives at each position of an array</title>
      <link>https://paper.wf/academiamastertrader/numpy-where-chooses-between-two-alternatives-at-each-position-of-an-array</link>
      <description>&lt;![CDATA[NumPy where chooses between two alternatives at each position of an array&#xA;&#xA;A condition can decide which of two alternatives supplies each output entry. In its three argument form, NumPy where selects from the first alternative when the condition is true and from the second when it is false. Academia Master Trader explains that form in English for readers in Uzbekistan. Constructed examples show how the selection preserves a common output shape instead of simply dropping the positions where a condition is false.&#xA;&#xA;Choose a value at every position&#xA;&#xA;After import numpy as np, define a = np.array([2,5,8,11]). The expression np.where(a &lt; 7,a,0) returns [2,5,0,0]. The condition is [True,True,False,False]. At the first two positions, the output comes from a. At the remaining positions, it comes from the scalar zero.&#xA;&#xA;The result still has four entries. Where has not removed eight and eleven to produce a shorter vector. It has filled their corresponding output positions with the false alternative. The original a retains its values because this call constructs a result rather than assigning that result back into a.&#xA;&#xA;NumPy where&#xA;&#xA;Both alternatives can be arrays&#xA;&#xA;Define b = np.array([20,50,80,110]). The call np.where(a &lt; 7,a,b) returns [2,5,80,110]. At each true position it selects the value from a at that position. At each false position it selects the value from b at that position. It does not take all of a first and append part of b afterward.&#xA;&#xA;Reversing the alternatives reverses their roles. The expression np.where(a &lt; 7,b,a) returns [20,50,8,11]. The condition stays the same, but true now selects from b and false selects from a. State the roles of the second and third arguments when explaining a selection, particularly if both contain plausible output values.&#xA;&#xA;Matrices retain their selection layout&#xA;&#xA;Define m = np.array([[1,4],[7,10]]). The call np.where(m &lt; 6,m,-1) returns [[1,4],[-1,-1]]. The condition and output have shape (2,2). Each output position corresponds to the same row and column position in the source matrix.&#xA;&#xA;This makes where different from a filtering operation that gathers only matching entries into a vector. A matrix shaped result can retain the placement of both matched and unmatched positions. The replacement value minus one is part of the chosen rule. It does not establish that the original entries were negative, absent or incorrectly recorded.&#xA;&#xA;Broadcasting defines the common shape&#xA;&#xA;The condition and both alternatives must be broadcastable to a common shape. A scalar alternative can supply the same value across many positions, as zero and minus one do above. Equal shaped arrays also fit the rule. Inputs that cannot broadcast to a common shape raise an error instead of defining a meaningful position by position selection.&#xA;&#xA;For example, np.where([[True],[False]],[10,20,30],-1) returns [[10,20,30],[-1,-1,-1]]. The two by one condition and the three entry alternative broadcast to shape (2,3). The first condition row selects the vector, while the second selects the scalar. Check this output shape before using a broadcast selection in another calculation.&#xA;&#xA;Keep the one argument form separate&#xA;&#xA;Calling where with only a condition has a different purpose: it returns the nonzero positions as a tuple of index arrays. It does not provide two alternatives or return the selected source values. The documentation recommends using nonzero directly for that purpose. Do not read a one argument call as shorthand for the three argument selection described here.&#xA;&#xA;Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the condition, true alternative, false alternative and common shape. Then trace the output position by position so the selection rule remains explicit.]]&gt;</description>
      <content:encoded><![CDATA[<p>NumPy where chooses between two alternatives at each position of an array</p>

<p>A condition can decide which of two alternatives supplies each output entry. In its three argument form, NumPy where selects from the first alternative when the condition is true and from the second when it is false. Academia Master Trader explains that form in English for readers in Uzbekistan. Constructed examples show how the selection preserves a common output shape instead of simply dropping the positions where a condition is false.</p>

<h2 id="choose-a-value-at-every-position">Choose a value at every position</h2>

<p>After <code>import numpy as np</code>, define <code>a = np.array([2,5,8,11])</code>. The expression <code>np.where(a &lt; 7,a,0)</code> returns <code>[2,5,0,0]</code>. The condition is <code>[True,True,False,False]</code>. At the first two positions, the output comes from a. At the remaining positions, it comes from the scalar zero.</p>

<p>The result still has four entries. Where has not removed eight and eleven to produce a shorter vector. It has filled their corresponding output positions with the false alternative. The original a retains its values because this call constructs a result rather than assigning that result back into a.</p>

<p><img src="https://academiamastertrader.com.br/materiais/img/aula1451.png" alt="NumPy where"></p>

<h2 id="both-alternatives-can-be-arrays">Both alternatives can be arrays</h2>

<p>Define <code>b = np.array([20,50,80,110])</code>. The call <code>np.where(a &lt; 7,a,b)</code> returns <code>[2,5,80,110]</code>. At each true position it selects the value from a at that position. At each false position it selects the value from b at that position. It does not take all of a first and append part of b afterward.</p>

<p>Reversing the alternatives reverses their roles. The expression <code>np.where(a &lt; 7,b,a)</code> returns <code>[20,50,8,11]</code>. The condition stays the same, but true now selects from b and false selects from a. State the roles of the second and third arguments when explaining a selection, particularly if both contain plausible output values.</p>

<h2 id="matrices-retain-their-selection-layout">Matrices retain their selection layout</h2>

<p>Define <code>m = np.array([[1,4],[7,10]])</code>. The call <code>np.where(m &lt; 6,m,-1)</code> returns <code>[[1,4],[-1,-1]]</code>. The condition and output have shape <code>(2,2)</code>. Each output position corresponds to the same row and column position in the source matrix.</p>

<p>This makes where different from a filtering operation that gathers only matching entries into a vector. A matrix shaped result can retain the placement of both matched and unmatched positions. The replacement value minus one is part of the chosen rule. It does not establish that the original entries were negative, absent or incorrectly recorded.</p>

<h2 id="broadcasting-defines-the-common-shape">Broadcasting defines the common shape</h2>

<p>The condition and both alternatives must be broadcastable to a common shape. A scalar alternative can supply the same value across many positions, as zero and minus one do above. Equal shaped arrays also fit the rule. Inputs that cannot broadcast to a common shape raise an error instead of defining a meaningful position by position selection.</p>

<p>For example, <code>np.where([[True],[False]],[10,20,30],-1)</code> returns <code>[[10,20,30],[-1,-1,-1]]</code>. The two by one condition and the three entry alternative broadcast to shape <code>(2,3)</code>. The first condition row selects the vector, while the second selects the scalar. Check this output shape before using a broadcast selection in another calculation.</p>

<h2 id="keep-the-one-argument-form-separate">Keep the one argument form separate</h2>

<p>Calling where with only a condition has a different purpose: it returns the nonzero positions as a tuple of index arrays. It does not provide two alternatives or return the selected source values. The documentation recommends using nonzero directly for that purpose. Do not read a one argument call as shorthand for the three argument selection described here.</p>

<p>Continue learning with Academia Master Trader at academiamastertrader.com.br and in <a href="https://academiamastertrader.com.br/materiais/aprenda/" rel="nofollow">Aprenda</a>. Record the condition, true alternative, false alternative and common shape. Then trace the output position by position so the selection rule remains explicit.</p>
]]></content:encoded>
      <guid>https://paper.wf/academiamastertrader/numpy-where-chooses-between-two-alternatives-at-each-position-of-an-array</guid>
      <pubDate>Sun, 29 Nov 2026 02:23:24 +0000</pubDate>
    </item>
  </channel>
</rss>