12. INTRODUCTION TO NUMPY ARRAYS AND BASIC OPERATIONS USING NUMPY

These free B.Pharm notes on numpy arrays and basic operations in python cover chapter 12 of Basics of Python Programming for Pharmaceutical Sciences (BP101T), a first-semester subject. Read the key points below, then study the complete chapter PDF. You can browse every chapter in the Basics of Python Programming for Pharmaceutical Sciences category.

Read the following document for full information

Overview of numpy arrays and basic operations in python

These notes introduce NumPy and the ndarray, its key features, advantages and disadvantages, and important terms such as axis, shape, size and dtype. They then cover array creation methods, indexing and slicing, broadcasting and element-wise arithmetic, ending with worked pharmaceutical problems on dose increase, concentration ratio, tablet scaling and average concentration.

Key points on numpy arrays and basic operations in python

  • A NumPy array, called an ndarray, holds data in one or more dimensions and requires every element to be of the same data type.
  • NumPy arrays are stored in contiguous memory and support vectorised operations, making them faster and more memory-efficient than Python lists.
  • The shape of an array gives its rows and columns, such as (2, 3), while size is the total number of elements.
  • Arrays can be created with array(), zeros(), ones(), arange() and linspace(), which gives evenly spaced values between two points.
  • Broadcasting allows arithmetic between arrays of different shapes, so a + 5 adds 5 to every element of array a.

Relevance to pharmacy practice

Pharmaceutical research produces large sets of numbers such as drug concentrations, dosages and laboratory readings. NumPy lets a student adjust doses, compare concentrations, scale tablet production and calculate averages across a whole array in a single step, without writing loops.

Every chapter in this subject builds on the one before it, so do not skip topics that look simple. Definitions, principles, procedures and examples are the parts that examiners return to most often, and a clear understanding here will also make later subjects easier to follow in the coming semesters.

Frequently asked questions on numpy arrays and basic operations in python

Why are NumPy arrays faster than Python lists?

NumPy arrays store elements of one data type in contiguous blocks of memory and support vectorised operations, so calculations are applied to the whole array at once without loops.

What is broadcasting in NumPy?

Broadcasting lets arithmetic be performed between arrays of different shapes without manually resizing the smaller one. For example, a + 5 adds 5 to every element of a.

What are the disadvantages of NumPy arrays?

NumPy arrays have a fixed size after creation, need some learning of their own syntax, and cannot hold mixed data types the way a Python list can.

Quick revision checklist

Use this self-test after reading the chapter on numpy arrays and basic operations in python. If you can do all of the following without looking at your notes, you are ready for the exam.

  • I can explain: what an ndarray is
  • I can explain: key features of NumPy arrays
  • I can explain: axis, shape, size and dtype
  • I can explain: creating arrays with NumPy built-in functions
  • I can explain: broadcasting and element-wise arithmetic

Study and exam tips

Start by reading the chapter once for the overall idea, then revise numpy arrays and basic operations in python using headings, definitions, principles, reactions and examples. Short-answer questions in the university exam usually ask for definitions, principles, procedures, reactions and uses, so write these in your own words and practise the equations, tables and flow charts that the chapter has.

For wider reading, standard books and open resources such as the NCBI Bookshelf help you confirm terms and see more examples. Revise numpy arrays and basic operations in python again a day later and again a week later, because spaced revision improves long-term memory.

This page is part of the Basics of Python Programming for Pharmaceutical Sciences series for first-semester B.Pharm students on B.Pharm Guru, where every chapter has a short summary and a full PDF. Bookmark this page and share it with classmates who are preparing for the same exam.

Related notes: 14. UNDERSTANDING STRUCTURED HEALTHCARE DATASETS, 15. IMPORTING SMALL PHARMACEUTICAL DATASETS AND PERFORMING BASIC DATA ACCESS AND MANIPULATION TASKS.

Next: 13. READING AND WRITING CSV FILES. Back to the Basics of Python Programming for Pharmaceutical Sciences category.