You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto-generated via `{sandpaper}`
Source : 6f16d3b
Branch : main
Author : scottan <33283688+Scottan@users.noreply.github.com>
Time : 2026-04-21 15:38:35 +0000
Message : Merge pull request #87 from UoMResearchIT/18-make-long-calculation-easier-to-read
18 make long calculation easier to read
Copy file name to clipboardExpand all lines: 03-numpy_essential.md
+14-11Lines changed: 14 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -170,32 +170,35 @@ Masked arrays associate a NumPy array with another array composed only of boolea
170
170
171
171
To demonstrate this we are going to create a Gaussian function and use it to generate an example dataset and generate a plot. We will then add some noise to it and use a masked array to filter out the noisy data. This represents the kind of processing that can be used for datasets such as a seismographs, where we would wish to isolate single events from noisy background data.
172
172
173
-
Reminder: the Gaussian function is defined by:
173
+
*Reminder*: the Gaussian function is defined by:
174
174
{alt='Gaussian function equation.'}
175
175
176
+
where **x** is an array, **µ** is the position of the centre of the curve/peak and **σ** is the width of the bell.
177
+
178
+
176
179
::::::::::::::::::::::::::::::::::::::: challenge
177
180
178
181
## Gaussian Function
179
182
180
183
1. Create a function called `gauss` which will take three arguments (inputs):
181
184
**x**, **µ**, and **σ**,
182
-
as defined above. (x is an array, µ is the position of the centre of the
183
-
curve/peak and σ is the width of the bell)
184
-
2. Create a NumPy array using the 'numpy' function 'linspace' which will contain 1000
185
-
points equally spaced between x=-100 and x=100. Hint: You can print the help
186
-
documentation of a function with 'help(name\_of\_the\_function)'
187
-
3. Using the above gauss function and the array, create a list which contains the value
188
-
of the gauss from x=-100 to x=100.
189
-
4. Use the 'matplotlib' library to plot the curve with mu=0 and sigma=10.
185
+
as defined above. *Hint*: you may wish to use the NumPy constant `pi`, and NumPy functions `square`, `sqrt` and `exp` for calcuating the square, square-root and exponential of **e** respectively for all elements in an array.
186
+
2. Create a NumPy array using the Numpy function `linspace` which will contain 1000
187
+
points equally spaced between **x**=-100 and **x**=100. *Hint*: You can print the help
188
+
documentation of a function with 'help(name\_of\_the\_function)'.
189
+
3. Using the above gauss function and the array, create an array which contains the values
190
+
of the Gaussian from **x**=-100 to **x**=100.
191
+
4. Use the 'matplotlib' library to plot the curve with **µ**=0 and **σ**=10.
0 commit comments