From the course: Testing Python Data Science Code
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
NumPy utilities - Python Tutorial
From the course: Testing Python Data Science Code
NumPy utilities
- [Instructor] Let's look at the NumPy Utilities, the type of service provides. State would like to use Benford's laws to detect fraud. Benford laws says that "the distribution of the first digit in real data is not even." in real data is not even." We are going to use several of the utilities from hypothesis.numpy extension to do that. Let's look at the code. First, here's our code. I have one function called first_digit that returns the first digit from a number. Then, we calculate the frequency. We use the first digit with the list comprehension, then use bincount to count how many digits from each kind. Finally, we divide by the len to get the frequency. For our code, we're going to do a bunch of import. We import NumPy in our code. From hypothesis, we are importing given and integers, but we also import arrays from hypothesis.extra.numpy. Now, we define our strategy. We say these are arrays. We say the data type is an…