Question
A drawback of cubic resampling is that it produces DN overshoot on either side of sharp edges. The magnitude of the overshoot is directly proportional
A drawback of cubic resampling is that it produces DN overshoot on either side of sharp edges. The magnitude of the overshoot is directly proportional to the magnitude of α. Although this characteristic contributes to the visual sharpness of the processed image, it is undesirable for further numerical analyses where radiometric accuracy is of prime importance. It has been shown (Keys, 1981; Park and Schowengerdt, 1983) that -0.5 is an optimal value for α (rather than the -1 commonly used), and the value of -0.5 was implemented early in the production of TM data (Fischel, 1984). The two interpolation functions are compared to the sinc function in Fig. 7-14. The effect of the nearest-neighbor, linear, and PCC resampling functions on Landsat TM imagery can be seen in Fig. 7-17. PCC generally does not yield a pronounced visual improvement over bilinear interpolation and requires more computation time. For applications in which the image sharpness is not critical, nearest-neighbor resampling may produce a satisfactory product with a large savings in computer processing time compared to the other interpolation functions.Given the global coordinates of a marker, develop a search routine for identifying the position of the marker in an unstructured grid consisting of triangular cells. The routine should first discover which cell contains the marker. Current processors exploit guidance level parallelism to further develop throughput. (a) Control-stream processors use pipelining to further develop throughput. What limits throughput in the basic 5-stage pipeline portrayed underneath? [10 marks] guidance interpret/execute memory register get register get access compose back (b) What is the guideline of activity of a static information stream processor and how can it determine information conditions? [10 marks] 3 Digital Communication I What is implied by the term stream control? [3 marks] What is implied by the term credit-based stream control? [4 marks] What is implied by start-stop (or XON-XOFF) stream control? [4 marks] A beginning stop framework is utilized on a 10 kbps interface with a steady postponement of 5 ms. How much support should a beneficiary save for possible later use for "halting time" to forestall data misfortune? [3 marks] Which framework is more proper to use across the Internet and why? [6 marks] 4 Computer Graphics and Image Processing Explain how a cathode beam tube (CRT) works, including subtleties of how tone is accomplished. [8 marks] Describe a run-length encoding plan for encoding pictures whose pixels have eight-cycle power values. [8 marks] Calculate the most ideal pressure proportion attainable with your plan and depict the situation(s) in which this proportion would be accomplished. [2 marks] Calculate the absolute worst pressure proportion feasible with your plan and portray the situation(s) in which this proportion would be accomplished. [2 marks] 2 CST.2000.12.3 5 Business Studies What are the distinctions among benefit and misfortune and income proclamations?
What is meant by a functional dependency between sets of attributes in a relational
database schema? What conditions must be satisfied for a relation to be in Boyce-
Codd Normal Form (BCNF)? [4 marks]
The Department of Transport is implementing plans to tax traffic congestion. From
2002, cars will carry approved radio-control units which at first will be used only
to monitor vehicle movement. In controlled areas sensors identify all vehicles,
recording their positions periodically. Amber signs flash when overall traffic flow
drops below some threshold, and vehicles within the controlled area may be fined
for lack of progress.
The owner of each vehicle has an account with the Department of Transport; owners
can transfer funds to ensure that their account is in credit. Once credit is exhausted
the level of fine increases by a factor 3, and a summons is sent by mail to the vehicle
owner's registered address. In order to maintain proper accounts it is essential to
keep an accurate record of each monitored offence.
You are employed to design the relational database that will enforce the scheme,
including provision for vehicle and driver registration, monitoring of vehicle offences
and management of vehicle accounts. Describe the schema you propose, stating
clearly any assumptions that you make. You need not discuss the calculation of the
fines due. [12 marks]
Outline the flow of information through the database. T[5 marks] What are the distinctions among obligation and value finance? [5 marks] What is a choice and how should it be esteemed? [5 marks] Comment on the ongoing costs of innovative stocks. [5 marks] 6 Comparative Programming Languages Outline how you would carry out complex numbers in C++. Your execution ought to endeavor to make complex numbers look as though they were incorporated into the language by permitting new comple...
[6:26 PM, 7/13/2022] Mumbi Gichobi: The quickest way to define a complex number in Python is by typing its literal directly in the source code:
>>>
>>> z = 3 + 2j
Although this looks like an algebraic formula, the expression to the right of the equals sign is already a fixed value that needs no further evaluation. When you check its type, you'll confirm that it's indeed a complex number:
>>>
>>> type(z)
How is that different from adding two numbers with the plus operator? A clear giveaway is the letter j glued to the second number, which completely changes the meaning of the expression. If you removed the letter, you'd get a familiar integer result instead:
>>>
>>> z = 3 + 2
>>> type(z)
By the way, you can use floating-point numbers to create complex numbers, too:
>>>
>>> z = 3.14 + 2.71j
>>> type(z)
Complex number literals in Python mimic the mathematical notation, which is also known as the standard form, the algebraic form, or sometimes the canonical form, of a complex number. In Python, you can use either lowercase j or uppercase J in those literals.
If you learned about complex numbers in math class, you might have seen them expressed using an i instead of a j. If you're curious about why Python uses j instead of i, then you can expand the collapsible section below to learn more.
Why j Instead of i?Show/Hide
The algebraic form of a complex number follows the standard rules of algebra, which is convenient in performing arithmetic. For example, addition has a commutative property, which lets you swap the order of the two parts of a complex number literal without changing its value:
>>>
>>> 3 + 2j == 2j + 3
True
Similarly, you can substitute addition for subtraction in a complex number literal because the minus sign is just a shorthand notation for an equivalent form:
>>>
>>> 3 - 2j == 3 + (-2j)
True
Does a complex number literal in Python always have to comprise two numbers? Can it have more? Are they ordered? To answer these questions, let's run some experiments. Unsurprisingly, if you specify only one number, without the letter j, then you'll end up with a regular integer or a floating-point number:
>>>
>>> z = 3.14
>>> type(z)
On the other hand, appending the letter j to a numeric literal will immediately turn it into a complex number:
>>>
>>> z = 3.14j
>>> type(z)
Strictly speaking, from a mathematical standpoint, you've just created a pure imaginary number, but Python can't represent it as a stand-alone data type. Therefore, without the other part, it's just a complex number .
How about the opposite? To create a complex number without the imaginary part, you can take advantage of zero and add or subtract it like so:
>>>
>>> z = 3.14 + 0j
>>> type(z)
In fact, both parts of the complex number are always there. When you don't see one, it means that it has a value of zero. Let's check what happens when you try stuffing more terms into the sum than before:
>>>
>>> 2 + 3j + 4 + 5j
(6+8j)
This time, your expression is no longer a literal because Python evaluated it into a complex number comprising only two parts. Remember that the basic rules of algebra carry over to complex numbers, so if you group similar terms and apply component-wise addition, then you'll end up with 6 + 8j.
Notice how Python displays complex numbers by default. Their textual representation contains an enclosing pair of parentheses, a lowercase letter j, and no whitespace. Additionally, the imaginary part comes second.
Complex numbers that also happen to be pure imaginary numbers show up without parentheses and only reveal their imaginary part:
>>>
>>> 3 + 0j
(3+0j)
>>> 0 + 3j
3j
This helps differentiate imaginary numbers from most complex numbers made up of real and imaginary parts.
Remove ads
complex() Factory Function
Python has a built-in function, complex(), that you can use as an alternative to the complex number literal:
>>>
>>> z = complex(3, 2)
The smoothing incurred with bilinear interpolation may be avoided with cubic (second-order) interpolation, at the expense of more computation. The cubic interpolating function is a piecewise cubic polynomial that approximates the theoretically ideal interpolation function for imagery, the sinc function (Pratt, 1991).3 The sinc function is not used for image interpolation because a large pixel neighborhood is required for accurate results. The cubic interpolator yields results approximating those from a sinc function and requires only a 4-by-4 neighborhood in the input image. The cubic resampling function is actually a parametric cubic convolution (PCC) family of functions, defined by a single parameter α,
(7.15)
where Δ is the local offset in either x or y, as appropriate (Park and Schowengerdt, 1983).
A drawback of cubic resampling is that it produces DN overshoot on either side of sharp edges. The magnitude of the overshoot is directly proportional to the magnitude of α. Although this characteristic contributes to the visual sharpness of the processed image, it is undesirable for further numerical analyses where radiometric accuracy is of prime importance. It has been shown (Keys, 1981; Park and Schowengerdt, 1983) that -0.5 is an optimal value for α (rather than the -1 commonly used), and the value of -0.5 was implemented early in the production of TM data (Fischel, 1984). The two interpolation functions are compared to the sinc function in Fig. 7-14. The effect of the nearest-neighbor, linear, and PCC resampling functions on Landsat TM imagery can be seen in Fig. 7-17. PCC generally does not yield a pronounced visual improvement over bilinear interpolation and requires more computation time. For applications in which the image sharpness is not critical, nearest-neighbor resampling may produce a satisfactory product with a large savings in computer processing time compared to the other interpolation functions.
>>>
>>> complex(3, 2) == 3 + 2j
True
Both parameters are optional, with default values of zero, which makes it less clunky to define complex numbers without the imaginary part or both the real and imaginary parts:
>>>
>>> complex(3) == 3 + 0j
True
>>> complex() == 0 + 0j
True
The single-argument version can be useful in type casting. For example, you can pass a nonnumeric value like a string literal to obtain a corresponding complex object. Note that the string can't contain any whitespace, though:
>>>
>>> complex("3+2j")
(3+2j)
>>> complex("3 + 2j")
Traceback (most recent call last):
File "
ValueError: complex() arg is a malformed string
Later, you'll find out how to make your classes compatible with this type casting mechanism. Interestingly, when you pass a complex number to complex(), you'll get the same instance back:
>>>
>>> z = complex(3, 2)
>>> z is complex(z)
True
That's consistent with how other types of numbers in Python work because they're all immutable. To make a distinct copy of a complex number, you must call the function with both arguments again or declare another variable with the complex number literal:
>>>
>>> z = complex(3, 2)
>>> z is complex(3, 2)
False
When you provide two arguments to the function, they must always be numbers, such as int, float, or complex. Otherwise, you'll get a runtime error. Technically speaking, bool is a subclass of int, so it'll work too:
>>>
>>> complex(False, True) # Booleans, same as complex(0, 1)
1j
>>> complex(3, 2) # Integers
(3+2j)
>>> complex(3.14, 2.71) # Floating-point numbers
(3.14+2.71j)
>>> complex("3", "2") # Strings
Traceback (most recent call last):
File "
TypeError: complex() can't take second arg if first is a string
Things get seemingly more bizarre when you supply the complex() factory function with complex numbers as arguments. If you provide only the first argument, though, it'll behave like a proxy as before:
>>>
>>> complex(complex(3, 2))
(3+2j)
However, when two arguments are present and at least one of them is a complex number, you'll get results that may be difficult to explain at first sight:
>>>
>>> complex(1, complex(3, 2))
(-1+3j)
>>> complex(complex(3, 2), 1)
(3+3j)
>>> complex(complex(3, 2), complex(3, 2))
(1+5j)
To get the answers, let's take a peek at the factory function's docstring or the online documentation, which explain what's going on under the hood when you call complex(real, imag):
Return a complex number with the value real + imag*1j or convert a string or number to a complex number. (Source)
In this explanation, real and imag are names of the function arguments. The second argument gets multiplied by the imaginary unit j, and the result is added to the first argument. Don't worry if it still doesn't make any sense. You can come back to this part when you've read about complex numbers arithmetic. The rules that you'll learn about will make this straightforward.
When would you want to use the complex() factory function over the literal? It depends, but calling the function may be more convenient when you're dealing with dynamically generated data, for example.
Explanation
Getting to Know Python Complex Numbers
In mathematics, complex numbers are a superset of real numbers, which means that every real number is also a complex number whose imaginary part is equal to zero. Python models this relationship through a concept called the numeric tower, described in PEP 3141:
>>>
>>> import numbers
>>> issubclass(numbers.Real, numbers.Complex)
True
The built-in numbers module defines a hierarchy of numeric types through abstract classes that can be used for type checking and classifying numbers. For example, to determine if a value belongs to a specific set of numbers, you can call isinstance() on it:
>>>
>>> isinstance(3.14, numbers.Complex)
True
>>> isinstance(3.14, numbers.Integral)
False
The floating-point value 3.14 is a real number that also happens to be a complex number but not an integral one. Note that you can't use built-in types directly in such a test:
>>>
>>> isinstance(3.14, complex)
False
The difference between complex and numbers.Complex is that they belong to separate branches in the numeric type hierarchy tree, and the latter is an abstract base class without any implementation:
Type hierarchy for numbers in Python
Abstract base classes, which are denoted in red on the diagram above, can bypass the regular inheritance check mechanism by registering unrelated classes as their virtual subclasses. That's why a floating-point value in the example appears to be an instance of numbers.Complex but not complex.
Accessing Real and Imaginary Parts
To get the real and imaginary parts of a complex number in Python, you can reach for the corresponding .real and .imag attributes:
>>>
>>> z = 3 + 2j
>>> z.real
3.0
>>> z.imag
2.0
Both properties are read-only because complex numbers are immutable, so trying to assign a new value to either of them will fail:
>>>
>>> z.real = 3.14
Traceback (most recent call last):
File "
AttributeError: readonly attribute
Since every number in Python is a more specific type of a complex number, attributes and methods defined in numbers.Complex are also available in all numeric types, including int and float:
>>>
>>> x = 42
>>> x.real
42
>>> x.imag
0Given the global coordinates of a marker, develop a search routine for identifying the position of the marker in an unstructured grid consisting of triangular cells. The routine should first discover which cell contains the marker. Current processors exploit guidance level parallelism to further develop throughput. (a) Control-stream processors use pipelining to further develop throughput. What limits throughput in the basic 5-stage pipeline portrayed underneath? [10 marks] guidance interpret/execute memory register get register get access compose back (b) What is the guideline of activity of a static information stream processor and how can it determine information conditions? [10 marks] 3 Digital Communication I What is implied by the term stream control? [3 marks] What is implied by the term credit-based stream control? [4 marks] What is implied by start-stop (or XON-XOFF) stream control? [4 marks] A beginning stop framework is utilized on a 10 kbps interface with a steady postponement of 5 ms. How much support should a beneficiary save for possible later use for "halting time" to forestall data misfortune? [3 marks] Which framework is more proper to use across the Internet and why? [6 marks] 4 Computer Graphics and Image Processing Explain how a cathode beam tube (CRT) works, including subtleties of how tone is accomplished. [8 marks] Describe a run-length encoding plan for encoding pictures whose pixels have eight-cycle power values. [8 marks] Calculate the most ideal pressure proportion attainable with your plan and depict the situation(s) in which this proportion would be accomplished. [2 marks] Calculate the absolute worst pressure proportion feasible with your plan and portray the situation(s) in which this proportion would be accomplished. [2 marks] 2 CST.2000.12.3 5 Business Studies What are the distinctions among benefit and misfortune and income proclamations?
What is meant by a functional dependency between sets of attributes in a relational
database schema? What conditions must be satisfied for a relation to be in Boyce-
Codd Normal Form (BCNF)? [4 marks]
The Department of Transport is implementing plans to tax traffic congestion. From
2002, cars will carry approved radio-control units which at first will be used only
to monitor vehicle movement. In controlled areas sensors identify all vehicles,
recording their positions periodically. Amber signs flash when overall traffic flow
drops below some threshold, and vehicles within the controlled area may be fined
for lack of progress.
The owner of each vehicle has an account with the Department of Transport; owners
can transfer funds to ensure that their account is in credit. Once credit is exhausted
the level of fine increases by a factor 3, and a summons is sent by mail to the vehicle
owner's registered address. In order to maintain proper accounts it is essential to
keep an accurate record of each monitored offence.
You are employed to design the relational database that will enforce the scheme,
including provision for vehicle and driver registration, monitoring of vehicle offences
and management of vehicle accounts. Describe the schema you propose, stating
clearly any assumptions that you make. You need not discuss the calculation of the
fines due. [12 marks]
Outline the flow of information through the database. T[5 marks] What are the distinctions among obligation and value finance? [5 marks] What is a choice and how should it be esteemed? [5 marks] Comment on the ongoing costs of innovative stocks. [5 marks] 6 Comparative Programming Languages Outline how you would carry out complex numbers in C++. Your execution ought to endeavor to make complex numbers look as though they were incorporated into the language by permitting new comple...
[6:26 PM, 7/13/2022] Mumbi Gichobi: The quickest way to define a complex number in Python is by typing its literal directly in the source code:
>>>
>>> z = 3 + 2j
Although this looks like an algebraic formula, the expression to the right of the equals sign is already a fixed value that needs no further evaluation. When you check its type, you'll confirm that it's indeed a complex number:
>>>
>>> type(z)
How is that different from adding two numbers with the plus operator? A clear giveaway is the letter j glued to the second number, which completely changes the meaning of the expression. If you removed the letter, you'd get a familiar integer result instead:
>>>
>>> z = 3 + 2
>>> type(z)
By the way, you can use floating-point numbers to create complex numbers, too:
>>>
>>> z = 3.14 + 2.71j
>>> type(z)
Complex number literals in Python mimic the mathematical notation, which is also known as the standard form, the algebraic form, or sometimes the canonical form, of a complex number. In Python, you can use either lowercase j or uppercase J in those literals.
If you learned about complex numbers in math class, you might have seen them expressed using an i instead of a j. If you're curious about why Python uses j instead of i, then you can expand the collapsible section below to learn more.
Why j Instead of i?Show/Hide
The algebraic form of a complex number follows the standard rules of algebra, which is convenient in performing arithmetic. For example, addition has a commutative property, which lets you swap the order of the two parts of a complex number literal without changing its value:
>>>
>>> 3 + 2j == 2j + 3
True
Similarly, you can substitute addition for subtraction in a complex number literal because the minus sign is just a shorthand notation for an equivalent form:
>>>
>>> 3 - 2j == 3 + (-2j)
True
Does a complex number literal in Python always have to comprise two numbers? Can it have more? Are they ordered? To answer these questions, let's run some experiments. Unsurprisingly, if you specify only one number, without the letter j, then you'll end up with a regular integer or a floating-point number:
>>>
>>> z = 3.14
>>> type(z)
On the other hand, appending the letter j to a numeric literal will immediately turn it into a complex number:
>>>
>>> z = 3.14j
>>> type(z)
Strictly speaking, from a mathematical standpoint, you've just created a pure imaginary number, but Python can't represent it as a stand-alone data type. Therefore, without the other part, it's just a complex number .
How about the opposite? To create a complex number without the imaginary part, you can take advantage of zero and add or subtract it like so:
>>>
>>> z = 3.14 + 0j
>>> type(z)
In fact, both parts of the complex number are always there. When you don't see one, it means that it has a value of zero. Let's check what happens when you try stuffing more terms into the sum than before:
>>>
>>> 2 + 3j + 4 + 5j
(6+8j)
This time, your expression is no longer a literal because Python evaluated it into a complex number comprising only two parts. Remember that the basic rules of algebra carry over to complex numbers, so if you group similar terms and apply component-wise addition, then you'll end up with 6 + 8j.
Notice how Python displays complex numbers by default. Their textual representation contains an enclosing pair of parentheses, a lowercase letter j, and no whitespace. Additionally, the imaginary part comes second.
Complex numbers that also happen to be pure imaginary numbers show up without parentheses and only reveal their imaginary part:
>>>
>>> 3 + 0j
(3+0j)
>>> 0 + 3j
3j
This helps differentiate imaginary numbers from most complex numbers made up of real and imaginary parts.
Remove ads
complex() Factory Function
Python has a built-in function, complex(), that you can use as an alternative to the complex number literal:
>>>
>>> z = complex(3, 2)
The smoothing incurred with bilinear interpolation may be avoided with cubic (second-order) interpolation, at the expense of more computation. The cubic interpolating function is a piecewise cubic polynomial that approximates the theoretically ideal interpolation function for imagery, the sinc function (Pratt, 1991).3 The sinc function is not used for image interpolation because a large pixel neighborhood is required for accurate results. The cubic interpolator yields results approximating those from a sinc function and requires only a 4-by-4 neighborhood in the input image. The cubic resampling function is actually a parametric cubic convolution (PCC) family of functions, defined by a single parameter α,
(7.15)
where Δ is the local offset in either x or y, as appropriate (Park and Schowengerdt, 1983).
A drawback of cubic resampling is that it produces DN overshoot on either side of sharp edges. The magnitude of the overshoot is directly proportional to the magnitude of α. Although this characteristic contributes to the visual sharpness of the processed image, it is undesirable for further numerical analyses where radiometric accuracy is of prime importance. It has been shown (Keys, 1981; Park and Schowengerdt, 1983) that -0.5 is an optimal value for α (rather than the -1 commonly used), and the value of -0.5 was implemented early in the production of TM data (Fischel, 1984). The two interpolation functions are compared to the sinc function in Fig. 7-14. The effect of the nearest-neighbor, linear, and PCC resampling functions on Landsat TM imagery can be seen in Fig. 7-17. PCC generally does not yield a pronounced visual improvement over bilinear interpolation and requires more computation time. For applications in which the image sharpness is not critical, nearest-neighbor resampling may produce a satisfactory product with a large savings in computer processing time compared to the other interpolation functions.
>>>
>>> complex(3, 2) == 3 + 2j
True
Both parameters are optional, with default values of zero, which makes it less clunky to define complex numbers without the imaginary part or both the real and imaginary parts:
>>>
>>> complex(3) == 3 + 0j
True
>>> complex() == 0 + 0j
True
The single-argument version can be useful in type casting. For example, you can pass a nonnumeric value like a string literal to obtain a corresponding complex object. Note that the string can't contain any whitespace, though:
>>>
>>> complex("3+2j")
(3+2j)
>>> complex("3 + 2j")
Traceback (most recent call last):
File "
ValueError: complex() arg is a malformed string
Later, you'll find out how to make your classes compatible with this type casting mechanism. Interestingly, when you pass a complex number to complex(), you'll get the same instance back:
>>>
>>> z = complex(3, 2)
>>> z is complex(z)
True
That's consistent with how other types of numbers in Python work because they're all immutable. To make a distinct copy of a complex number, you must call the function with both arguments again or declare another variable with the complex number literal:
>>>
>>> z = complex(3, 2)
>>> z is complex(3, 2)
False
When you provide two arguments to the function, they must always be numbers, such as int, float, or complex. Otherwise, you'll get a runtime error. Technically speaking, bool is a subclass of int, so it'll work too:
>>>
>>> complex(False, True) # Booleans, same as complex(0, 1)
1j
>>> complex(3, 2) # Integers
(3+2j)
>>> complex(3.14, 2.71) # Floating-point numbers
(3.14+2.71j)
>>> complex("3", "2") # Strings
Traceback (most recent call last):
File "
TypeError: complex() can't take second arg if first is a string
Things get seemingly more bizarre when you supply the complex() factory function with complex numbers as arguments. If you provide only the first argument, though, it'll behave like a proxy as before:
>>>
>>> complex(complex(3, 2))
(3+2j)
However, when two arguments are present and at least one of them is a complex number, you'll get results that may be difficult to explain at first sight:
>>>
>>> complex(1, complex(3, 2))
(-1+3j)
>>> complex(complex(3, 2), 1)
(3+3j)
>>> complex(complex(3, 2), complex(3, 2))
(1+5j)
To get the answers, let's take a peek at the factory function's docstring or the online documentation, which explain what's going on under the hood when you call complex(real, imag):
Return a complex number with the value real + imag*1j or convert a string or number to a complex number. (Source)
In this explanation, real and imag are names of the function arguments. The second argument gets multiplied by the imaginary unit j, and the result is added to the first argument. Don't worry if it still doesn't make any sense. You can come back to this part when you've read about complex numbers arithmetic. The rules that you'll learn about will make this straightforward.
When would you want to use the complex() factory function over the literal? It depends, but calling the function may be more convenient when you're dealing with dynamically generated data, for example.
Explanation
Getting to Know Python Complex Numbers
In mathematics, complex numbers are a superset of real numbers, which means that every real number is also a complex number whose imaginary part is equal to zero. Python models this relationship through a concept called the numeric tower, described in PEP 3141:
>>>
>>> import numbers
>>> issubclass(numbers.Real, numbers.Complex)
True
The built-in numbers module defines a hierarchy of numeric types through abstract classes that can be used for type checking and classifying numbers. For example, to determine if a value belongs to a specific set of numbers, you can call isinstance() on it:
>>>
>>> isinstance(3.14, numbers.Complex)
True
>>> isinstance(3.14, numbers.Integral)
False
The floating-point value 3.14 is a real number that also happens to be a complex number but not an integral one. Note that you can't use built-in types directly in such a test:
>>>
>>> isinstance(3.14, complex)
False
The difference between complex and numbers.Complex is that they belong to separate branches in the numeric type hierarchy tree, and the latter is an abstract base class without any implementation:
Type hierarchy for numbers in Python
Abstract base classes, which are denoted in red on the diagram above, can bypass the regular inheritance check mechanism by registering unrelated classes as their virtual subclasses. That's why a floating-point value in the example appears to be an instance of numbers.Complex but not complex.
Accessing Real and Imaginary Parts
To get the real and imaginary parts of a complex number in Python, you can reach for the corresponding .real and .imag attributes:
>>>
>>> z = 3 + 2j
>>> z.real
3.0
>>> z.imag
2.0
Both properties are read-only because complex numbers are immutable, so trying to assign a new value to either of them will fail:
>>>
>>> z.real = 3.14
Traceback (most recent call last):
File "
AttributeError: readonly attribute
Since every number in Python is a more specific type of a complex number, attributes and methods defined in numbers.Complex are also available in all numeric types, including int and float:
>>>
>>> x = 42
>>> x.real
42
>>> x.imag
0
The imaginary part of such numbers is always zero.
Calculating the Conjugate of a Complex Number
Python complex numbers have only three public members. Apart from the .real and .imag properties, they expose the .conjugate() method, which flips the sign of the imaginary part:
>>>
>>> z = 3 + 2j
The imaginary part of such numbers is always zero.
Calculating the Conjugate of a Complex Number
Python complex numbers have only three public members. Apart from the .real and .imag properties, they expose the .conjugate() method, which flips the sign of the imaginary part:
>>>
>>> z = 3 + 2j
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Given the wide range of topics covered in your question it seems youre looking for detailed explanations or answers across different areas which encompass image processing computer architecture digita...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started