You are on page 1of 1

Numpy - Annotations

- Applications of numpy:
- Mathematics(MATLAB Replacement)
- Plotting(Matplotlib)
- Backend(Pandas, Connect 4, Digital Photography)
- Machine learning
- Basic functions:
- np.array = creates a list which can have 1-3 dimensions
- np.array([1,2,3]) #output: [1,2,3]
- var.ndim = get the dimension of the list
- a.ndim #output: 1
- var.shape = get the shape of the list
- a.shape #output: (1,1)
- var.dtype = get type
- a.dtype # output: int16
- var.itemsize = get size
- a.size #output: 4
- var.size/var.nbytes = get total size
- a.nbytes #output = 12
- a.size #output = 12
- Accessing/Changing specifics elements,rows, columns, etc
- var[r, c] = get specific element
- var[0, :] = get specific row
- var[:, 2] = get specific column
- var[startindex:endindex:stepsize] = interval
- var[1,5] = 20 = replace the element of the list to another
- Initializing Differents types of Arrays
- np.zeros((2,2)) = creates an array with zeros
- np.ones((2,2)) = creates an array with ones
- np.full((r,c), num) =creates an array with any number
- np.full_like(a, 4) = insert 4 all of the array
- np.random.random_sample(a.shape) = get the a shape and add random
numbers that variates 0 to 1
- np.repeat() = repeat a number in the array
- When copying arrays, use the .copy() function

You might also like