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 i0 evaluates a modified Bessel function rather than a numbered array entry

Some mathematical function names look like short variable labels. NumPy i0 is the modified Bessel function of the first kind, order zero, usually written I with a subscript zero. Academia Master Trader presents this English lesson for readers in Bolivia, using selected real arguments to explain its outputs and array behaviour.

The zero names the order

After import numpy as np, the call np.i0([0.,1.,2.]) returns approximately [1.,1.26606588,2.27958530].

The zero in the name identifies the function's order. It is not an instruction to select array position zero, add a zero to each input or return a zero whenever an argument is missing.

The first input above is the number zero, and its function value is one. That input value and the order in the function name play different roles.

Keep the full function name in an explanation. Calling it simply a Bessel function can hide distinctions between modified and ordinary functions, kinds and orders.

Selected values of the modified Bessel function I0

Opposite real arguments give matching values

The call np.i0([-2.,-1.,0.,1.,2.]) returns approximately [2.27958530,1.26606588,1.,1.26606588,2.27958530].

For this function, opposite real arguments have the same value. The displayed pairs at minus one and plus one, and at minus two and plus two, illustrate that symmetry.

This does not mean all functions with Bessel in their names behave identically. The symmetry belongs to the particular function being evaluated here.

It also does not mean the result equals the input's absolute value. At either plus two or minus two, the result is approximately 2.27958530 rather than two.

An array supplies evaluation points

Each input entry is an argument at which the function is evaluated. The output keeps the input shape and associates one returned value with each supplied position.

For example, a two-by-two array of arguments yields a two-by-two arrangement of function values. NumPy does not sort those arguments or treat their positions as automatically chosen coordinates on a graph.

A list such as [0.,1.,2.] is therefore a collection of evaluation points, not a request for three different function orders.

Nor does the call solve for an argument that would produce a desired output. Evaluating a function and finding an inverse value are separate operations.

Decimal output is a numeric approximation

The displayed nontrivial values are rounded decimal summaries of floating-point calculations. Printing more digits can make comparisons clearer, but it does not create arbitrary precision.

The examples here use modest finite real inputs. They do not establish that every larger argument will remain representable in the selected floating-point format.

Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the function family, order and argument arrangement when explaining a special-function calculation.

NumPy sinc uses a pi-normalized curve with a defined value at zero

A familiar function name can hide an important normalization choice. NumPy sinc uses sine of pi times the input, divided by pi times the input, with a defined value at zero. Academia Master Trader presents this English lesson for readers in Argentina, using selected sample points to explain the curve's scale and numeric output.

The factor of pi belongs to the definition

After import numpy as np, the call np.sinc(0.5) returns approximately 0.6366197724. The mathematical expression at this nonzero point is sin(pi/2) divided by pi/2.

This is different from sin(0.5) divided by 0.5. A formula that omits the pi factors describes the unnormalized sinc convention rather than NumPy's convention.

Write the definition beside the function name when comparing sources. Two references may use the same name while assigning different horizontal scales to their curves.

The input is the argument of the normalized function. NumPy does not infer whether a number originally represented seconds, sample positions or a frequency ratio.

Selected values of the pi-normalized sinc function

Zero is defined by continuity

The call np.sinc(0.) returns 1.. At zero, directly writing the quotient of sine and its argument would produce an indeterminate zero-over-zero expression.

The sinc function uses the limiting value one at that point. It therefore connects continuously with nearby values instead of leaving a hole at the centre.

This is a defined function value, not a statement that dividing zero by zero generally equals one. Keeping those ideas separate avoids turning a particular limiting result into an invalid arithmetic rule.

Side values can be negative

The call np.sinc(1.5) returns approximately -0.2122065908. Beyond the central positive region, the normalized curve has alternating lobes.

The function is even: opposite arguments have the same mathematical value. For example, the outputs at minus 0.5 and plus 0.5 are both approximately 0.6366197724.

At a nonzero integer such as one, the mathematical value is zero. Floating-point evaluation may display a tiny residual instead; the example here produces approximately 3.898e-17.

A small residual at an expected zero should be interpreted in the context of numeric precision. It does not move the mathematical zero or establish a meaningful positive amplitude by itself.

Array shape is preserved

The call np.sinc(np.array([0.,0.5,1.5])) returns three corresponding values, approximately [1.,0.6366197724,-0.2122065908].

A multidimensional input retains its shape in the output. The function evaluates the curve at supplied arguments; it does not choose a sampling interval, build an interpolator or reconstruct a signal automatically.

Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the pi normalization, the defined centre value and the sample arguments when describing sinc output.

NumPy modf separates fractional and integral components without floor rounding

Separating a number into components requires a rule for negative values as well as positive ones. NumPy modf returns a fractional component and an integral component, in that order. Academia Master Trader presents this English lesson for readers in Brazil, using constructed values to explain output order, signs and reconstruction.

Fractional output comes first

After import numpy as np, define values = np.array([3.75,-3.75,0.25,-0.25,4.]). The assignment fraction, integral = np.modf(values) produces two arrays.

The fractional output is [0.75,-0.75,0.25,-0.25,0.]. The integral output is [3.,-3.,0.,-0.,4.].

The order matters. Assigning the first output to a variable called integral would not change what the function returns; it would only give that component a misleading name.

Each output follows the shape and position arrangement of the input. Corresponding entries describe two components of the same original number.

Fractional and integral components returned by modf

Negative components retain their direction

For minus 3.75, the integral component is minus three and the fractional component is minus 0.75. Together they add back to minus 3.75.

The integral component is taken towards zero, not towards negative infinity. A floor-based decomposition would use minus four with a positive fractional remainder instead, which is a different convention.

For minus 0.25, the fractional component is minus 0.25 and the integral component is negative zero in the floating-point output. Its numeric magnitude is zero, while its stored sign follows the negative input.

This convention makes the signed fractional component easy to interpret alongside its matching integral component. It is not a rule that forces every fractional remainder into a nonnegative interval.

Integral does not mean integer storage

The integral output contains floating-point values in these examples. The term integral describes the component's mathematical value, not a promise that its array has an integer dtype.

Integer inputs also produce floating-point outputs. For example, np.modf([2,5]) returns fractional values [0.,0.] and integral values [2.,5.].

Do not assume that selecting the second output performs a dtype conversion to integers. If another operation requires an integer array, that is a separate decision with its own numeric limits.

Components can be recombined by position

For the constructed values shown here, fraction + integral reconstructs [3.75,-3.75,0.25,-0.25,4.].

This addition uses matching positions. Sorting one output independently would break that relationship even though both arrays still contain valid numeric values.

The function does not round values to a chosen number of decimal places, format a price or split a text string at a decimal point. It operates on numeric values already supplied to NumPy.

Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Keep the fractional-first order and the negative-value convention explicit when explaining a numeric decomposition.

NumPy signbit identifies the sign flag and distinguishes negative zero

A numeric comparison and a representation-level sign check answer different questions. NumPy signbit returns a Boolean result describing whether the sign bit is set. Academia Master Trader presents this English lesson for readers in Suriname, using ordinary finite floating-point values and signed zero to make that distinction visible.

A Boolean result for each entry

After import numpy as np, define values = np.array([-4.,-0.,0.,3.]). The call np.signbit(values) returns [True,True,False,False].

The negative nonzero value has its sign bit set. So does negative zero. Positive zero and the positive nonzero value do not have that bit set in this example.

The output contains Boolean values, not the numbers minus one, zero and one. It records a property of each input representation without replacing the input values themselves.

A scalar input produces a scalar Boolean result. For instance, np.signbit(-2.5) returns True, while np.signbit(2.5) returns False.

Sign-bit results for negative values and signed zero

Negative zero explains the difference

For the same array, values < 0 returns [True,False,False,False]. Negative zero is not less than zero, even though its sign bit is set.

The expression values == 0 returns [False,True,True,False]. Both signed zeros compare equal to zero.

These results do not contradict each other. The comparison asks about numeric order or equality; signbit asks about the sign flag carried by the representation.

Keep the chosen question explicit when building a selection rule. A rule for values strictly below zero should not be silently replaced by a rule that also includes negative zero.

A mask can select the marked entries

With mask = np.signbit(values), the selection values[mask] returns [-4.,-0.] for this constructed array.

The mask keeps the same arrangement as the input array. Each Boolean belongs to the corresponding position, so preserving alignment matters when applying it elsewhere.

A multidimensional input similarly produces a Boolean array with the same shape. The function does not collapse rows into one summary or count marked entries automatically.

Selection also leaves the meaning of the selected values unchanged. A negative-zero entry remains zero numerically; its inclusion reflects the mask's sign-bit criterion.

Representation is not a rounding rule

Signbit does not round a small negative value to zero, measure how far it is from zero or decide whether it is negligible for a particular application.

A separate threshold rule may be useful for such questions, but that rule needs its own stated units and purpose. The sign flag alone supplies neither.

These finite examples isolate the sign-bit distinction. They do not provide a general procedure for classifying every exceptional floating-point value.

Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Name whether a rule concerns numeric order, equality or the stored sign flag before selecting entries.

NumPy nextafter moves to a neighbouring representable floating-point value

Floating-point numbers occupy a discrete set of representable values. Between two neighbouring members of that set, there may be mathematical numbers that the chosen format cannot store exactly. Academia Master Trader presents this English lesson for readers in Haiti, using NumPy nextafter to explain a single step through that numeric representation.

The second input selects a direction

After import numpy as np, the call np.nextafter(1.,2.) returns 1.0000000000000002 for the float64 example used here. It finds the next representable value above one, in the direction of two.

The function does not jump straight to two. The second input supplies a direction, while the spacing of the numeric format determines the next available value.

The call np.nextafter(1.,100.) produces the same result in this example. A more distant destination in the same direction does not request a larger first step.

By contrast, np.nextafter(1.,0.) returns 0.9999999999999999. This is the neighbouring representable value below one.

Neighbouring float64 values around one

One step is not a fixed decimal increment

The decimal gap above one differs from the gap below it in these float64 examples. Floating-point spacing follows the representation rather than a universal decimal step size.

Nextafter therefore does not mean add 0.01, keep a chosen number of decimal places or move a specified percentage towards the second input.

A displayed value can also hide the step. If an output display rounds both the original and its neighbour to a short decimal string, they may look identical even though their stored values differ.

Use enough displayed precision when explaining these examples. A rounded label alone cannot establish that no movement occurred.

The numeric format matters

The call np.nextafter(np.float32(1),np.float32(2)) uses float32 inputs and commonly displays 1.0000001. Its neighbouring value is farther from one than the float64 neighbour shown above.

Keep both inputs explicitly typed when comparing formats. Changing one input's type can affect the operation's selected numeric type, so an informal comparison may no longer describe the intended format.

The purpose is to inspect representable neighbours, not to manufacture extra precision. Taking a step changes the value to another member of the available set.

Arrays apply the rule position by position

Two compatible arrays can provide separate starting values and directions. Broadcasting also allows a scalar direction to apply across an array of starting values.

The output shape follows the compatible inputs. Each position uses its own starting value, so a shared direction does not imply an identical numeric increment everywhere.

When the two inputs are the same ordinary finite value, the result is that value. For example, np.nextafter(1.,1.) returns 1. rather than choosing an arbitrary side.

Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the starting value, direction and numeric format before describing a neighbouring floating-point value.

NumPy logaddexp adds positive quantities while keeping their representation logarithmic

A logarithmic representation stores the logarithm of a quantity rather than the quantity itself. Combining two such records requires attention: adding their stored numbers directly describes multiplication of the original quantities. Academia Master Trader presents this English lesson for readers in Myanmar, using NumPy logaddexp to explain addition in logarithmic form.

Inputs already represent logarithms

The function computes the natural logarithm of the sum of the exponentials of two inputs. In mathematical notation, the relationship is log(exp(a) + exp(b)). The output remains in the natural-logarithm representation.

After import numpy as np, define a = np.log(2.) and b = np.log(3.). The call np.logaddexp(a,b) returns approximately 1.6094379124, which is the natural logarithm of five.

The input quantities were two and three. Their sum is five, but the returned number is not five because the output is still logarithmic.

To express that result on the original scale, apply np.exp to the returned value. Small floating-point differences can appear in the displayed decimal representation.

Adding quantities represented by natural logarithms

Direct addition means something different

The expression a + b gives the logarithm of six in this example, not the logarithm of five. Adding logarithms corresponds to multiplying the original positive quantities.

Likewise, np.logaddexp(2.,3.) does not calculate the logarithm of two plus three. It treats two and three as the stored logarithms themselves and combines their exponentials.

Write down which scale each input uses before choosing the operation. A quantity and its logarithm may both be ordinary floating-point numbers, so their storage type alone cannot reveal their meaning.

Large magnitudes show why the operation matters

The call np.logaddexp(1000.,1000.) returns approximately 1000.6931471806. The two inputs are equal, so their combined result is the common input plus the natural logarithm of two.

Computing both exponentials separately in ordinary floating-point arithmetic can exceed the available range for this example. Logaddexp allows the combined logarithmic value to remain representable without explicitly forming those enormous quantities first.

The call np.logaddexp(-1000.,-1000.) similarly returns approximately -999.3068528194. Keeping the representation logarithmic also helps with extremely small original quantities.

This does not grant arbitrary precision or unlimited range to every later operation. Converting a result back with exp still depends on whether the original-scale quantity fits the chosen numeric representation.

Arrays combine corresponding positions

Both inputs may be arrays, or one may be a scalar. Their shapes must be compatible for broadcasting, and each output combines the corresponding pair of logarithmic inputs.

The function uses natural logarithms. A different base needs a matching operation or an explicit conversion; changing a label does not change the mathematics.

Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Keep the input scale and output scale explicit whenever combining logarithmic records.

NumPy ldexp constructs floating values from multipliers and integer powers of two

Binary scaling combines a multiplier with an integer exponent of two. NumPy ldexp performs that combination element by element, returning floating-point values. Academia Master Trader presents this English lesson for readers in Timor-Leste, using constructed inputs to explain paired scaling, negative exponents and compatible input shapes.

Each exponent selects a power of two

After import numpy as np, define multiplier = np.array([0.75,-0.625,0.5]) and exponent = np.array([3,4,-2]). The call np.ldexp(multiplier,exponent) returns [6.,-10.,0.125].

The first multiplier is scaled by two cubed, so 0.75 times eight gives six. The second is scaled by two to the fourth power, so minus 0.625 times sixteen gives minus ten.

The third uses exponent minus two. Its factor is one quarter, and multiplying 0.5 by that factor gives 0.125.

The exponent input contains integers. It describes powers of two, not decimal places, a general base chosen separately or a count of repeated additions.

Multipliers combined with powers of two

A scalar exponent supplies a shared scale

The call np.ldexp([1.5,2.5],2) returns [6.,10.]. The scalar exponent two supplies a factor of four to both multipliers.

The multiplier does not need to be a fraction between minus one and one. Here both inputs exceed one in magnitude, yet the same power-of-two relationship applies.

Similarly, np.ldexp(1.5,[0,1,2]) returns [1.5,3.,6.]. A scalar multiplier can be shared across several integer exponents, producing one output for each compatible position.

Broadcasting determines the common output shape. It does not pair unrelated arrays by sorting them or infer which scale should belong to a particular observation.

Negative exponents reduce the scale

The call np.ldexp(8.,[-1,-2,-3]) returns [4.,2.,1.]. Each negative exponent selects a reciprocal power of two.

This differs from changing a sign: all three results remain positive because the multiplier is positive and powers of two are positive. A negative multiplier would retain its negative sign under these finite examples.

An exponent of zero supplies a factor of one. It does not erase the multiplier, round it or create a zero output automatically.

Reconstruction keeps two components together

A decomposition into a binary fraction and exponent can be reversed by passing those components to ldexp. This is the operation's relationship to frexp, which returns those components separately.

Keep corresponding positions aligned. Combining one fraction with another entry's exponent reconstructs a different value, even when both component arrays have valid shapes.

The function does not support complex dtypes. It also works within floating-point representation rather than promising unlimited numeric range or arbitrary precision.

These examples describe exact constructed values with simple binary representations. They explain scaling, not a forecast or an automatic decision about real-world data.

Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the multiplier, integer exponent and compatible output arrangement when explaining binary scaling.

NumPy frexp separates each number into a fraction and a power of two

A real number can be described as a fractional component multiplied by a power of two. NumPy frexp returns those two components separately. Academia Master Trader presents this English lesson for readers in South Africa, using constructed values to explain paired outputs, binary scaling and the difference between decomposition and rounding.

One input produces two corresponding outputs

After import numpy as np, define values = np.array([6.,-10.,0.125,0.]). The statement fraction, exponent = np.frexp(values) assigns one output array to each name.

The fractions are [0.75,-0.625,0.5,0.], and the exponents are [3,4,-2,0]. Corresponding positions belong together: six is represented by the fraction 0.75 and exponent three.

The relationship is values = fraction * 2**exponent. For the first entry, 0.75 multiplied by eight gives six. For the second, minus 0.625 multiplied by sixteen gives minus ten.

Both arrays follow the input shape. They are not a sorted list of fractions followed by unrelated exponents, and neither output alone describes the complete original magnitude.

Real values decomposed into fractions and binary exponents

Negative exponents describe smaller scales

The third input, 0.125, becomes fraction 0.5 with exponent minus two. Two raised to minus two is one quarter, and one half multiplied by one quarter gives one eighth.

The exponent therefore need not be positive. It records the required power-of-two scale, rather than counting decimal places or digits displayed after a decimal point.

The fractional component preserves the input's sign for these nonzero examples. A negative exponent does not make a positive fraction negative: it changes the scale through a reciprocal power of two.

Zero has its own simple representation

For the zero input in this example, both returned components are zero. The reconstruction is zero multiplied by one, which remains zero.

Keep zero separate when describing the size of a nonzero fractional component. The displayed arrays show why a single informal rule about all fractions being near one cannot describe every input.

This lesson uses finite real values. The function does not support complex dtypes, so complex-valued data require a different operation rather than assuming the same two-output convention applies.

Decomposition is not decimal rounding

Frexp does not ask for a number of decimal places, remove the fractional part or round six to a nearby power of two. It returns components whose combination describes the supplied value.

The exponent is an integer array, while the fractional output contains floating-point values. The name fraction here refers to the returned binary scaling component, not simply the digits after a decimal point.

For these constructed values, fraction * np.power(2.,exponent) reconstructs [6.,-10.,0.125,0.]. Using a floating base makes the negative exponent explicit in the reconstruction expression.

Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Keep each fraction beside its corresponding exponent and record that the scale uses powers of two.

NumPy copysign combines the magnitude of one input with the sign of another

Changing a sign need not mean multiplying two full values. NumPy copysign takes magnitude from its first input and sign from its second input. Academia Master Trader presents this English lesson for readers in Mozambique, using constructed arrays to explain the two roles, scalar broadcasting and signed floating-point zero.

The two inputs supply different information

After import numpy as np, define values = np.array([-2.5,0.,7.]) and direction = np.array([1.,-4.,-1.]). The call np.copysign(values,direction) returns [2.5,-0.,-7.].

The first result has magnitude two and a half because that magnitude came from the first input. Its positive sign came from the corresponding positive second input.

The final result has magnitude seven and a negative sign. The second input's magnitude of one does not replace seven. Likewise, the magnitude four in the middle second input does not multiply or scale zero.

The function uses the second input as a sign source, not as a multiplier, a weight or a threshold.

Magnitude and sign combined element by element

A scalar supplies one sign across an array

The call np.copysign(values,-1.) returns [-2.5,-0.,-7.]. A negative scalar supplies a negative sign to every corresponding output entry.

Using np.copysign(values,1.) returns [2.5,0.,7.]. Both a previously negative magnitude and a previously positive magnitude receive the scalar's positive sign.

This is not the same as ordinary multiplication by minus one. Multiplying minus two and a half by minus one produces positive two and a half; copying a negative sign onto it leaves it negative.

The distinction is useful whenever the requirement is a chosen sign with preserved magnitude, rather than an algebraic reversal of the original sign.

Floating-point zero can carry a sign

The middle result in the opening example is negative zero. Its magnitude is still zero, but its floating-point sign bit is negative.

The call np.copysign(3.,-0.) returns -3.. The sign source is negative zero, even though negative zero compares equal to positive zero numerically.

A sign rule based only on whether the second input is less than zero would miss this distinction. Copysign transfers its sign instead of relying on that comparison.

Signed zero is a numeric representation detail. It does not indicate an extra observation or a value with a nonzero magnitude.

Broadcasting determines the output arrangement

A scalar first input can also combine with several sign sources. The call np.copysign(2.,[-1.,1.,-1.]) returns [-2.,2.,-2.].

For array inputs, their shapes must broadcast to a common output shape. Corresponding magnitudes and signs are then combined element by element under that arrangement.

The operation does not sort values, calculate absolute differences or decide which sign a real-world observation ought to have. The sign source must already express the intended convention.

Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Name the magnitude source and sign source separately when explaining a sign-copying calculation.

NumPy heaviside applies a step rule with an explicit value at zero

A step function distinguishes negative inputs from positive inputs, while leaving one important choice at the boundary. NumPy heaviside makes that choice explicit through its second argument. Academia Master Trader presents this English lesson for readers in Angola, using constructed values to explain the boundary, shifted thresholds and element-wise evaluation.

Three input cases define the rule

After import numpy as np, define values = np.array([-3.,0.,4.]). The call np.heaviside(values,0.5) returns [0.,0.5,1.].

A negative first input produces zero. A positive first input produces one. When the first input equals zero, the result is the second input, here one half.

The second argument is therefore not a threshold location. It supplies the output specifically at zero. Confusing these roles would change the intended calculation.

This step rule does not retain the magnitude of each input: minus three and another negative number both map to zero. Positive numbers similarly map to one, regardless of their size.

Heaviside rule with a chosen boundary value

The zero convention is part of the calculation

The call np.heaviside(values,0.) returns [0.,0.,1.], while np.heaviside(values,1.) returns [0.,1.,1.].

Only the zero input changes between these examples. Negative and positive inputs keep their outputs of zero and one.

A boundary value of one half is a common convention, but it is not forced by the function. Choose and record the convention required by the mathematical definition being implemented.

Exact equality to zero matters here. A tiny positive input still produces one, and a tiny negative input produces zero. The second argument does not establish a tolerance interval around the boundary.

Shift the first input to move a threshold

To place a boundary at five, define samples = np.array([4.,5.,6.]) and evaluate np.heaviside(samples-5.,0.5). The result is [0.,0.5,1.].

Subtracting five moves the chosen boundary to zero before the step rule is applied. The second argument still determines only the output at that boundary.

This construction explains the operation without implying a decision about real observations. A numeric step is a transformation of supplied values, not a prediction, a probability or an instruction to act.

Boundary values can vary element by element

The call np.heaviside([0.,0.,0.],[0.,0.5,1.]) returns [0.,0.5,1.]. Each zero input receives its corresponding second input.

The two inputs must have shapes that broadcast to a common output shape. A scalar boundary value can be shared across a vector, as in the opening example, while a compatible array can supply separate boundary values.

The operation is element-wise. It does not sort inputs, count how often a threshold was crossed or remember an earlier value in a sequence. Those tasks require their own operations and an explicit interpretation of order.

Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the first-input transformation and the chosen value at zero when explaining a step calculation.