0
0
NumPydata~10 mins

Working with large files efficiently in NumPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load a large CSV file efficiently using NumPy.

NumPy
import numpy as np
large_data = np.genfromtxt('data.csv', delimiter=[1])
Drag options to blanks, or click blank then click option'
A\t
B;
C|
D,
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong delimiter like semicolon or tab.
Forgetting to specify the delimiter.
2fill in blank
medium

Complete the code to load only the first 1000 rows from a large file using NumPy.

NumPy
import numpy as np
subset_data = np.genfromtxt('data.csv', delimiter=',', max_rows=[1])
Drag options to blanks, or click blank then click option'
A1500
B500
C1000
D2000
Attempts:
3 left
💡 Hint
Common Mistakes
Using max_rows larger than the file size.
Not using max_rows and loading the entire file.
3fill in blank
hard

Fix the error in the code to load a large binary file efficiently with NumPy.

NumPy
import numpy as np
large_array = np.fromfile('data.bin', dtype=[1])
Drag options to blanks, or click blank then click option'
Afloat64
Bint
Cstring
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using Python types like 'int' or 'list' instead of NumPy dtypes.
Using 'string' which is not valid for binary numeric data.
4fill in blank
hard

Fill both blanks to create a memory-mapped array for efficient large file access.

NumPy
import numpy as np
memmap_array = np.memmap('large_data.dat', dtype=[1], mode=[2])
Drag options to blanks, or click blank then click option'
A'float32'
B'r+'
C'int64'
D'w+'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mode='w+' which overwrites the file.
Using an incorrect dtype that doesn't match the file data.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

NumPy
words = ['data', 'science', 'ai', 'ml']
lengths = { [1] : [2] for [3] in words if len([3]) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Dw
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not filtering words by length.