Sunday, May 10, 2026
banner
Top Selling Multipurpose WP Theme

A collection of small NumPy tasks to check out. construct one thing Use NumPy as a substitute of simply working random features or paperwork. I’ve all the time felt that the easiest way to study is by doing, so for this venture I wished to make one thing sensible and private.

The concept was easy. It is about analyzing my each day habits comparable to sleep, research time, display screen time, train, and temper, and seeing how they have an effect on my productiveness and general happiness. The information is not actual. That is hypothetical and simulated over a 30-day interval. Nonetheless, the objective will not be information accuracy, however studying the right way to use NumPy meaningfully.

So let’s take a step-by-step take a look at the method.

Step 1 — Load and perceive the info

First, I created a easy NumPy array with 30 rows (one for every day) and 6 columns. Every column represents a unique behavior indicator. Then I saved it as .npy Put it aside to a file so you may simply load it later.

# TODO: Import NumPy and cargo the .npy information file
import numpy as np
information = np.load(‘activity_data.npy’)

As soon as loaded, I wished to ensure all the things regarded as anticipated. So I checked form (to know the variety of rows and columns) variety of dimensions (to ensure it is a 2D desk and never a 1D checklist).

# TODO: Print array form, first few rows, and many others.
information.form
information.ndim

Output: 30 rows, 6 columns, ndim=2

I additionally printed out the primary few traces to visually affirm that every worth regarded OK (for instance, the sleep length was not unfavourable, the temper worth was inside an affordable vary, and many others.).

# TODO: Prime 5 rows
information[:5]

output:

array([[ 1. , 6.5, 5. , 4.2, 20. , 6. ],
[ 2. , 7.2, 6. , 3.1, 35. , 7. ],
[ 3. , 5.8, 4. , 5.5, 0. , 5. ],
[ 4. , 8. , 7. , 2.5, 30. , 8. ],
[ 5. , 6. , 5. , 4.8, 10. , 6. ]])

Step 2 – Validate the info

Earlier than doing any evaluation, I wished to ensure the info made sense. That is typically omitted when working with fictitious information, but it surely’s nonetheless good follow.

So I checked the next:

  • No unfavourable sleep time
  • No temper rating lower than 1 or larger than 10

For sleep, meaning choosing the sleep column (index 1 within the array) and checking if there’s a worth lower than zero.

# Be sure values are affordable (no unfavourable sleep)
information[:, 1] < 0

output:

array([False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False])

This implies there aren’t any minuses. Subsequent, we did the identical for temper. I counted and located that the temper column was at index 5, so I checked to see if there was something lower than 1 or greater than 10.

# Is temper out of vary?
information[:, 5] < 1
information[:, 5] > 10

I acquired the identical output.

All the things regarded high-quality so I used to be capable of transfer on.

Step 3 — Cut up the info into weeks

I had 30 days of knowledge and wished to research it weekly. My first intuition was to make use of NumPy cut up() I used the operate, but it surely failed as a result of 30 will not be divisible by 4. So I used the next operate as a substitute: np.array_split()which permits for unequal splits.

It gave me the next:

  • 1st week → 8 days
  • 2nd week → 8 days
  • third week → 7 days
  • 4th week → 7 days
# TODO: Slice information into week 1, week 2, week 3, week 4
weekly_data = np.array_split(information, 4)
weekly_data

output:

[array([[ 1. , 6.5, 5. , 4.2, 20. , 6. ],
[ 2. , 7.2, 6. , 3.1, 35. , 7. ],
[ 3. , 5.8, 4. , 5.5, 0. , 5. ],
[ 4. , 8. , 7. , 2.5, 30. , 8. ],
[ 5. , 6. , 5. , 4.8, 10. , 6. ],
[ 6. , 7.5, 6. , 3.3, 25. , 7. ],
[ 7. , 8.2, 3. , 6.1, 40. , 7. ],
[ 8. , 6.3, 4. , 5. , 15. , 6. ]]),

array([[ 9. , 7. , 6. , 3.2, 30. , 7. ],
[10. , 5.5, 3. , 6.8, 0. , 5. ],
[11. , 7.8, 7. , 2.9, 25. , 8. ],
[12. , 6.1, 5. , 4.5, 15. , 6. ],
[13. , 7.4, 6. , 3.7, 30. , 7. ],
[14. , 8.1, 2. , 6.5, 50. , 7. ],
[15. , 6.6, 5. , 4.1, 20. , 6. ],
[16. , 7.3, 6. , 3.4, 35. , 7. ]]),

array([[17. , 5.9, 4. , 5.6, 5. , 5. ],
[18. , 8.3, 7. , 2.6, 30. , 8. ],
[19. , 6.2, 5. , 4.3, 10. , 6. ],
[20. , 7.6, 6. , 3.1, 25. , 7. ],
[21. , 8.4, 3. , 6.3, 40. , 7. ],
[22. , 6.4, 4. , 5.1, 15. , 6. ],
[23. , 7.1, 6. , 3.3, 30. , 7. ]]),

array([[24. , 5.7, 3. , 6.7, 0. , 5. ],
[25. , 7.9, 7. , 2.8, 25. , 8. ],
[26. , 6.2, 5. , 4.4, 15. , 6. ],
[27. , 7.5, 6. , 3.5, 30. , 7. ],
[28. , 8. , 2. , 6.4, 50. , 7. ],
[29. , 6.5, 5. , 4.2, 20. , 6. ],
[30. , 7.4, 6. , 3.6, 35. , 7. ]])]

The information is now divided into 4 chunks, every of which may now be simply analyzed individually.

Step 4 – Calculate weekly metrics

I wished to see how every behavior modified from week to week. So I targeted on 4 most important issues:

  • common sleep time
  • common research time
  • common display screen time
  • common temper rating

I saved the weekly array in a separate variable after which used it np.imply() Calculate the common of every metric.

common sleep time

# retailer into variables
week_1 = weekly_data[0]
week_2 = weekly_data[1]
week_3 = weekly_data[2]
week_4 = weekly_data[3]

# TODO: Compute common sleep
week1_avg_sleep = np.imply(week_1[:, 1])
week2_avg_sleep = np.imply(week_2[:, 1])
week3_avg_sleep = np.imply(week_3[:, 1])
week4_avg_sleep = np.imply(week_4[:, 1])

common research time

# TODO: Compute common research hours
week1_avg_study = np.imply(week_1[:, 2])
week2_avg_study = np.imply(week_2[:, 2])
week3_avg_study = np.imply(week_3[:, 2])
week4_avg_study = np.imply(week_4[:, 2])

common display screen time

# TODO: Compute common display screen time
week1_avg_screen = np.imply(week_1[:, 3])
week2_avg_screen = np.imply(week_2[:, 3])
week3_avg_screen = np.imply(week_3[:, 3])
week4_avg_screen = np.imply(week_4[:, 3])

common temper rating

# TODO: Compute common temper rating
week1_avg_mood = np.imply(week_1[:, 5])
week2_avg_mood = np.imply(week_2[:, 5])
week3_avg_mood = np.imply(week_3[:, 5])
week4_avg_mood = np.imply(week_4[:, 5])

I then formatted the outcomes correctly to make all the things simpler to learn.

# TODO: Show weekly outcomes clearly
print(f”Week 1 — Common sleep: {week1_avg_sleep:.2f} hrs, Research: {week1_avg_study:.2f} hrs, “
f”Display screen time: {week1_avg_screen:.2f} hrs, Temper rating: {week1_avg_mood:.2f}”)

print(f”Week 2 — Common sleep: {week2_avg_sleep:.2f} hrs, Research: {week2_avg_study:.2f} hrs, “
f”Display screen time: {week2_avg_screen:.2f} hrs, Temper rating: {week2_avg_mood:.2f}”)

print(f”Week 3 — Common sleep: {week3_avg_sleep:.2f} hrs, Research: {week3_avg_study:.2f} hrs, “
f”Display screen time: {week3_avg_screen:.2f} hrs, Temper rating: {week3_avg_mood:.2f}”)

print(f”Week 4 — Common sleep: {week4_avg_sleep:.2f} hrs, Research: {week4_avg_study:.2f} hrs, “
f”Display screen time: {week4_avg_screen:.2f} hrs, Temper rating: {week4_avg_mood:.2f}”)

output:

Week 1 – Common sleep: 6.94 hrs, Research: 5.00 hrs, Display screen time: 4.31 hrs, Temper rating: 6.50
Week 2 – Common sleep: 6.97 hrs, Research: 5.00 hrs, Display screen time: 4.39 hrs, Temper rating: 6.62
Week 3 – Common sleep: 7.13 hrs, Research: 5.00 hrs, Display screen time: 4.33 hrs, Temper rating: 6.57
Week 4 – Common sleep: 7.03 hrs, Research: 4.86 hrs, Display screen time: 4.51 hrs, Temper rating: 6.57

Step 5 — Perceive the outcomes

As soon as I printed out the numbers, I began to see some patterns.

my sleep time It was fairly secure for the primary two weeks (about 6.9 hours), however by the third week it jumped to about 7.1 hours. That signifies that because the months handed, I used to be capable of sleep higher. By week 4, it was round 7.0 hours.

for research timeit was the alternative. Weeks 1 and a pair of averaged about 5 hours per day, which decreased to about 4 hours by week 4. Mainly, I began off robust however step by step misplaced momentum. To be trustworthy, this appears about proper.

Then got here display screen time. This one was a bit of painful. Within the first week, it was about 4.3 hours per day, and every week it elevated barely. It is a traditional cycle of excessive productiveness within the early days and slowly growing “scroll breaks” within the second half of the month.

Lastly, there was feeling. My temper rating began at about 6.5 in week 1, rose barely to six.6 in week 2, and stayed there for the remainder of the week. It wasn’t a dramatic change, but it surely was attention-grabbing to see a small spike throughout the second week, proper earlier than I began spending much less time learning and extra time screens.

To make it interactive, I believed it could be nice to visualise it utilizing matplotlib.

Step 6 — Search for patterns

Now that I do know the numbers, I wished to know. why I felt higher within the second week.

So I made a decision to match them by week. In the course of the second week, I had extra sleep, extra research time, and comparatively much less display screen time in comparison with later weeks.

That will clarify why my temper scores peaked there. By the third week, my research time began to lower, although I used to be getting extra sleep. You in all probability acquired extra relaxation, however much less accomplishment, and did not really feel as excessive as you anticipated.

What I favored about this venture is that it is not concerning the information being actual, it is about how one can make it occur. Use NumPy Discover patterns, relationships, and small insights. Even fictional information can inform a narrative should you take a look at it accurately.

Step 7 — Abstract and subsequent steps

On this little venture, I discovered just a few vital issues about NumPy and structuring analyzes like this.

We began with a uncooked array of hypothetical each day habits, discovered the right way to examine its construction and validity, divided it into significant chunks (weeks), after which analyzed every section utilizing easy NumPy operations.

This can be a small venture that reminds us that information evaluation would not need to be difficult. Generally all it takes is an easy query like: “How does display screen time change over time?” or “When do I really feel the most effective?”

If you wish to take this additional (and also you in all probability will), there are a lot of instructions you may go.

  • please discover greatest day and worst day entire
  • evaluate Comparability of weekdays and weekends
  • Alternatively, you may mix a number of habits to create a easy “happiness rating.”

However that can in all probability be the following a part of the collection.

To this point, I am joyful that I have been capable of apply NumPy not simply to summary arrays and numbers, however to issues which are actual and relatable, like habits and feelings. That is studying that sticks.

Thanks for studying.

If you happen to observe the collection, attempt recreating this with your personal fictional information. On this course of you’ll learn to slice, partition, and analyze arrays like a professional, even when the numbers are random.

banner
Top Selling Multipurpose WP Theme

Converter

Top Selling Multipurpose WP Theme

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

banner
Top Selling Multipurpose WP Theme

Leave a Comment

banner
Top Selling Multipurpose WP Theme

Latest

Best selling

22000,00 $
16000,00 $
6500,00 $

Top rated

6500,00 $
22000,00 $
900000,00 $

Products

Knowledge Unleashed
Knowledge Unleashed

Welcome to Ivugangingo!

At Ivugangingo, we're passionate about delivering insightful content that empowers and informs our readers across a spectrum of crucial topics. Whether you're delving into the world of insurance, navigating the complexities of cryptocurrency, or seeking wellness tips in health and fitness, we've got you covered.