Podcast
Questions and Answers
Which NumPy function is used to create an array with random values between 0 and 1?
Which NumPy function is used to create an array with random values between 0 and 1?
- np.array()
- np.randint()
- np.arange()
- np.random.rand() (correct)
The np.arange()
function includes the end value in the generated array.
The np.arange()
function includes the end value in the generated array.
False (B)
What attribute of a NumPy array returns its dimensions?
What attribute of a NumPy array returns its dimensions?
shape
To change the dimensions of an NumPy array, you can use the ______
method.
To change the dimensions of an NumPy array, you can use the ______
method.
When using the sum()
function on a NumPy array, what does the axis
parameter control?
When using the sum()
function on a NumPy array, what does the axis
parameter control?
The np.polyld()
function can only be used with NumPy arrays containing integer values.
The np.polyld()
function can only be used with NumPy arrays containing integer values.
What function is used to write a NumPy array to a text file?
What function is used to write a NumPy array to a text file?
To read data from a text file into a NumPy array, use the ______
function.
To read data from a text file into a NumPy array, use the ______
function.
What function should you use to find the number of elements in a NumPy array?
What function should you use to find the number of elements in a NumPy array?
The np.fromfile()
method can save a NumPy array to a file.
The np.fromfile()
method can save a NumPy array to a file.
Given arr = np.arange(1, 10)
, what values will arr
contain?
Given arr = np.arange(1, 10)
, what values will arr
contain?
What is the outcome of running arr = np.array([1, 2, 3, 4]); arr.reshape(2, 2)
?
What is the outcome of running arr = np.array([1, 2, 3, 4]); arr.reshape(2, 2)
?
With arr = np.array([1, 5, 2, 9, 3])
, what NumPy function returns the maximum value present in arr
?
With arr = np.array([1, 5, 2, 9, 3])
, what NumPy function returns the maximum value present in arr
?
By default, NumPy's savetxt()
function saves data in binary format.
By default, NumPy's savetxt()
function saves data in binary format.
In np.random.randint(1, 12, size=(3, 4))
, the array created will contain integers ranging from __ to __.
In np.random.randint(1, 12, size=(3, 4))
, the array created will contain integers ranging from __ to __.
Match the following NumPy functions with their descriptions:
Match the following NumPy functions with their descriptions:
Given arr = np.array([[1, 2, 3], [4, 5, 6]])
, what will arr.sum(axis=0)
return?
Given arr = np.array([[1, 2, 3], [4, 5, 6]])
, what will arr.sum(axis=0)
return?
NumPy's reshape()
method modifies the array in place.
NumPy's reshape()
method modifies the array in place.
If arr = np.array([1, 2, 3, 4, 5])
, how can you extract the elements from index 1 up to (but not including) index 4?
If arr = np.array([1, 2, 3, 4, 5])
, how can you extract the elements from index 1 up to (but not including) index 4?
To represent the polynomial $x^2 - 2x + 3$ using NumPy, you would use np.polyld(np.array([1, -2, 3]))
. The coefficients are listed in order of ______ power.
To represent the polynomial $x^2 - 2x + 3$ using NumPy, you would use np.polyld(np.array([1, -2, 3]))
. The coefficients are listed in order of ______ power.
Flashcards
np.array()
np.array()
Creates a NumPy array with the specified elements.
np.arange(start, stop)
np.arange(start, stop)
Creates a NumPy array with a range of numbers.
np.random.rand(rows, cols)
np.random.rand(rows, cols)
Creates an array with random values between 0 and 1.
np.random.randint(low, high, size)
np.random.randint(low, high, size)
Signup and view all the flashcards
array.size
array.size
Signup and view all the flashcards
array.shape
array.shape
Signup and view all the flashcards
array.reshape(rows, cols)
array.reshape(rows, cols)
Signup and view all the flashcards
array[start_row:end_row, start_col:end_col]
array[start_row:end_row, start_col:end_col]
Signup and view all the flashcards
array.sum()
array.sum()
Signup and view all the flashcards
array.sum(axis=0 or 1)
array.sum(axis=0 or 1)
Signup and view all the flashcards
array.max()
array.max()
Signup and view all the flashcards
np.polyld(array)
np.polyld(array)
Signup and view all the flashcards
np.savetxt()
np.savetxt()
Signup and view all the flashcards
np.loadtxt()
np.loadtxt()
Signup and view all the flashcards
array.tofile()
array.tofile()
Signup and view all the flashcards
array.fromfile()
array.fromfile()
Signup and view all the flashcards
Study Notes
NumPy Library
- NumPy is imported as
np
.
Array Creation
np.array([1,2,3,4])
creates an array with the specified values.np.arange(1,10)
generates a range of numbers from 1 to 9.np.random.rand(3,4)
produces a 3x4 array with random values between 0 and 1.np.random.randint(1,12, size=(3,4))
creates a 3x4 array with random integers from 1 to 11.
Array Properties and Manipulation
arr4.size
returns the total number of elements in the array (e.g., 12).arr4.shape
returns the dimensions of the array as a tuple (e.g., (3,4)).ar4.reshape(4,3)
changes the dimensions of the array to 4x3.np.random.randint(1,25, size=(2,3,4))
creates a 3D array, with order 3D -> 2D -> 1D.np.arange(1,25).reshape(2,3,4)
reshapes a range into a 2x3x4 array.ar5[0,0:2,1:3]
accesses a specific slice of the array.
Array Operations
ar5.sum()
calculates the sum of all elements in the array.ar5.sum(axis=0)
sums the values vertically.ar5.sum(axis=1)
sums the values horizontally.ar5.max()
finds the maximum value in the array.ar5.max(axis = 0)
finds the maximum values along axis 0.ar5.max(axis = 1)
finds the maximum values along axis 1.
Mathematical Functions
ar6 = np.array([1,-2,3])
creates an array of coefficients.f = np.polyld(ar6)
defines a polynomial function using the coefficients inar6
(e.g., x**2 - 2x + 3).
File I/O
np.savetxt()
saves array data to a file, with parameters for path, filename, data, format, and delimiter.np.loadtxt()
loads array data from a file, with parameters for path and filename.ar5.fromfile()
reads data from a file to create an array.ar5.tofile()
writes array data to a file.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.