Put the lesson Working with Scientific Data into practice by writing a program yourself.
The starter code contains the elastic part of a tensile test as CSV text: strain in the first column and stress in MPa in the second.
In the elastic region, stress = E × strain, so the slope of a straight-line fit is Young's modulus E.
np.loadtxt(), skipping the header.np.polyfit().Data points: 6 Young's modulus: 70.3 GPa
Write your program below and press Run. Each run is checked against the expected output.
Press Run to see what your program prints.
One possible solution. Other programs that print the same output are correct too.
import ioimport numpy as npcsv_text = """strain,stress_mpa0.0000,00.0010,710.0020,1390.0030,2110.0040,2800.0050,352"""data = np.loadtxt(io.StringIO(csv_text), delimiter=",", skiprows=1)strain = data[:, 0]stress = data[:, 1]print("Data points:", len(data))slope, intercept = np.polyfit(strain, stress, 1)print(f"Young's modulus: {slope / 1000:.1f} GPa")