Let's begin with the basics of NumPy. There are different ways to create NumPy arrays but the easiest way will be to use something that we are all familiar with, which are lists, and pass it to the array()
function.
Syntax
nameofarray = np.array(lists)
Below are some examples. Click on the Run button in each trinket to view the results.
To find out what data types are in an array, you can use .dtype
Syntax
print(myArray.dtype)
You can edit an element in an array by referring to its index.
Recall that myArray = [1 2 3 4 5 6 7]
. You can change the first element of myArray
from 1
to 20
by referring to its index (which is 0
).
myArray[0] = 20
You can also check the shape of an array (i.e. number of rows and columns) using .shape
You are expected to comply with University policies and guidelines namely, Appropriate Use of Information Resources Policy, IT Usage Policy and Social Media Policy. Users will be personally liable for any infringement of Copyright and Licensing laws. Unless otherwise stated, all guide content is licensed by CC BY-NC 4.0.