Bernard Aybouts - Blog - Miltonmarketing.com

Approx. read time: 2.8 min.

Post: Learn about Numpy Arrays in Python programming

Lesson: Introduction to Numpy Arrays in Python

Getting Started with Numpy Arrays

Numpy arrays are a powerful alternative to Python lists. They are particularly useful for handling large amounts of data due to their speed and efficiency. Numpy arrays allow you to perform mathematical operations across entire arrays, which is faster and more intuitive than using Python lists.

Some key advantages of Numpy arrays:

  • Fast: Numpy arrays are more efficient than Python lists.
  • Easy to work with: You can easily create and manipulate arrays.
  • Mathematical operations: You can perform calculations across entire arrays in one go.

In this lesson, we will explore the basics of Numpy arrays with examples.


Example 1: Creating a Numpy Array

You can convert Python lists into Numpy arrays using the numpy.array() function. Let’s create two arrays from height and weight data.

Copy to Clipboard

Explanation:

  • We first create two lists: height and weight.
  • We use np.array() to convert these lists into Numpy arrays: np_height and np_weight.
  • The type() function is used to confirm that np_height is indeed a Numpy array.

Output:

Copy to Clipboard

Example 2: Element-wise Calculations

One of the major benefits of Numpy arrays is the ability to perform element-wise operations. Let’s calculate the Body Mass Index (BMI) for each observation using the formula:

Copy to Clipboard

Explanation:

  • We compute BMI by dividing the weight by the square of the height for each observation.
  • This is an element-wise operation performed on the entire array.

Output (example BMI values):

Copy to Clipboard

Example 3: Subsetting Numpy Arrays

You can easily subset Numpy arrays to extract specific values. Let’s find the BMI values that are greater than 23.

Copy to Clipboard

Explanation:

  • We use a boolean condition bmi > 23 to create a mask (array of True or False values).
  • We use this mask to filter and extract only the BMI values that satisfy the condition.

Output (example):

Copy to Clipboard

Exercise: Convert Weights from Kilograms to Pounds

Task: Convert the list of weights from kilograms to pounds. Use the scalar conversion factor of 1 kg=2.2 lbs.

Steps:

  1. Convert the list of weights in kilograms to a Numpy array.
  2. Convert each weight from kilograms to pounds using element-wise multiplication.
  3. Print the resulting array of weights in pounds.
Copy to Clipboard

Expected Output:

Copy to Clipboard

Final Assignment: Numpy Arrays Practice

Problem: You are given two lists: one containing the heights of individuals in meters and the other containing their weights in kilograms. You need to:

  1. Convert both lists into Numpy arrays.
  2. Calculate the BMI for each individual.
  3. Find and print the BMI values greater than 25.
  4. Convert the weights from kilograms to pounds and print the result.

Here is the data:

  • Heights: [1.72, 1.85, 1.65, 1.90, 1.75] (in meters)
  • Weights: [65.0, 80.5, 72.3, 90.0, 85.6] (in kilograms)

Final Assignment Solution (Answer Key)

Copy to Clipboard

Expected Output:

Copy to Clipboard

Conclusion

In this lesson, we learned how to:

  • Create Numpy arrays from Python lists.
  • Perform element-wise operations on Numpy arrays.
  • Subset arrays based on conditions.
  • Use Numpy to quickly convert units of measurement.

Numpy arrays are an excellent tool for handling large datasets efficiently, and with these basic skills, you can now start exploring more advanced features of Numpy.


Assignment Idea: a. Try working with larger datasets and practice subsetting and element-wise operations. b. Explore other Numpy functions like np.mean(), np.median(), and np.std() for basic statistical calculations.

The Longevity Blueprint: AI-Powered Health Optimization

Current step:1AI-Human Medical Analyzer: Smarter, Personalized Health
2AI-Human Medical Analyzer: Smarter, Personalized Health

> SYS.HEALTH: AI-Human Medical Analyzer_

// Revolutionize Your Diagnostics

Experience the perfect blend of cutting-edge AI precision and expert human care. Our revolutionary analyzer turns your raw health data into personalized, actionable insights tailored just for you.

> INITIALIZING_BIOMETRIC_SCAN...

[+] DATA_INPUT

Securely upload complex health parameters, including lab bloodwork and comprehensive medical history.

[+] PROCESSING

Advanced algorithmic parsing combined with human-level oversight ensures hyper-accurate data interpretation.

[+] OUTPUT_MATRIX

Receive smarter, faster, and truly personalized care strategies to take immediate charge of your health journey.

A name/nickname is required to continue.

> TRANSLATION_MATRIX_ACTIVE...
[ LANG_EN ]
Knowledge Heals, Prevention Protects
[ LANG_HI ]
ज्ञान ठीक करता है, रोकथाम सुरक्षा करती है
[ LANG_ZH ]
知识治愈,预防保护
[ LANG_JA ]
知識は癒し、予防は守る
[ LANG_HE ]
הידע מרפא, המניעה מגנה
[ LANG_AR ]
المعرفة تُشفي، والوقاية تحمي
[ LANG_FR ]
La connaissance guérit, la prévention protège

> SYS.AUTH: Data Processing Consent_

[ AWAITING_AUTHORIZATION ] By providing consent, you allow us to process your uploaded data through our proprietary AI-Human analysis system.

  • [+] SECURE_REVIEW: This ensures your information is carefully reviewed using advanced AI technology and certified professional oversight to deliver personalized health insights.
  • [+] PRIVACY_LOCK: Your privacy is our strict priority. Your data will only be used for this specific diagnostic purpose.

> SYS.UPLOAD: Share Medical Records [OPTIONAL]_

[ USER_CONTROL_ACTIVE ] Uploading your medical records during registration is entirely optional. You can choose to bypass this step and provide data later if it suits your timeline.

You dictate the data flow: share as much or as little as you’re comfortable with, and let us guide you toward better health.

[+] FORMAT_SUPPORT

We accept all file formats, including photos, PDFs, text documents, and raw official medical data.

[+] DATA_YIELD

Increased inputs correlate with higher precision. The more info you share, the better we tailor your personalized insights.

> NEXT_STEPS: Post-Registration Protocol_

Once your registration is complete, a human specialist from our team will personally reach out to you within 3-10 business days. We will discuss your health journey and map out exactly how we can support you.

About the Author: Bernard Aybout (Virii8)

Avatar Of Bernard Aybout (Virii8)
I am a dedicated technology enthusiast with over 45 years of life experience, passionate about computers, AI, emerging technologies, and their real-world impact. As the founder of my personal blog, MiltonMarketing.com, I explore how AI, health tech, engineering, finance, and other advanced fields leverage innovation—not as a replacement for human expertise, but as a tool to enhance it. My focus is on bridging the gap between cutting-edge technology and practical applications, ensuring ethical, responsible, and transformative use across industries. MiltonMarketing.com is more than just a tech blog—it's a growing platform for expert insights. We welcome qualified writers and industry professionals from IT, AI, healthcare, engineering, HVAC, automotive, finance, and beyond to contribute their knowledge. If you have expertise to share in how AI and technology shape industries while complementing human skills, join us in driving meaningful conversations about the future of innovation. 🚀