# -*- coding: utf-8 -*- """ Created on Wed Nov 9 10:58:16 2022 @author: cpresser """ import numpy as np listOfLists = [[0, 1.5, 2], [3, 4, 5]] array2d = np.array(listOfLists) print("2D Array: ") print(f"{array2d}") #All arrays in the array must be the same length #Every row has the same number of columns #Rectangular arrays #print(f"{listOfLists}") print(listOfLists[1][2]) print(array2d[1][2]) #access using a different notation print(array2d[1,2]) #multiply an element by 2 array2d[0, 1] *= 2 #array2d[0,1] = array2d[0,1] * 2 array2d[1,2] = 0 otherArray2d = 2*array2d + 1 print(f"{array2d}") print(f"{otherArray2d}") #different with lists list1 = [0, 2, 3] list2 = list1*2 print(list1) print(list2) print("---------------") #create and array of zeros array1 = np.zeros(5) print(array1) #create an array with 3 rows and 2 columns array2 = np.zeros((3,2)) array2[0,0] = 1 print(array2) print("---------------") array3 = np.array(range(-2, 2, 1)) array3[2] = 5.7 print(array3) print("---------------") # linspace: linear space sampling # start value # end value (inclusive) # number of values array4 = np.linspace(0, 10, 11) print(array4) print("---------------") #determine the dimensions print(array4.ndim) print(array2d.ndim) print("---------------") array3d = np.zeros((2, 3, 4)) #2 matrices each with 3 rows and four columns array3d[0, 2, 3] = -1 print(array3d) print(f"Dimensions: {array3d.ndim}") print("---------------") print(f"array4's shape is {array4.shape}") print(f"array2d's shape is {array2d.shape}") print(f"array3d's shape is {array3d.shape}") print("---------------") array5 = np.array(5) print(array5) print(f"Dimensions: {array5.ndim}") print(f"array5's shape is {array5.shape}") print("---------------") #create points between 0 and 2pi x = np.linspace(0, 2*np.pi, 10) print(np.cos(x))