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 atleast_3d gives arrays a minimum of three dimensions with specific positions for added size-one axes

A one-dimensional vector and a two-dimensional table need different shape changes to become three-dimensional. NumPy atleast_3d handles these inputs according to their starting dimensions. The operation provides a minimum of three dimensions, rather than forcing every input into one fixed three-dimensional shape.

Academia Master Trader presents this explanation in English for readers in Palau. The examples concern numerical array structure only. They are not prices, trading signals or financial results. Following the shape entries makes the added dimensions easier to understand.

A vector gains a leading and a trailing dimension

The reference states that a one-dimensional array with shape (N,) becomes a view with shape (1,N,1). The original length stays in the middle position, between two new dimensions of length one.

For a NumPy array x containing [0.,1.,2.], the input shape is (3,). Calling np.atleast_3d(x) gives shape (1,3,1).

Original diagram: NumPy atleast_3d changes vector shape three into shape one by three by one, keeping the original length three in the middle and adding size-one dimensions at the beginning and end.

The three numerical entries remain. The two new ones in the shape are dimension lengths, not extra values inserted into the vector. Shape and array contents describe different properties.

A two-dimensional array gains a trailing dimension

For a two-dimensional input with shape (M,N), the documented output shape is (M,N,1). The two existing dimension lengths keep their order, and a new trailing dimension has length one.

The reference gives an input reshaped to (4,3). Its atleast_3d result has shape (4,3,1). The new axis is at the end, not at the beginning.

State the full result shape when explaining this operation. Saying that one dimension is added does not identify where it appears. The distinction between (1,4,3) and (4,3,1) is structural, even though both shapes describe twelve entries.

The operation does not add every new axis at the front

The vector rule and the two-dimensional rule are different. A vector becomes (1,N,1), while a two-dimensional array becomes (M,N,1).

A description that always adds leading size-one axes would therefore give the wrong output shape. Read the documented rule for the starting dimension count instead of assuming a single insertion pattern.

For the three-entry vector, writing (1,1,3) would place the original length in the last position. That is not the vector rule described by atleast_3d, which places it in the middle.

A scalar becomes a one-by-one-by-one array

The reference shows np.atleast_3d(3.0) returning an array containing [[[3.]]]. The result has shape (1,1,1) and contains one numerical entry.

The three dimensions each have length one. Multiplying those lengths gives one, so the additional dimensions do not create more copies of the number.

This example separates dimension count from entry count. The result has three dimensions but one entry. A vector example can have three dimensions and three entries. Neither dimension count alone nor bracket depth alone tells the whole story.

Arrays already meeting the minimum are preserved

The documentation states that arrays with three or more dimensions are preserved. An array that already has shape (1,1,2) meets the minimum without adding a new axis.

The function also does not reduce an array with more than three dimensions to exactly three. The word at least expresses a lower bound, not an instruction to flatten higher-dimensional structure.

Before predicting a change, identify the input's number of dimensions. If the array already meets the minimum, do not describe an extra leading or trailing axis as a required part of the operation.

Similar contents can begin with different shapes

The reference compares the separate inputs [1,2], [[1,2]] and [[[1,2]]]. Each contains the same two numerical values, but their starting dimensions differ.

The first two inputs yield results with shape (1,2,1). The third input already has three dimensions and retains shape (1,1,2).

This is a useful reason to record shape before discussing values. Matching contents do not guarantee matching shapes after a minimum-dimension operation. The original arrangement determines which rule applies.

Several arguments receive separate results

Atleast_3d accepts one or more array-like inputs. With several arguments, each input receives an array result with at least three dimensions.

The function does not combine those arguments into one new shared dimension. In the reference comparison, the separate results can be inspected individually, including their different shapes.

Keep the grouping clear in written examples. Values inside one bracketed sequence belong to one input. Commas separating function arguments can instead identify several inputs, each handled on its own.

Keep the storage condition with the explanation

The documentation says that copies are avoided where possible and views with three or more dimensions are returned. Non-array inputs are converted to arrays, so a storage explanation must account for the starting input type.

A new shape is not, by itself, evidence that a separate independent copy of all numerical data has been made. Equally, copies avoided where possible should not become a promise of no allocation for every kind of input.

Continue learning with Academia Master Trader at academiamastertrader.com.br. Aprenda provides access to educational material. Identify the starting dimensions, apply the corresponding shape rule and state where each size-one axis appears. That keeps the minimum-dimension requirement separate from the number of numerical entries and from the question of independent storage.

NumPy atleast_2d gives inputs a minimum of two dimensions without flattening higher-dimensional arrays

An input may be a single number, a one-dimensional sequence or an array that already has several dimensions. NumPy atleast_2d views inputs as arrays with at least two dimensions. The phrase at least sets a minimum. It does not mean that every result must have exactly two dimensions.

Academia Master Trader presents this explanation in English for readers in Nauru. The examples concern numerical array structure only. They are not market prices, trading signals or financial results. Reading the input and output shapes makes the function's purpose easier to understand.

A scalar becomes a one-by-one array

The NumPy reference shows np.atleast_2d(3.0) returning [[3.]] as an array. The result has one row and one column, with shape (1,1).

The single numerical value is retained. Adding dimensions does not require adding more distinct values. Here the two dimensions each have length one, so the result still contains one entry.

The decimal notation reflects the floating-point value used in this example. The important structural point is that a scalar input is represented in an array with two dimensions rather than remaining a scalar.

A one-dimensional array becomes a single row

Let x be the NumPy array containing [0.,1.,2.]. Its shape is (3,), meaning one dimension with three entries. The call np.atleast_2d(x) returns a single row containing those same values, with shape (1,3).

Original diagram: NumPy atleast_2d changes a vector of shape three into a one-row array of shape one by three, keeping the entries zero, one and two.

The result is not a column with shape (3,1). The function's one-dimensional example becomes a row. State the resulting shape explicitly when the distinction between a row and a column matters.

The entry count stays separate from dimension count

In the vector example, shape (3,) describes three entries. Shape (1,3) also describes three entries. The new size-one dimension changes the arrangement, not the number of numerical entries.

This is different from repeating the vector several times. A repeated arrangement would contain additional positions for values. The one-row result has only the original three positions.

Keep the shape beside the contents when explaining this change. The contents show which values remain, while the shape identifies how many dimensions describe them and the length of each dimension.

Existing two-dimensional arrays are preserved

The reference states that arrays that already have two or more dimensions are preserved. A two-dimensional array therefore does not need another dimension simply because it is passed to atleast_2d.

For an input whose shape is already (1,2), the minimum requirement is already met. The function is not an instruction to add one more leading dimension to every input.

This distinction separates a minimum-dimension operation from unconditional axis insertion. Before describing a shape change, identify whether the input actually falls below the two-dimensional minimum.

Higher-dimensional arrays are not flattened to a matrix

An array with three dimensions already satisfies the requirement of at least two dimensions. The documentation says that arrays with two or more dimensions are preserved, rather than reduced to exactly two.

For example, an array with shape (2,3,4) already has more than the required minimum. Atleast_2d is not a request to combine two of those dimensions into a larger row or column dimension.

Do not describe this function as a general reshape-to-matrix operation. Its name specifies a lower bound on the number of dimensions, not a target shape with exactly two positions.

Several inputs are handled individually

The function accepts one or more array-like inputs. The reference gives a call with three separate inputs: np.atleast_2d(1,[1,2],[[1,2]]).

The returned arrays represent [[1]], [[1,2]] and [[1,2]]. The scalar, the one-dimensional sequence and the already two-dimensional sequence each receive the structure appropriate to that input.

Those separate arguments are not instructions to concatenate their contents into one larger row. Read the result as a collection of results corresponding to the supplied inputs, each satisfying the minimum dimension count.

A sequence and several arguments are different requests

A call containing one sequence, such as np.atleast_2d([1,2]), supplies a single array-like input. Its two values belong to one sequence that becomes a one-row array.

A call with several separate arguments supplies several inputs for individual treatment. The distinction is in the call structure, before looking at the shapes of the returned arrays.

When recording an example, keep the brackets and commas clear. They show whether values are grouped inside one input or supplied as separate inputs. That makes the relationship between inputs and results easier to follow.

Copies are avoided where possible

The documentation says that copies are avoided where possible and that views with two or more dimensions are returned. Non-array inputs are converted to arrays, so the starting type matters when describing the operation.

In the reference's one-dimensional NumPy array example, the result's base is the original x. That illustrates a view relationship for that example. A different bracket layout does not by itself prove independent storage.

Do not turn this into a promise that every possible input requires no allocation. The documented wording is copies avoided where possible. Keep that condition when explaining the storage behaviour.

Read the minimum before predicting the shape

Continue learning with Academia Master Trader at academiamastertrader.com.br. Aprenda provides access to educational material. Identify the input's dimension count, then ask whether it already meets the minimum of two. For lower-dimensional inputs, state the resulting shape. For arrays already meeting the minimum, avoid describing a flattening or extra-axis step that the function does not require.

NumPy squeeze removes size-one axes while preserving the numerical entries in an array

A dimension of length one can describe a row, a column or another position in an array's shape. NumPy squeeze removes axes whose length is one. It changes the shape without selecting fewer numerical entries. The operation is about dimensions, rather than deleting values that happen to equal one.

Academia Master Trader presents this explanation in English for readers in Kiribati. The examples concern array structure only. They are not market prices, signals or financial results. A shape containing two size-one dimensions makes the operation easy to follow.

Read the input shape before removing an axis

Consider an array x containing the nested values [[[0],[1],[2]]]. Its shape is (1,3,1). The first dimension has length one, the second has length three and the third has length one.

The call np.squeeze(x) gives shape (3,). With the default axis argument, the size-one axes are removed. The length-three dimension remains, and the entries zero, one and two are retained.

Original diagram: NumPy squeeze changes shape one by three by one into shape three by removing axes zero and two, both length one, while retaining entries zero, one and two.

The result has one dimension and three entries. The value one is still present. This matters because squeeze acts on dimension lengths, not on whether an individual entry has the numerical value one.

Remove only a selected size-one axis

The optional axis argument can limit the operation. For the same input, np.squeeze(x,axis=0) produces shape (3,1). Only the first size-one axis has been removed.

The original last axis still has length one, so the result is two-dimensional. A selected axis does not mean that every other eligible size-one axis must disappear too.

The call np.squeeze(x,axis=2) instead produces shape (1,3). The last size-one axis is removed, while the leading one remains. Both calls keep the same three numerical entries but give different shapes.

The selected axis must have length one

For shape (1,3,1), the dimension at axis one has length three. The call np.squeeze(x,axis=1) raises ValueError because this dimension cannot be removed by squeeze.

The operation does not reduce the three entries to a single number. It does not choose a representative entry, calculate an average or combine neighbouring values. A selected dimension must already have length one.

Before supplying an axis, write down its length in the input shape. This gives a direct explanation of why axes zero and two are eligible in this example, while axis one is not.

Keep axis position separate from axis length

In shape (1,3,1), axis zero and axis two each have length one. The axis number names a position. The corresponding shape entry gives the length at that position.

Saying remove axis one would therefore name the middle dimension, not mean remove any dimension whose length is one. These are different uses of the number one and should be described separately.

A clear explanation states both pieces of information: remove axis zero, whose length is one. That wording avoids confusing an index with a dimension size or an array entry.

Several selected axes can be named

The reference allows axis to be an integer or a tuple of integers, as well as the default None. A tuple selects a subset of size-one dimensions for removal.

For the example shape (1,3,1), selecting axes zero and two removes the two size-one dimensions and leaves shape (3,). Each selected dimension satisfies the same length-one requirement.

Read the selected positions from the input shape. When explaining a tuple, list the dimensions it selects and the remaining dimensions in order. This makes the resulting shape easier to understand than relying only on nested brackets.

Entry count does not shrink with dimension count

The product of the input dimension lengths is one times three times one, which equals three. The output shape (3,) also describes three entries.

Removing a dimension of length one does not discard a row full of distinct data. That dimension has only one position, so removing its place in the shape does not remove the values described by the other dimensions.

This is why shape reduction and data reduction need separate names. Squeeze simplifies dimensions that have length one. It is not an operation for summarising multiple values into fewer values.

Removing every axis leaves a zero-dimensional array

The reference gives another example: an array containing [[1234]] has shape (1,1). Calling squeeze removes both size-one dimensions and produces an array with shape ().

That result is a zero-dimensional array, not an ordinary scalar. It still contains the numerical value 1234, but its shape has no dimension lengths listed.

Do not describe the empty shape tuple as an empty array. There is still one value. The absence of axes is different from the absence of entries, and the reference explicitly distinguishes this result from a scalar.

The documented result shares the input relationship

The documentation states that the result is the input itself or a view into it. A shorter shape does not establish that a separate, independent copy of the numerical data has been created.

If later work requires an independent copy, that is a separate requirement from removing size-one dimensions. Shape and storage relationship answer different questions and should be explained separately.

Continue learning with Academia Master Trader at academiamastertrader.com.br. Aprenda provides access to educational material. Read the input shape, identify dimensions of length one and state which of them are removed. Then describe the output shape without suggesting that values equal to one were deleted.

NumPy expand_dims inserts a size-one axis at a chosen position without adding new numerical entries

An array can gain a dimension without gaining more data values. NumPy expand_dims inserts a new axis at a specified position in the expanded shape. The inserted axis has length one. This changes the arrangement described by the shape, rather than repeating the existing entries.

Academia Master Trader presents this explanation in English for readers in Tuvalu. The examples concern numerical array structure only. They are not prices, trading signals or financial results. A short vector makes the difference between adding a row axis and adding a column axis easy to read.

Begin with a one-dimensional array

Let x be a NumPy array containing [1,2]. Its shape is (2,), meaning that it has one axis with two entries. The shape does not include a separate row axis and column axis.

The expression np.expand_dims(x,axis=0) gives an array with one row, [1,2], and shape (1,2). The inserted size-one dimension appears at position zero in the output shape.

Original diagram: NumPy expand_dims inserts a leading size-one axis into a vector of shape two, producing a one-row array with shape one by two and the same entries one and two.

There are still two numerical entries. The new one in the shape describes the length of the added axis. It is not an extra data value inserted before one and two.

Insert the new axis after the existing axis

For the same x, np.expand_dims(x,axis=1) produces rows [1] and [2], with shape (2,1). The original length-two dimension stays first, and the new size-one dimension appears second.

The two outputs contain the same values, but one is a single row and the other is a single column. The axis argument selects where the new dimension appears, so it changes the arrangement even when the entry count stays unchanged.

Read the output shape from beginning to end. In (1,2), the first dimension has length one. In (2,1), the second dimension has length one. Writing only that the result is two-dimensional leaves this distinction unstated.

The axis names an expanded position

The documentation defines axis as a position in the expanded axes. This is important because the position belongs to the result that includes the new axis, rather than merely naming an existing input dimension.

For the one-dimensional vector, positions zero and one can each identify a place for a new axis in a two-dimensional result. They do not select an input axis to remove or replace.

Keep the operation separate from moving an existing axis. Expand_dims adds a dimension of length one. Moving axes changes the positions of dimensions that are already present. The two operations answer different structural questions.

Shape grows while entry count stays fixed

The input shape (2,), the row shape (1,2) and the column shape (2,1) each describe two entries. Multiplying the dimension lengths gives two in each case. The extra dimension does not multiply the data into additional copies.

This is why the word expand needs a precise explanation. It is the number of dimensions that increases, not the numerical values and not necessarily the number of entries.

A small example should therefore state both the shape and the contents. The contents show that one and two are retained. The shape shows where the size-one axis has been inserted.

Several new axes can be requested

The axis argument may be a tuple. For x containing [1,2], the reference shows np.expand_dims(x,axis=(0,1)), whose result has shape (1,1,2).

Two new size-one axes appear before the original length-two dimension. The result has three dimensions but still contains only the two original numerical entries.

The reference also shows axis=(2,0), giving shape (1,2,1). The new axes occupy positions zero and two of the expanded result. The original length-two axis lies between them.

Read tuple positions in the resulting shape

A tuple names positions for the inserted axes in the expanded arrangement. It should not be described as an instruction to repeatedly insert one axis and then reinterpret every subsequent position through a separate call.

For shape (1,2,1), naming the size-one axes at positions zero and two is enough to explain the structure. The remaining position holds the input's original length-two dimension.

Write the full output shape beside a multi-axis call. Nested brackets alone can be difficult to read, especially when several dimensions have length one. A shape gives a compact account of the dimension positions.

The documented result is a view

The reference describes the result as a view of the input with the number of dimensions increased. Do not describe the different bracket layout as evidence that an independent full copy of the data was created.

If later work needs an independent snapshot, that is a separate requirement from inserting an axis. A dimension change explains the arrangement used to address entries, not a guarantee that storage has become separate.

Keep those statements distinct: the output has more dimensions, the added dimensions have length one, the original values are retained and the documented result is a view. Each statement explains a different property.

Name the new dimension and its position

Continue learning with Academia Master Trader at academiamastertrader.com.br. Aprenda provides access to educational material. Read the input shape, identify the output positions for the new size-one axes and state the resulting shape. That keeps adding a dimension distinct from repeating values, changing their magnitude or moving an existing axis.

NumPy moveaxis places selected axes in new positions while keeping the remaining axes in their original relative order

An array's shape is an ordered description of its dimensions. NumPy moveaxis changes that order by placing selected axes at specified destinations. The axes that are not selected keep their original relative order. This makes the function useful to explain as moving dimensions within an ordered list.

Academia Master Trader presents this explanation in English for readers in Tonga. The examples concern numerical array structure only. They are not prices, trading signals or financial results. Reading the source axis and destination position separately helps distinguish movement from a simple exchange of two axes.

Start with three named dimensions

Let x be a NumPy array with shape (3,4,5). Call its axes A, B and C for the explanation, with lengths three, four and five respectively. The initial order is A, B, C.

The expression np.moveaxis(x,0,-1) gives shape (4,5,3). Axis zero, labelled A in this explanation, moves to the final position. The remaining axes B and C stay in that relative order.

Original diagram: axes A B C with lengths three four five become B C A with lengths four five three after moving source axis zero to the final destination with NumPy moveaxis.

The letters are teaching labels, not additional function arguments. They help track the dimensions through the operation. The actual call identifies the source and destination through axis positions.

A destination is a position in the output

The source argument identifies the original axis to move. The destination identifies where that axis should appear in the result. In this example, negative one names the final destination position.

The length three travels with its axis. It does not become four merely because a different axis now occupies the first position. The shape changes from (3,4,5) to (4,5,3) because the existing dimensions have been reordered.

Keep axis identifiers and dimension lengths separate. The source value zero does not mean a dimension of length zero, and the destination value negative one does not request a negative dimension length.

Move the final axis to the beginning

For the same x, np.moveaxis(x,-1,0) gives shape (5,3,4). Axis C moves from the final input position to the first output position. Axes A and B retain their relative order after it.

This result differs from moving the first axis to the end. One operation produces B, C, A; the other produces C, A, B. The same dimensions participate, but the source and destination describe different arrangements.

Read both arguments in the call. Saying that an axis moves between the beginning and the end is incomplete unless the direction of that move is also clear.

Movement is not always an exchange

For shape (3,4,5), swapping the first and final axes gives shape (5,4,3). Moving the first axis to the end instead gives (4,5,3). The middle dimension behaves differently in the two arrangements.

With moveaxis, the unselected dimensions keep their relative order. With a pairwise swap, the selected axes exchange places directly. These are different rules, even though both reorder dimensions.

Use a three-axis example when teaching this distinction. A two-axis example can make the operations look identical because there is less remaining order to observe.

Follow a single entry through its indices

An entry at input index (1,2,3) in shape (3,4,5) is identified through axes A, B and C in that order. After moving A to the final position, the same entry is identified at output index (2,3,1).

The index components move with their axes. The numerical entry stored at that location is not being multiplied or replaced. A change of coordinates within the array is separate from an arithmetic change to its contents.

This index example also shows why shape alone is not the entire explanation. The output dimensions describe the arrangement, while the index mapping connects a particular input entry to its resulting position.

Several axes can be moved together

The reference permits a sequence of source axes and a sequence of destinations. Source positions must be unique, and destination positions must also be unique. Each selected source needs a corresponding destination.

For x with shape (3,4,5), the documented example np.moveaxis(x,[0,1],[-1,-2]) gives shape (5,4,3). Axis zero moves to the final position, and axis one moves to the preceding position.

Do not explain this as a series of separate calls that continually renumber the remaining input. The source sequence identifies original axes for the requested arrangement. State the pairings clearly, then read the resulting shape.

The documented result is a view

The reference describes the returned array as a view of the input array. A new visible axis order should therefore not be described as an independent snapshot of all the numerical data.

If later work requires separate storage, that is an additional requirement. Moving axes answers an arrangement question; it does not by itself establish that later changes are isolated from the original array.

Keep the shape, index mapping and view property separate when presenting the result. They explain different aspects of the same operation and prevent a familiar-looking printed array from carrying an unsupported storage claim.

State what moves and what stays ordered

Continue learning with Academia Master Trader at academiamastertrader.com.br. Aprenda provides access to educational material. Name each source axis, state its destination and read the remaining axes in order. That makes an axis movement clear without confusing it with a pairwise exchange, a numerical transformation or a complete reversal of every dimension.

NumPy swapaxes exchanges two array axes while leaving the other axes in their existing positions

A multidimensional array can describe the same entries through a different order of dimensions. NumPy swapaxes performs a specific version of that change: it exchanges two named axes. The function takes the input array and the two axis numbers, making the selected exchange explicit.

Academia Master Trader presents this explanation in English for readers in Samoa. The examples concern numerical arrays only. They are not prices, trading signals or financial results. Reading axis numbers separately from dimension lengths helps explain what changes and what remains in place.

Start with a matrix that has one row

Let x be a NumPy array with one row, [1,2,3], and shape (1,3). The expression np.swapaxes(x,0,1) produces three rows: [1], [2] and [3]. The output shape is (3,1).

The first axis and the second axis exchange places. The input's three-column dimension becomes the output's three-row dimension, while its single-row dimension becomes the single-column dimension.

Original diagram: NumPy swapaxes exchanges axes zero and one of a one-by-three array, turning the row one two three into three single-entry rows and changing the shape to three by one.

The values remain one, two and three. They are not summed, sorted or replaced. The operation changes how existing entries are indexed through the selected axes.

A single row is not a one-dimensional vector

The shape (1,3) contains two dimensions. The shape (3,) contains only one. Both can display the values one, two and three in a horizontal line, but they do not supply the same set of axes.

The reference's first example deliberately uses a two-dimensional input with a single row. That provides axis zero and axis one for the exchange. Do not remove the extra dimension from the explanation and still describe the same operation.

Read the shape before choosing axis numbers. An axis names a dimension that exists in the input; it is not created merely by including its number in the function call.

Axis numbers are positions, not lengths

For an input shape (2,3,4), exchanging axes zero and two gives shape (4,3,2). The middle axis remains in its original position. The lengths two and four move because the dimensions they describe have exchanged places.

The arguments zero and two identify the first and third axes. They do not request dimensions with lengths zero and two. Keep the axis identifiers separate from the numbers written in the input shape.

Writing both shapes side by side is useful. Mark the two exchanged positions and leave the middle position unmarked. That makes the scope of this operation clearer than saying that every dimension has been reversed.

A square shape can hide the exchange

The reference includes a three-dimensional array with shape (2,2,2). Exchanging axes zero and two leaves that shape unchanged, because both exchanged dimensions have length two. The entries still move to different indexed positions.

The input has two blocks: rows [0,1] and [2,3] in the first block, followed by rows [4,5] and [6,7] in the second. After np.swapaxes(x,0,2), the first block has rows [0,4] and [2,6]; the second has rows [1,5] and [3,7].

The equal dimension lengths make shape an incomplete description of the result. Read selected entries as well as the shape. An unchanged shape does not establish that the arrangement stayed unchanged.

Follow an index to understand the rule

In that three-dimensional example, the value one begins at index (0,0,1). Exchanging axes zero and two places it at (1,0,0). The middle index stays zero while the outer index positions exchange places.

This is a rule about index positions, not about reversing the values within every row. The value one remains one, and the new location follows from the selected axes.

A single traced entry can explain a large printed result. State its original index, exchange the selected index positions and identify the resulting location. That links the function call to the output without depending only on visual block layout.

Distinguish a pairwise exchange from a general permutation

Swapaxes names two axes to exchange. A general transpose can specify an entire ordering of axes. When describing a pairwise exchange, the two-axis function makes that intention direct.

For shape (2,3,4), swapping zero and one yields (3,2,4). A default transpose would instead reverse the complete axis order to (4,3,2). The two operations need not produce the same arrangement or shape.

Choose an explanation that matches the intended change. Do not call every axis operation a reversal, because a two-axis exchange can leave several other dimensions untouched.

Keep the return-value condition

The reference states that, for NumPy versions from 1.10.0 onwards, an ndarray input returns a view; otherwise a new array is created. Keep the input condition when describing storage behaviour.

A view is not automatically an independent snapshot. If later work needs separate storage, that is a different requirement from exchanging two axes. A changed printed arrangement does not itself show that a separate copy exists.

For this lesson's matrix example, name x as a NumPy array before discussing its view result. That prevents a statement about one input type from becoming a broader claim about every accepted input.

Explain the selected pair clearly

Continue learning with Academia Master Trader at academiamastertrader.com.br. Aprenda provides access to educational material. Read the input shape, name the two axes and follow an entry into the output. This keeps a pairwise axis exchange distinct from creating a dimension, reversing entries or applying a complete default transpose.

NumPy transpose changes the order of an array's axes rather than sorting or reversing its numerical values

An array's dimensions describe how its entries are arranged. NumPy transpose changes the order of those axes. In two dimensions, it gives the familiar matrix transpose: rows become columns and columns become rows. The operation should be explained through positions and shape, rather than described as a numerical calculation.

Academia Master Trader presents this explanation in English for readers in Vanuatu. The examples concern numerical arrays only. They are not prices, trading signals or financial results. A rectangular matrix makes the change of arrangement visible, while a vector shows an important limit of the operation.

Begin with a rectangular matrix

Let a contain rows [1,2,3] and [4,5,6]. Its shape is (2,3). The expression np.transpose(a) produces rows [1,4], [2,5] and [3,6], with shape (3,2).

The first input row becomes the first output column. The second input row becomes the second output column. The value two, originally in the first row and second column, moves to the second row and first column.

Original diagram: a two-by-three matrix with rows one two three and four five six becomes a three-by-two matrix with rows one four, two five and three six after NumPy transpose.

There are six values before and after the operation. The row and column counts exchange places, but no new numerical values are created. Stating the two shapes helps separate a change of arrangement from a change of array size.

A transpose is not a quarter turn

The transposed output begins with [1,4]. A counterclockwise quarter turn of the same matrix would instead begin with [3,6]. Both can produce a three-row arrangement, but their entry positions differ.

A matching output shape therefore does not prove that two operations are equivalent. Follow a specific entry from its original row and column to its new position. That reveals the distinction more clearly than comparing only the dimensions.

Transposition is also not sorting. The output is determined by the axes, regardless of whether the numerical values happen to be increasing, decreasing or mixed. It is the positions that supply the rule.

A one-dimensional vector stays one-dimensional

For the vector [1,2,3,4], np.transpose(a) leaves the vector unchanged. Its shape remains (4,). There is only one axis, so changing the axis order does not turn it into a two-dimensional column.

The reference makes this distinction explicit. To obtain a two-dimensional column from a one-dimensional array, an additional dimension must be introduced. Transposition by itself does not supply that extra axis.

This matters when describing a vector as a row or column. A printed horizontal sequence can still be a one-dimensional array. Read its shape before assuming that transposition will exchange a row dimension with a column dimension.

The default reverses the order of axes

When axes is omitted, transpose reverses the axis order. For a two-dimensional array, (0,1) becomes (1,0). For an input shape (2,3,4,5), the default output shape is (5,4,3,2).

That rule reverses the list of dimensions, not the numerical sequence within every dimension. It should not be confused with flipping entries along an axis. An axis permutation changes which dimension occupies each position in the array description.

For a higher-dimensional input, write the original shape and its reversed order side by side. That makes the default understandable even when a full printed array would contain too many entries to read comfortably.

An explicit permutation names the input axes

The axes argument must contain a permutation of the input axes. The axis at position i in the output corresponds to input axis axes[i]. This is an output-order specification, not a list of new dimension lengths.

For an input with shape (1,2,3), np.transpose(a,(1,0,2)) gives shape (2,1,3). The output first uses input axis one, then input axis zero, then input axis two.

All input axes appear once in that specification. Do not interpret (1,0,2) as a request to create dimensions of lengths one, zero and two. The numbers identify existing axes and state their new order.

Negative axis names count from the end

The documentation allows negative indices in an axis permutation. For an input shape (3,4,5), np.transpose(a,(-1,0,-2)) gives shape (5,3,4).

Here, negative one names the final input axis and negative two names the preceding input axis. The tuple therefore chooses the third, first and second input dimensions in that output order.

The negative signs do not negate any entries and do not request negative dimension lengths. They are a convention for naming axes relative to the end of the input's axis list.

A view is returned whenever possible

The reference states that transpose returns a view whenever possible. Keep that qualification. It is more precise than saying that every possible use always creates an independent copy, or that every use has identical storage behaviour.

A displayed change in layout is not evidence of independent storage. If a later operation needs a separate snapshot of the entries, that requirement should be considered separately from the axis permutation.

When presenting an example, identify the output shape and the axis order first. Discuss storage only with the documented qualification, rather than making a broader promise from the appearance of a printed matrix.

Read positions through the shape

Continue learning with Academia Master Trader at academiamastertrader.com.br. Aprenda provides access to educational material. State the input shape, name the output axis order and follow one entry to its new position. Those details keep transposition distinct from rotation, reversal and adding a dimension.

NumPy rot90 rotates an array by quarter turns in a plane defined by two different axes

Turning a matrix through a right angle changes the positions of its entries in a particular way. NumPy rot90 expresses that operation as a number of quarter turns within a plane defined by two axes. For a two-dimensional array with the default settings, one turn is counterclockwise.

Academia Master Trader presents this explanation in English for readers in Solomon Islands. The examples concern numerical arrays only. They are not prices, trading signals or financial results. Reading the selected plane, the turn count and the output arrangement together makes the operation clear.

Begin with a two-by-two matrix

Let m have rows [1,2] and [3,4]. The expression np.rot90(m) produces rows [2,4] and [1,3]. This is the reference's basic two-dimensional example, with the default turn count of one and axes (0,1).

Follow the value two. It begins at the upper right and ends at the upper left. Four begins at the lower right and ends at the upper right. These positions show the counterclockwise turn without relying on the function name alone.

Original diagram: the matrix with rows one two and three four rotates one quarter turn counterclockwise into rows two four and one three under the default NumPy rot90 settings.

The values remain one, two, three and four. Rotation does not calculate a new numerical value for any entry. It changes their arrangement according to the selected axes and the number of turns.

The turn count is not a degree value

The parameter k counts how many times the array is rotated by ninety degrees. The default is one. For the same m, np.rot90(m,2) returns rows [4,3] and [2,1], corresponding to two quarter turns.

Do not read k as a direct angle in degrees. A value of two means two right-angle turns, not two degrees. Naming the unit as quarter turns keeps the parameter's role separate from a general geometric angle.

A useful explanation writes the function call, states the turn count and then reads the full result. That sequence gives the reader a concrete arrangement to compare with the original matrix.

Reversing the axes reverses the direction

The reference defines the rotation direction from the first selected axis towards the second. With the default two-dimensional axes (0,1), the default turn is counterclockwise. Swapping their order to (1,0) reverses that direction.

For the same m, np.rot90(m,1,axes=(1,0)) produces rows [3,1] and [4,2]. The value three moves from the lower left to the upper left, making the clockwise arrangement visible.

The documentation also states that this reversed axis order with k equal to one is equivalent to keeping axes (0,1) and using k equal to negative one. The sign and the ordered axis pair both matter when explaining direction.

Two different axes define the plane

The input must have at least two dimensions. The axes parameter names two different axes, because those axes define the plane in which the rotation occurs. A single vector does not supply that two-axis plane on its own.

For an array with more than two dimensions, the selected pair still determines the plane. The function does not require every dimension to participate in the rotation. Specify the pair rather than describing the operation only as rotating the array.

The reference includes a three-dimensional example using axes (1,2). That selection rotates within the plane of the final two dimensions while retaining the other dimension as a separate part of the arrangement. A two-dimensional diagram should not be mistaken for a picture of every possible plane.

A rectangular matrix can change its shape

A square example hides a useful detail. Let r have rows [1,2,3] and [4,5,6], giving it shape (2,3). The expression np.rot90(r) produces rows [3,6], [2,5] and [1,4].

The output shape is (3,2). There are still six entries, but the row and column counts exchange places under this quarter turn. Preserving the number of entries is not the same as preserving the shape.

Read both dimensions before and after the operation. That makes rotation distinct from reversing the order of rows or columns, where a rectangular two-dimensional array can retain its original shape.

The documented result is a view

The reference describes the return value as a rotated view of the input. Do not call it an independent full copy merely because its printed layout differs from the original. Arrangement and storage independence are separate properties.

That distinction matters if a later step changes entries. A view should not automatically be treated as a separate snapshot. If independent storage is needed, describe that as an additional requirement rather than as something guaranteed by rotation itself.

For teaching, keep the claims precise: the operation rotates entry positions, the axes define a plane, k counts quarter turns and the documented result is a view. None of those properties implies a new measurement or new numerical observation.

Read direction and shape together

Continue learning with Academia Master Trader at academiamastertrader.com.br. Aprenda provides access to educational material. Name the ordered axes, state the number of quarter turns and compare the input and output shapes. Following one corner entry then makes the rotation easy to distinguish from reversal or a simple exchange of row and column labels.

NumPy roll moves entries around an array axis and brings values that cross the boundary back at the other end

Moving entries by a fixed number of positions can mean several different things. NumPy roll uses a circular arrangement: entries that pass one end return at the other. It does not fill newly exposed positions with zeros or discard the entries that cross the boundary. The output keeps the input shape.

Academia Master Trader presents this explanation in English for readers in Papua New Guinea. The examples describe numerical arrays only. They are not prices, trading signals or financial results. A clear account of the shift, the axis and the boundary behaviour makes this operation easier to read.

Begin with a short circular shift

Let a be [0,1,2,3,4]. The expression np.roll(a,2) produces [3,4,0,1,2]. Each entry moves two positions in the positive direction, and the final two entries reappear at the beginning.

There are still five values. Nothing is added to fill an empty space, because the movement wraps around the boundary. The order within the wrapped group remains three followed by four, then the remaining sequence continues from zero.

Original diagram: NumPy roll moves the vector zero one two three four by positive two positions, producing three four zero one two, with the wrapped entries highlighted.

The result is not [0,0,0,1,2], which would describe a different boundary rule. It is also not [2,1,0,4,3], because roll is not a reversal. A small complete result is often clearer than the phrase move the values.

A negative shift moves the other way

For the same a, np.roll(a,-2) produces [2,3,4,0,1]. The first two entries move around to the end. Positive and negative shifts describe opposite directions along the array axis.

The sign belongs to the positional shift, not to the values. The zero and one retain their values when they reappear at the end. Rolling an array does not negate its entries or calculate a numerical difference between neighbours.

Name the shift direction together with the chosen example. Phrases such as forwards and backwards can be read differently, while the actual input and output make the intended arrangement explicit.

The default flattens before shifting

Now let x have rows [0,1,2,3,4] and [5,6,7,8,9]. Its shape is (2,5). The expression np.roll(x,1) returns rows [9,0,1,2,3] and [4,5,6,7,8].

With no axis supplied, the function first uses the flattened array for the shift and then restores the original shape. Nine wraps to the beginning of the flattened sequence, and four moves into the first position of the second row.

The restored shape does not mean that each original row was shifted independently. The movement crossed a row boundary in the flattened arrangement. Explain that default explicitly when presenting a two-dimensional input.

Select the row axis

The expression np.roll(x,1,axis=0) produces rows [5,6,7,8,9] and [0,1,2,3,4]. Here the rows move as units along the first axis, with the bottom row returning at the top.

The entries within each row keep their order. The output still has shape (2,5), but the grouping differs from the result with no axis supplied. Both outputs preserve shape, so shape alone does not identify the movement.

Because this example has only two rows, a shift of positive one and a shift of negative one along axis zero give the same row order. That equality follows from this particular two-position cycle; it is not a general rule for every array length.

Select the column axis

For the same x, np.roll(x,1,axis=1) produces rows [4,0,1,2,3] and [9,5,6,7,8]. Each row wraps independently along the column axis.

Compare this with the default result. Under the explicit column axis, four returns to the beginning of its own row and nine returns to the beginning of its own row. Under the default flattened shift, nine moves to the start of the whole arrangement.

Reading one complete row makes this distinction concrete. State the axis before describing which entry appears first, because the same shift count can produce different outputs under different axis choices.

Multiple axes can have separate shifts

The reference supports a tuple of shift counts together with a tuple of axes of the same length. Each shift corresponds to the axis in the same tuple position. The order of that pairing should be written clearly.

For the two-row x, np.roll(x,(2,1),axis=(1,0)) produces rows [8,9,5,6,7] and [3,4,0,1,2]. The column axis receives a shift of two, and the row axis receives a shift of one.

An integer shift can also be used with a tuple of axes, applying that same count to each named axis. Distinguish a shared count from separate counts, rather than assuming that every multidimensional operation has only one direction.

Explain the boundary rule first

Continue learning with Academia Master Trader at academiamastertrader.com.br. Aprenda provides access to educational material. Identify the shift count, state whether the array is flattened or an axis is selected, and show where wrapped entries return. That keeps circular movement distinct from reversal, padding and removing values.

NumPy flip reverses the order along selected axes while preserving an array's shape

Reversing an array means changing where its entries appear, not changing the values themselves. NumPy flip reverses their order along a chosen axis or set of axes. The output retains the input shape. Reading both the axis and the arrangement is therefore more useful than describing the operation simply as turning data around.

Academia Master Trader presents this explanation in English for readers in Fiji. The numerical examples illustrate array structure only. They are not prices, trading signals or financial results. A small matrix makes the difference between reversing rows, reversing columns and reversing both easy to see.

Begin with a vector

For the vector [1,2,3,4], reversing its only axis produces [4,3,2,1]. The first entry becomes the last and the last becomes the first. There are still four entries, and their numerical values remain unchanged.

This operation is not sorting. It follows the existing order in reverse, whatever that order happens to be. A vector such as [3,1,4,2] becomes [2,4,1,3], rather than a sequence arranged from largest to smallest.

Stating that distinction matters whenever the input is not already ordered numerically. Reverse order describes positions. Ascending or descending order describes a relationship between values, which is a different requirement.

Reverse the row axis

Let x contain rows [1,2,3] and [4,5,6]. Its shape is (2,3). The expression np.flip(x,axis=0) produces rows [4,5,6] and [1,2,3]. The bottom row becomes the top row.

Within each row, the entry order is unchanged. Four still precedes five and six; one still precedes two and three. Only the order along the first axis is reversed in this example.

The output shape remains (2,3). There are still two rows and three columns. Reordering those rows does not exchange the dimensions or turn the matrix into a three-row array.

Original diagram: the two rows one two three and four five six are reversed along axis zero, producing four five six followed by one two three while keeping shape two by three.

Reverse the column axis

For the same x, np.flip(x,axis=1) produces rows [3,2,1] and [6,5,4]. The top row stays the top row, but the entries within each row appear in reverse column order.

This output also has shape (2,3). A shape check alone cannot distinguish it from the axis-zero result, because both operations preserve the dimensions. The selected axis and a reading of the entries explain what changed.

For a two-dimensional array, axis zero and axis one identify different directions of arrangement. Always tie those names to the displayed matrix rather than assuming that the word reverse identifies one unique result.

Omit the axis to reverse every axis

The default axis is None. In this case, flip reverses all axes of the input. For the two-row x, np.flip(x) produces rows [6,5,4] and [3,2,1].

Both the row order and the order within each row are reversed. The result is not merely the axis-zero output or merely the axis-one output. The default applies the reversal across both dimensions of this matrix.

For this input, explicitly selecting axis=(0,1) gives the same arrangement. A tuple names the axes to reverse. This becomes especially useful when an input has more than two dimensions and only some of them should change order.

Read negative axes from the end

The reference allows negative axis numbers, counted from the final axis backwards. In the two-dimensional example, axis=-1 refers to the column axis, so it produces the same arrangement as axis=1.

The meaning depends on the number of dimensions. The final axis of a three-dimensional array is not its second axis. Describe a negative axis as a position counted from the end, then connect it to the actual input shape.

This is a naming convention for dimensions, not a request to make values negative. Reversing [1,2,3] does not produce [-1,-2,-3]. Order changes while the values are retained.

A view is not an independent copy

The documented return value is a view of the input with the chosen axis entries reversed. The reference explains that this makes the operation constant time. Do not describe flip as always allocating a separate full copy of the numerical data.

That distinction matters if a later step changes array entries. A view should not be treated as an independent snapshot merely because it displays a different order. If independent storage is required, that is a separate requirement from reversing the arrangement.

For a short explanation, identify three properties separately: the output shape, the visible order and whether the result is a view. They answer different questions about the operation and should not be collapsed into the single word reversed.

Name the axes before reading the result

Continue learning with Academia Master Trader at academiamastertrader.com.br. Aprenda provides access to educational material. State which axes are reversed, confirm that the shape is preserved and read a complete output row. That makes the operation clear without confusing reversal with sorting, transposition or a change in numerical sign.