Trusted answers to developer questions

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The **real_if_close()**** function** in NumPy is used to return real parts of an input array of complex values with all imaginary parts close to zero.

np.real_if_close(a, tol=100)

Syntax of real_if_close() function

The `real_if_close()`

function takes the following parameter values:

: This represents the input array. This is a required parameter.**a**

: This represents the tolerance in machine epsilons for the complex part of the input array elements. This is a required parameter.**tol**

Note:Machine epsilonsrepresent the smallest positive float value greater than zero.

The `real_if_close()`

function returns a float if the input array has complex elements. If the input array is real, its data type is the same for the output.

import numpy as np# creating an input arrayx = np.array([10.4 + 10e-14j, 15.5 + 15e-15j])# defining the real_if_close() functionmyarray = np.real_if_close(x, tol=1000)print(myarray)

Using the real_if_close() function

- Line 1: We import the
`numpy`

module. - Line 4: We create an input array,
`x`

, using the`array()`

function. - Line 7: We define the
`real_if_close()`

function on the input array,`x`

. We assign the result to a variable`myarray`

. - Line 9: We print the variable
`myarray`

.

RELATED TAGS

function

numpy

python

communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Related Courses