Introduction To NumPy Array: A Review Of It's Fundamental Features (Part- II)

Introduction To NumPy Array: A Review Of It's Fundamental Features (Part- II)

NumPy Operations

Arithmatic

You can easily perform array with array arithmetic, or scalar with array arithmetic. Let's see some examples:

carbon (18).png

carbon (19).png

Universal Function

Numpy comes with many universal array functions, which are essentially just mathematical operations you can use to perform the operation across the array. Let's show some common ones:

carbon (20).png

carbon (21).png

carbon (23).png

carbon (25).png

NumPy Indexing and Selection

A) Bracket Indexing and Selection: The simplest way to pick one or some elements of an array looks very similar to python lists:

carbon (26).png

carbon (27).png

Broadcasting

Numpy arrays differ from a normal Python list because of their ability to broadcast:

carbon (41).png

carbon (42).png

carbon (43).png

carbon (44).png

Now note the changes also occur in our original array!

carbon (45).png

Indexing a 2D Numpy Array

The general format is arr_2d[row][col] or arr_2d[row,col] I recommend usually using the comma notation for clarity.

carbon (46).png

carbon (48).png

carbon (49).png

carbon (50).png

carbon (51).png

carbon (52).png

Fancy Indexing

Fancy indexing allows you to select entire rows or columns out of order,to show this, let's quickly build out a numpy array:

carbon (30).png

carbon (31).png

carbon (32).png

carbon (33).png

Selection

Let's briefly go over how to use brackets for selection based off of comparison operators.

carbon (34).png

carbon (35).png

carbon (36).png

carbon (37).png

carbon (38).png

carbon (39).png

carbon (40).png

Takeaway

NumPy as is pretty fun and interesting if you are a Python lover like me. So, if you are curious and want something new. Then, play around with these stuff and don't forget to read refer the documentation if you feel stuck.

If you are new to the page and haven't read the first blog. Here you can go and check out: