Python Generators and Random Number Generation Quiz
48 Questions
10 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Match the following functions with their corresponding descriptions:

bernoulli = Draws binary random numbers (0 or 1) from a Bernoulli distribution normal = Returns a tensor of random numbers drawn from separate normal distributions whose mean and standard deviation are given randint = Returns a tensor filled with random integers generated uniformly between low (inclusive) and high (exclusive) poisson = Returns a tensor of the same size as input with each element sampled from a Poisson distribution with rate parameter given by the corresponding element in input

Match the following functions with their corresponding descriptions:

manual_seed = Sets the seed for generating random numbers get_rng_state = Returns the random number generator state as a torch.ByteTensor set_rng_state = Sets the random number generator state torch.default_generator = Returns the default CPU torch.Generator

Match the following functions with their corresponding descriptions:

rand = Returns a tensor filled with random numbers from a uniform distribution on the interval $[ 0 , 1 )$ rand_like = Returns a tensor with the same size as input that is filled with random numbers from a uniform distribution on the interval $[ 0 , 1 )$ multinomial = Returns a tensor where each row contains num_samples indices sampled from the multinomial probability distribution located in the corresponding row of tensor input randint_like = Returns a tensor with the same shape as Tensor input filled with random integers generated uniformly between low (inclusive) and high (exclusive)

Match the following in-place random sampling functions with their respective distributions:

<p>torch.Tensor.bernoulli_() = Bernoulli distribution torch.Tensor.cauchy_() = Cauchy distribution torch.Tensor.exponential_() = Exponential distribution torch.Tensor.geometric_() = Geometric distribution</p> Signup and view all the answers

Match the following functions with their descriptions:

<p>torch.quasirandom.SobolEngine = An engine for generating (scrambled) Sobol sequences torch.save() = Saves an object to a disk file get_num_threads = Returns the number of threads used for parallelizing CPU operations set_num_threads = Sets the number of threads used for intraop parallelism on CPU</p> Signup and view all the answers

Match the following functions with their descriptions:

<p>get_num_interop_threads = Returns the number of threads used for inter-op parallelism on CPU set_num_interop_threads = Sets the number of threads used for interop parallelism torch.Tensor.log_normal_() = Samples from the log-normal distribution torch.Tensor.uniform_() = Numbers sampled from the continuous uniform distribution</p> Signup and view all the answers

Match the following PyTorch context managers with their descriptions:

<p>torch.no_grad() = Context-manager that disables gradient calculation torch.enable_grad() = Context-manager that enables gradient calculation torch.set_grad_enabled() = Context-manager that sets gradient calculation on or off torch.is_grad_enabled() = Returns True if grad mode is currently enabled</p> Signup and view all the answers

Match the following PyTorch commands with their effects on gradient calculation:

<p>x = torch.zeros(1, requires_grad=True) = Creates a tensor with gradient computation enabled with torch.no_grad(): y = x * 2 = Performs a computation with gradient calculation disabled with torch.set_grad_enabled(is_train): y = x * 2 = Performs a computation with gradient calculation set according to the is_train variable torch.set_grad_enabled(False) = Globally disables gradient computation</p> Signup and view all the answers

Match the following PyTorch commands with their results:

<p>y = x * 2; y.requires_grad = Returns True if x requires gradient and gradient computation is enabled with torch.no_grad(): y = x * 2; y.requires_grad = Returns False, as gradient computation is disabled within the block with torch.set_grad_enabled(is_train): y = x * 2; y.requires_grad = Returns the value of is_train, as gradient computation is set according to the is_train variable within the block torch.set_grad_enabled(False); y = x * 2; y.requires_grad = Returns False, as gradient computation is globally disabled</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>torch.abs() = Computes the absolute value of each element in input. torch.acos() = Computes the inverse cosine of each element in input. torch.add() = Adds other, scaled by alpha, to input. torch.angle() = Computes the element-wise angle (in radians) of the given input tensor.</p> Signup and view all the answers

Match the following PyTorch functions with their operations:

<p>torch.asin() = Returns a new tensor with the arcsine of the elements of input. torch.atan() = Returns a new tensor with the arctangent of the elements of input. torch.addcdiv() = Performs the element-wise division of tensor1 by tensor2, multiplies the result by the scalar value and adds it to input. torch.addcmul() = Performs the element-wise multiplication of tensor1 by tensor2, multiplies the result by the scalar value and adds it to input.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>torch.atan2() = Element-wise arctangent of input $\frac{input_i}{other_i}$ with consideration of the quadrant. torch.asinh() = Returns a new tensor with the inverse hyperbolic sine of the elements of input. torch.acosh() = Returns a new tensor with the inverse hyperbolic cosine of the elements of input. torch.atanh() = Returns a new tensor with the inverse hyperbolic tangent of the elements of input.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>bitwise_not = Computes the bitwise NOT of the given input tensor bitwise_and = Computes the bitwise AND of input and other bitwise_or = Computes the bitwise OR of input and other bitwise_xor = Computes the bitwise XOR of input and other</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>bitwise_left_shift = Computes the left arithmetic shift of input by other bits bitwise_right_shift = Computes the right arithmetic shift of input by other bits ceil = Returns a new tensor with the ceil of the elements of input, the smallest integer greater than or equal to each element clamp = Clamps all elements in input into the range [ min, max ]</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>clip = Alias for torch.clamp() conj_physical = Computes the element-wise conjugate of the given input tensor copysign = Create a new floating-point tensor with the magnitude of input and the sign of other, elementwise cos = Returns a new tensor with the cosine of the elements of input</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>cosh = Returns a new tensor with the hyperbolic cosine of the elements of input deg2rad = Returns a new tensor with each of the elements of input converted from angles in degrees to radians div = Divides each element of the input input by the corresponding element of other divide = Alias for torch.div()</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>digamma = Alias for torch.special.digamma() erf = Alias for torch.special.erf() erfc = Alias for torch.special.erfc() erfinv = Alias for torch.special.erfinv()</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>exp = Returns a new tensor with the exponential of the elements of the input tensor input exp2 = Alias for torch.special.exp2() expm1 = Alias for torch.special.expm1() fake_quantize_per_channel_affine = Returns a new tensor with the data in input fake quantized per channel using scale, zero_point, quant_min and quant_max, across the channel specified by axis</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>fake_quantize_per_tensor_affine = Returns a new tensor with the data in input fake quantized using scale, zero_point, quant_min and quant_max. float_power = Raises input to the power of exponent, elementwise, in double precision. gradient = Estimates the gradient of a function in one or more dimensions using the second-order accurate central differences method. ldexp = Multiplies input by $2^{\text{other}}$.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>lgamma = Computes the natural logarithm of the absolute value of the gamma function on input. log1p = Returns a new tensor with the natural logarithm of $(1 + \text{input})$. logaddexp2 = Logarithm of the sum of exponentiations of the inputs in base-2. logical_not = Computes the element-wise logical NOT of the given input tensor.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>hypot = Given the legs of a right triangle, return its hypotenuse. mul = Multiplies input by other. nan_to_num = Replaces NaN, positive infinity, and negative infinity values in input with the values specified by nan, posinf, and neginf, respectively. negative = Returns a new tensor with the negative of the elements of input.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>pow = Takes the power of each element in input with exponent and returns a tensor with the result. quantized_max_pool1d = Applies a 1D max pooling over an input quantized tensor composed of several input planes. reciprocal = Returns a new tensor with the reciprocal of the elements of input remainder = Computes Python's modulus operation entrywise.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>rsqrt = Returns a new tensor with the reciprocal of the square-root of each of the elements of input. sign = Returns a new tensor with the signs of the elements of input. sin = Returns a new tensor with the sine of the elements of input. sqrt = Returns a new tensor with the square-root of the elements of input.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>sub = Subtracts other, scaled by alpha, from input. tan = Returns a new tensor with the tangent of the elements of input. tanh = Returns a new tensor with the hyperbolic tangent of the elements of input. true_divide = Alias for torch.div() with rounding_mode=None.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>lerp = Does a linear interpolation of two tensors start (given by input) and end based on a scalar or tensor weight and returns the resulting out tensor. log = Returns a new tensor with the natural logarithm of the elements of input. log10 = Returns a new tensor with the logarithm to the base 10 of the elements of input. log2 = Returns a new tensor with the logarithm to the base 2 of the elements of input.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>logit = Alias for torch.special.logit(). i0 = Alias for torch.special.i0(). igamma = Alias for torch.special.gammainc(). igammac = Alias for torch.special.gammaincc().</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>mvlgamma = Alias for torch.special.multigammaln(). nextafter = Return the next floating-point value after input towards other, elementwise. polygamma = Alias for torch.special.polygamma(). positive = Returns input.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>quantized_batch_norm = Applies batch normalization on a 4D (NCHW) quantized tensor. quantized_max_pool2d = Applies a 2D max pooling over an input quantized tensor composed of several input planes. rad2deg = Returns a new tensor with each of the elements of input converted from angles in radians to degrees. real = Returns a new tensor containing real values of the self tensor.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>fake_quantize_per_tensor_affine = Returns a new tensor with the data in input fake quantized using scale, zero_point, quant_min, and quant_max. float_power = Raises input to the power of exponent, elementwise, in double precision. ldexp = Multiplies input by $2^{other}$. logical_xor = Computes the element-wise logical XOR of the given input tensors.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>log = Returns a new tensor with the natural logarithm of the elements of input. mul = Multiplies input by other. nan_to_num = Replaces NaN, positive infinity, and negative infinity values in input with the values specified by nan, posinf, and neginf, respectively. reciprocal = Returns a new tensor with the reciprocal of the elements of input.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>real = Returns a new tensor containing real values of the self tensor. quantized_max_pool2d = Applies a 2D max pooling over an input quantized tensor composed of several input planes. rsqrt = Returns a new tensor with the reciprocal of the square-root of each of the elements of input. sign = Returns a new tensor with the signs of the elements of input.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>sin = Returns a new tensor with the sine of the elements of input. sqrt = Returns a new tensor with the square-root of the elements of input. sub = Subtracts other, scaled by alpha, from input. tanh = Returns a new tensor with the hyperbolic tangent of the elements of input.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>logit = Alias for torch.special.logit(). lgamma = Computes the natural logarithm of the absolute value of the gamma function on input. quantized_batch_norm = Applies batch normalization on a 4D (NCHW) quantized tensor. floor_divide = Applies C++'s std::fmod entrywise.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>lerp = Does a linear interpolation of two tensors start (given by input) and end based on a scalar or tensor weight and returns the resulting out tensor. logaddexp2 = Logarithm of the sum of exponentiations of the inputs in base-2. sigmoid = Alias for torch.special.expit(). hypot = Given the legs of a right triangle, return its hypotenuse.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>log1p = Returns a new tensor with the natural logarithm of (1 + input). log10 = Returns a new tensor with the logarithm to the base 10 of the elements of input. log2 = Returns a new tensor with the logarithm to the base 2 of the elements of input. logaddexp = Logarithm of the sum of exponentiations of the inputs.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>gradient = Estimates the gradient of a function $g : R^n \rightarrow R$ in one or more dimensions using the second-order accurate central differences method. imag = Returns a new tensor containing imaginary values of the self tensor. frac = Computes the fractional portion of each element in input. frexp = Decomposes input into mantissa and exponent tensors such that $input = mantissa \times 2^{exponent}$.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>floor = Returns a new tensor with the floor of the elements of input, the largest integer less than or equal to each element. fmod = Applies C++'s std::fmod entrywise. rad2deg = Returns a new tensor with each of the elements of input converted from angles in radians to degrees. square = Returns a new tensor with the square of the elements of input.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>nextafter = Return the next floating-point value after input towards other, elementwise. signbit = Tests if each element of input has its sign bit set or not. tan = Returns a new tensor with the tangent of the elements of input. true_divide = Alias for torch.div() with rounding_mode=None.</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>fake_quantize_per_tensor_affine = Fake quantizes the data in input using scale, zero_point, quant_min and quant_max float_power = Raises input to the power of exponent, elementwise, in double precision log = Returns a new tensor with the natural logarithm of the elements of input mul = Multiplies input by other</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>neg = Returns a new tensor with the negative of the elements of input log10 = Returns a new tensor with the logarithm to the base 10 of the elements of input ldexp = Multiplies input by 2 ** other logit = Alias for torch.special.logit()</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>logical_and = Computes the element-wise logical AND of the given input tensors hypot = Given the legs of a right triangle, return its hypotenuse log2 = Returns a new tensor with the logarithm to the base 2 of the elements of input igamma = Alias for torch.special.gammainc()</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>quantized_max_pool1d = Applies a 1D max pooling over an input quantized tensor composed of several input planes real = Returns a new tensor containing real values of the self tensor sin = Returns a new tensor with the sine of the elements of input tanh = Returns a new tensor with the hyperbolic tangent of the elements of input</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>sqrt = Returns a new tensor with the square-root of the elements of input polygamma = Alias for torch.special.polygamma() floor = Returns a new tensor with the floor of the elements of input, the largest integer less than or equal to each element reciprocal = Returns a new tensor with the reciprocal of the elements of input</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>sigmoid = Alias for torch.special.expit() logaddexp = Logarithm of the sum of exponentiations of the inputs sub = Subtracts other, scaled by alpha, from input round = Rounds elements of input to the nearest integer</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>tan = Returns a new tensor with the tangent of the elements of input imag = Returns a new tensor containing imaginary values of the self tensor logaddexp2 = Logarithm of the sum of exponentiations of the inputs in base-2 gradient = Estimates the gradient of a function in one or more dimensions using the second-order accurate central differences method</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>log1p = Returns a new tensor with the natural logarithm of (1 + input) lerp = Does a linear interpolation of two tensors start (given by input) and end based on a scalar or tensor weight and returns the resulting out tensor lgamma = Computes the natural logarithm of the absolute value of the gamma function on input rsqrt = Returns a new tensor with the reciprocal of the square-root of each of the elements of input</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>nan_to_num = Replaces NaN, positive infinity, and negative infinity values in input with the values specified by nan, posinf, and neginf, respectively signbit = Tests if each element of input has its sign bit set or not quantized_max_pool2d = Applies a 2D max pooling over an input quantized tensor composed of several input planes remainder = Computes Python's modulus operation entrywise</p> Signup and view all the answers

Match the following PyTorch functions with their descriptions:

<p>sign = Returns a new tensor with the signs of the elements of input nextafter = Return the next floating-point value after input towards other, elementwise logical_xor = Computes the element-wise logical XOR of the given input tensors frexp = Decomposes input into mantissa and exponent tensors such that input = mantissa × 2 exponent input=mantissa×2 exponent</p> Signup and view all the answers

Study Notes

Functions and Descriptions Overview

  • In-depth understanding of various functions is crucial for effective implementation in programming.
  • Matching functions with their respective descriptions enhances comprehension and usability in coding.

In-Place Random Sampling Functions

  • In-place random sampling is essential for data manipulation and selection processes.
  • Correct identification of distributions related to random sampling can optimize performance in statistical analyses.

PyTorch Context Managers

  • Context managers in PyTorch streamline resource management, particularly with GPU and CPU utilization.
  • Understanding how each context manager modifies behavior aids in efficient debugging and resource handling.

Effects of PyTorch Commands on Gradient Calculation

  • Different PyTorch commands interact uniquely with gradient calculations, impacting how models learn.
  • Knowledge of these commands is vital for optimizing model training and ensuring correctness in backpropagation.

Results of PyTorch Commands

  • Exploring the outputs of various commands provides insight into their functionality.
  • Analyzing results fosters a better grasp of implementing these commands effectively.

Description of PyTorch Functions

  • Familiarity with various PyTorch functions enables quick problem-solving and model creation.
  • Distinguishing the purpose of each function can aid in informed decision-making during development.

Operations of PyTorch Functions

  • Understanding operation types (e.g., tensor operations, mathematical functions) is key to efficient coding in PyTorch.
  • Knowing which functions perform specific operations helps streamline the development process.

Repeated Exposure to PyTorch Functions

  • Regular practice with matching functions and descriptions strengthens memory retention and understanding.
  • Being well-versed in various PyTorch functions can enhance performance in machine learning tasks.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

Test your knowledge on generators and random number generation in Python with this quiz. Learn about creating generator objects, setting random number seeds, and more.

More Like This

Use Quizgecko on...
Browser
Browser