Recall & Review
beginner
What is the default string type in NumPy arrays?
The default string type in NumPy arrays is fixed-length ASCII strings, represented as
S followed by the length, for example S10 means a string of length 10.Click to reveal answer
beginner
How do you create a NumPy array of Unicode strings?
You create a NumPy array of Unicode strings by specifying the data type as
U followed by the maximum length, for example U5 for Unicode strings up to length 5.Click to reveal answer
intermediate
What happens if you assign a longer string to a NumPy string array with fixed length?
If you assign a string longer than the fixed length, NumPy will truncate the string to fit the defined length, potentially losing data.
Click to reveal answer
intermediate
How can you convert a NumPy array of bytes strings to Unicode strings?
You can convert by using the
astype method with a Unicode dtype, for example arr.astype('U') converts byte strings to Unicode strings.Click to reveal answer
beginner
Why might you prefer Unicode strings (
U) over byte strings (S) in NumPy?Unicode strings support a wide range of characters from many languages, while byte strings only support ASCII or raw bytes. Use Unicode for international text.
Click to reveal answer
What does the dtype
S8 mean in a NumPy array?✗ Incorrect
S8 means a fixed-length ASCII string of length 8 characters.
How do you specify a Unicode string type of length 10 in NumPy?
✗ Incorrect
U10 specifies a Unicode string of length 10 in NumPy.
What happens if you assign a string longer than the dtype length in a NumPy string array?
✗ Incorrect
NumPy truncates the string to the fixed length defined by the dtype.
Which method converts a byte string array to Unicode strings in NumPy?
✗ Incorrect
The astype('U') method converts byte strings to Unicode strings.
Why choose Unicode strings (
U) over byte strings (S) in NumPy?✗ Incorrect
Unicode strings support many languages and characters beyond ASCII.
Explain how NumPy handles string data types and the difference between
S and U types.Think about ASCII vs Unicode and fixed length.
You got /5 concepts.
Describe how to convert a NumPy array of byte strings to Unicode strings and why this might be useful.
Consider encoding and international characters.
You got /4 concepts.