Exercise 4.2: Computing things!
[1]:
import polars as pl
We have looked at a data set from Harvey and Orbidans on the cross-sectional area of C. elegans eggs. Recall, we loaded the data and converted everything to Numpy arrays like this:
[2]:
df = pl.read_csv('data/c_elegans_egg_xa.csv', comment_prefix='#')
xa_high = df.filter(pl.col('food')=='high')['area (sq. um)'].to_numpy()
xa_low = df.filter(pl.col('food')=='low')['area (sq. um)'].to_numpy()
Now we would like to compute the diameter of the egg from the cross-sectional area. Write a function that takes in an array of cross-sectional areas and returns an array of diameters. Recall that the diameter \(d\) and cross-sectional area \(A\) are related by \(A = \pi d^2/4\). There should be no for
loops in your function! The call signature is
xa_to_diameter(xa)
Use your function to compute the diameters of the eggs.