Deck 7: Array-Oriented Programming With Num
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/18
العب
ملء الشاشة (f)
Deck 7: Array-Oriented Programming With Num
1
Which of the following statements a), b) or c) is false?
A) Calculating the mean of an array totals all of its elements regardless of its shape, then divides by the total number of elements.
B) You can perform array calculations on each array dimension as well. For example, in a two-dimensional array, you can calculate each row's mean or each column's mean.
C) The array methods sum, min, max, mean, std (standard deviation) and var (variance) are each functional-style programming reductions.
D) All of the above statements are true.
A) Calculating the mean of an array totals all of its elements regardless of its shape, then divides by the total number of elements.
B) You can perform array calculations on each array dimension as well. For example, in a two-dimensional array, you can calculate each row's mean or each column's mean.
C) The array methods sum, min, max, mean, std (standard deviation) and var (variance) are each functional-style programming reductions.
D) All of the above statements are true.
D
2
Which of the following statements a), b) or c) is false?
A) The xe "NumPy (Numerical Python):array function"xe "array function (NumPy)"array function copies its argument's dimensions and creates a new array.
B) The following creates an array from a two-row-by-three-column list: np.array([[1, 2, 3], [4, 5, 6]])
C) NumPy auto-formats arrays, based on their number of dimensions, aligning the columns within each row.
D) All of the above statements are true.
A) The xe "NumPy (Numerical Python):array function"xe "array function (NumPy)"array function copies its argument's dimensions and creates a new array.
B) The following creates an array from a two-row-by-three-column list: np.array([[1, 2, 3], [4, 5, 6]])
C) NumPy auto-formats arrays, based on their number of dimensions, aligning the columns within each row.
D) All of the above statements are true.
D
3
Which of the following statements is false?
A) The NumPy (Numerical Python) library is the preferred Python array implementation-it offers a high-performance, richly functional n-dimensional array type called ndarray, which you can refer to by its synonym, array.
B) Operations on arrays are up to two orders of magnitude faster than those on lists.
C) Many popular data science libraries such as Pandas, SciPy (Scientific Python) and Keras (for deep learning) are built on or depend on NumPy.
D) A strength of NumPy is "array-oriented programming," which uses functional-style programming with external iteration to make array manipulations concise and straightforward, eliminating the kinds of bugs that can occur with the internal iteration of explicitly programmed loops.
A) The NumPy (Numerical Python) library is the preferred Python array implementation-it offers a high-performance, richly functional n-dimensional array type called ndarray, which you can refer to by its synonym, array.
B) Operations on arrays are up to two orders of magnitude faster than those on lists.
C) Many popular data science libraries such as Pandas, SciPy (Scientific Python) and Keras (for deep learning) are built on or depend on NumPy.
D) A strength of NumPy is "array-oriented programming," which uses functional-style programming with external iteration to make array manipulations concise and straightforward, eliminating the kinds of bugs that can occur with the internal iteration of explicitly programmed loops.
D
4
Assume the array numbers contains the values 10, 20, 30, 40, 50, 60. Which of the following statements is false?
A) The following code uses the xe "NumPy (Numerical Python):multiply universal function"xe "multiply universal function (NumPy)"multiply universal function to multiply every element of numbers by the scalar value 5: import numpy as np
Np)multiply(numbers, 5)
B) The following code uses the xe "NumPy (Numerical Python):multiply universal function"xe "multiply universal function (NumPy)"multiply universal function to multiply every element of numbers by the scalar value 5: numbers * 5
C) The following code reshapes numbers into a 2-by-3 array, then multiplies its values by a one-dimensional array of three elements: numbers2 = numbers.reshape(2, 3)
Numbers3 = np.array([2, 4, 6])
Np)multiply(numbers2, numbers3)
The preceding code works because numbers3 has the same length as each column of numbers2.
D) If a universal function receives two arrays of different shapes that do not support xe "NumPy (Numerical Python):broadcasting"xe "broadcasting (NumPy)"broadcasting, a ValueError occurs.
A) The following code uses the xe "NumPy (Numerical Python):multiply universal function"xe "multiply universal function (NumPy)"multiply universal function to multiply every element of numbers by the scalar value 5: import numpy as np
Np)multiply(numbers, 5)
B) The following code uses the xe "NumPy (Numerical Python):multiply universal function"xe "multiply universal function (NumPy)"multiply universal function to multiply every element of numbers by the scalar value 5: numbers * 5
C) The following code reshapes numbers into a 2-by-3 array, then multiplies its values by a one-dimensional array of three elements: numbers2 = numbers.reshape(2, 3)
Numbers3 = np.array([2, 4, 6])
Np)multiply(numbers2, numbers3)
The preceding code works because numbers3 has the same length as each column of numbers2.
D) If a universal function receives two arrays of different shapes that do not support xe "NumPy (Numerical Python):broadcasting"xe "broadcasting (NumPy)"broadcasting, a ValueError occurs.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck
5
Which of the following statements is true with respect to displaying an array of 1000 items or more?
A) NumPy always drops the middle rows and middle columns from the output.
B) NumPy always drops only the middle rows from the output.
C) NumPy always drops only the middle columns from the output.
D) NumPy drops the middle rows, middle columns or both from the output.
A) NumPy always drops the middle rows and middle columns from the output.
B) NumPy always drops only the middle rows from the output.
C) NumPy always drops only the middle columns from the output.
D) NumPy drops the middle rows, middle columns or both from the output.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck
6
The attribute ________ contains an array's number of dimensions and the attribute ________ contains a ________ specifying an array's dimensions:
A) dim, size, list
B) ndim, shape, tuple
C) dim, size, tuple
D) ndim, shape, list
A) dim, size, list
B) ndim, shape, tuple
C) dim, size, tuple
D) ndim, shape, list
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck
7
Which of the following statements a), b) or c) is false?
A) Element-wise operations are applied to every array element, so given an integer array named numbers, the expression numbers * 2
Multiplies every element by 2, and the expression
Numbers ** 3
Cubes every element.
B) The expressions in Part (a) do not modify the array numbers.
C) Augmented assignments modify every element in the right operand.
D) All of the above statements are true.
A) Element-wise operations are applied to every array element, so given an integer array named numbers, the expression numbers * 2
Multiplies every element by 2, and the expression
Numbers ** 3
Cubes every element.
B) The expressions in Part (a) do not modify the array numbers.
C) Augmented assignments modify every element in the right operand.
D) All of the above statements are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck
8
Which of the following statements a), b) or c) is false?
A) You can create an array from a range of elements, then use array method reshape to transform the one-dimensional array into a multidimensional array.
B) The following code creates an array containing the values from 1 through 20, then reshapes it into four rows by five columns: import numpy as np
Np)arange(1, 21).reshape(4, 5)
C) A 24-element one-dimensional array can be reshaped into a 2-by-12, 8-by-3 or 4-by-8 array, and vice versa.
D) All of the above statements are true.
A) You can create an array from a range of elements, then use array method reshape to transform the one-dimensional array into a multidimensional array.
B) The following code creates an array containing the values from 1 through 20, then reshapes it into four rows by five columns: import numpy as np
Np)arange(1, 21).reshape(4, 5)
C) A 24-element one-dimensional array can be reshaped into a 2-by-12, 8-by-3 or 4-by-8 array, and vice versa.
D) All of the above statements are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck
9
The NumPy array function receives as an argument an array or other collection of elements and returns a new array containing the argument's elements. Based on the statement: import numpy as np
Numbers = np.array([2, 3, 5, 7, 11])
What type will be output by the following statement?
Type(numbers)
A) array
B) ndarray
C) numpy.ndarray
D) numpy
Numbers = np.array([2, 3, 5, 7, 11])
What type will be output by the following statement?
Type(numbers)
A) array
B) ndarray
C) numpy.ndarray
D) numpy
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck
10
Which of the following statements a), b) or c) is false?
A) Most array operations execute significantly faster than corresponding list operations.
B) With the IPython %timeit magic command, you can time the average duration of operations.
C) The times displayed by %timeit on one system may vary from those shown on another.
D) All of the above statements are true.
A) Most array operations execute significantly faster than corresponding list operations.
B) With the IPython %timeit magic command, you can time the average duration of operations.
C) The times displayed by %timeit on one system may vary from those shown on another.
D) All of the above statements are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck
11
Which of the following statements a), b) or c) is false?
A) You'll generally manipulate arrays using xe "functional-style programming"concise functional-style programming techniques with internal iteration.
B) Because arrays are iterable, you cannot use external iteration with them.
C) You can iterate through a multidimensional array as if it were one-dimensional by using its flat attribute.
D) All of the above statements are true.
A) You'll generally manipulate arrays using xe "functional-style programming"concise functional-style programming techniques with internal iteration.
B) Because arrays are iterable, you cannot use external iteration with them.
C) You can iterate through a multidimensional array as if it were one-dimensional by using its flat attribute.
D) All of the above statements are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck
12
Which of the following statements a), b) or c) is false?
A) NumPy provides functions zeros, ones and full for creating arrays containing 0s, 1s or a specified value, respectively.
B) The first argument to the functions in Part (a) must be an integer or a tuple of integers specifying the desired dimensions. For an integer, each function returns a one-dimensional array with the specified number of elements. For a tuple of integers, these functions return a multidimensional array with the specified dimensions.
C) The array returned by NumPy function full contains elements with the second argument's value and type.
D) All of the above statements are true.
A) NumPy provides functions zeros, ones and full for creating arrays containing 0s, 1s or a specified value, respectively.
B) The first argument to the functions in Part (a) must be an integer or a tuple of integers specifying the desired dimensions. For an integer, each function returns a one-dimensional array with the specified number of elements. For a tuple of integers, these functions return a multidimensional array with the specified dimensions.
C) The array returned by NumPy function full contains elements with the second argument's value and type.
D) All of the above statements are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck
13
Which of the following statements is false?
A) Many calculation methods can be performed on specific array dimensions, known as the array's axes. These methods receive an axis keyword argument that specifies which dimension to use in the calculation, giving you a quick way to perform calculations by row or column in a two-dimensional array.
B) Assume that you want to calculate the average grade on each exam, represented by the columns of grades. Specifying axis=0 performs the calculation on all the row values within each column. Similarly, specifying axis=1 performs the calculation on all the column values within each individual row.
C) NumPy does not display trailing 0s to the right of the decimal point. Also, it does not display all element values in the same field width.
D) For a two-dimensional array grades in which each row represents one student's grades on several exams, we can calculate each student's average grade with: grades.mean(axis=1)
A) Many calculation methods can be performed on specific array dimensions, known as the array's axes. These methods receive an axis keyword argument that specifies which dimension to use in the calculation, giving you a quick way to perform calculations by row or column in a two-dimensional array.
B) Assume that you want to calculate the average grade on each exam, represented by the columns of grades. Specifying axis=0 performs the calculation on all the row values within each column. Similarly, specifying axis=1 performs the calculation on all the column values within each individual row.
C) NumPy does not display trailing 0s to the right of the decimal point. Also, it does not display all element values in the same field width.
D) For a two-dimensional array grades in which each row represents one student's grades on several exams, we can calculate each student's average grade with: grades.mean(axis=1)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck
14
Which of the following statements a), b) or c) is false?
A) The following code uses the random module's randrange function with a list comprehension to create a list of six million die rolls and time the operation using %timeit: import random
%timeit rolls_list = \
[random.randrange(1, 7) for i in range(0, 6_000_000)]
B) By default, %timeit executes a statement in a loop, and it runs the loop seven times.
C) After executing the statement, %timeit displays the statement's xe "average time"average execution time, as well as the xe "standard deviation"standard deviation of all the executions.
D) All of the above statements are true.
A) The following code uses the random module's randrange function with a list comprehension to create a list of six million die rolls and time the operation using %timeit: import random
%timeit rolls_list = \
[random.randrange(1, 7) for i in range(0, 6_000_000)]
B) By default, %timeit executes a statement in a loop, and it runs the loop seven times.
C) After executing the statement, %timeit displays the statement's xe "average time"average execution time, as well as the xe "standard deviation"standard deviation of all the executions.
D) All of the above statements are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck
15
Which of the following statements is false?
A) Normally, the arithmetic operations on arrays require as operands two arrays of the same size and shape.
B) When one operand is a single value, called a scalar, NumPy performs the element-wise calculations as if the scalar were an array of the same shape as the other operand, but with that scalar value in all its elements.
C) If numbers is a five-element integer array, numbers * 2 is equivalent to: numbers * [2, 2, 2, 2, 2]
D) Broadcasting can only be applied between arrays of the same size and shape, enabling some concise and powerful manipulations.
A) Normally, the arithmetic operations on arrays require as operands two arrays of the same size and shape.
B) When one operand is a single value, called a scalar, NumPy performs the element-wise calculations as if the scalar were an array of the same shape as the other operand, but with that scalar value in all its elements.
C) If numbers is a five-element integer array, numbers * 2 is equivalent to: numbers * [2, 2, 2, 2, 2]
D) Broadcasting can only be applied between arrays of the same size and shape, enabling some concise and powerful manipulations.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck
16
Which of the following statements about NumPy's linspace function is false?
A) You can produce evenly spaced floating-point ranges with linspace.
B) The function's first two arguments specify the starting and ending values in the range, and the ending value is included in the array.
C) The optional keyword argument num specifies the number of xe "evenly-spaced values"evenly spaced values to produce-this argument's default value is 50.
D) All of the above statements are true.
A) You can produce evenly spaced floating-point ranges with linspace.
B) The function's first two arguments specify the starting and ending values in the range, and the ending value is included in the array.
C) The optional keyword argument num specifies the number of xe "evenly-spaced values"evenly spaced values to produce-this argument's default value is 50.
D) All of the above statements are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck
17
Which of the following statements is false?
A) You may perform arithmetic operations and augmented assignments between arrays of the same shape.
B) Arithmetic between arrays of integers and floating-point numbers results in an array of integers.
C) You can compare arrays with individual values and with other arrays. Comparisons are performed element-wise. Such comparisons produce arrays of Boolean values in which each element's True or False value indicates the comparison result.
D) The expression numbers >= 13 uses broadcasting to determine whether each element of numbers is greater than or equal to 13.
A) You may perform arithmetic operations and augmented assignments between arrays of the same shape.
B) Arithmetic between arrays of integers and floating-point numbers results in an array of integers.
C) You can compare arrays with individual values and with other arrays. Comparisons are performed element-wise. Such comparisons produce arrays of Boolean values in which each element's True or False value indicates the comparison result.
D) The expression numbers >= 13 uses broadcasting to determine whether each element of numbers is greater than or equal to 13.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck
18
Assume the following array definitions: import numpy as np
Integers = np.array([[1, 2, 3], [4, 5, 6]])
Floats = np.array([0.0, 0.1, 0.2, 0.3, 0.4])
Which of the following statements a), b) or c) is false?
A) The xe "NumPy (Numerical Python):array function"xe "array function (NumPy)"array function determines an array's element type from its argument's elements.
B) You can check the element type with an array's dtype attribute.
C) For performance reasons, NumPy is written in the xe "C programming language"Java programming language and uses Java's data types.
D) All of the above statements are true.
Integers = np.array([[1, 2, 3], [4, 5, 6]])
Floats = np.array([0.0, 0.1, 0.2, 0.3, 0.4])
Which of the following statements a), b) or c) is false?
A) The xe "NumPy (Numerical Python):array function"xe "array function (NumPy)"array function determines an array's element type from its argument's elements.
B) You can check the element type with an array's dtype attribute.
C) For performance reasons, NumPy is written in the xe "C programming language"Java programming language and uses Java's data types.
D) All of the above statements are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 18 في هذه المجموعة.
فتح الحزمة
k this deck