Notes, assignments, and code for NEUROBIO 735 (Spring 2024).
1/11 – 4/17:
Tuesday, Thursday
3:00 – 4:30
301 Bryan Research Building
splicer(['foo', 'bar', 'baz'], '.')
should return
'foo.bar.baz'
Make the separator default to the underscore, '_'
. Would this work if the separator were the first input? Why or why not?
try...except
.) Note that all the data types we’ve seen so far can be converted to strings. If you want to test this behavior, you might try:class Failer:
def __str__(self):
pass
test_obj = Failer()
to get an object that cannot be converted to a string (h/t this StackOverflow answer).
Create a diagonal matrix whose nonzero entries are the numbers 1 through 10.
Create an array of random numbers, each entry drawn from a Gaussian (normal) distribution of mean 0 and standard deviation 1. The array should be 3 by 4 by 7.
Get the first and third “columns” (second dimension) of this array. What is the shape of the resulting array?
Let’s say that we need to manipulate the dimensions of this array. One way to do this is to flatten
the matrix. In what order are the entries read out? What if we wanted to swap dimensions so that the last index became the first index? (Hint: what is it called when we swap the rows and columns of a matrix? Does NumPy have a function for this? What does it do to higher-order arrays?)
Write a function that finds the value in a NumPy array closest to a given number. The first input should be the array. There are many ways to do this.