Numpy Week 2 Notes New
Numpy Week 2 Notes New
1. Numpy arrays:
2. Creating a list and converting it as Numpy array: Creating a list with one data type as numpy array will not take different data types
4. Data type of the above lists and numpy array – official name for numpy array is nd array
5. Numpy matrix
6. We are not creating a matrix here, just displaying the array in the form of matrix
Numpy functions:
1. Using np.arange() function:
2. Creating a function with arguments with start and stop value – where the last value is exclusive
3. Adding a step size or incremental value to the above function
4. Using np.linspace() function – This is the only exception function where the stop value is included. Instead of incremental value, it will
create a evenly spaced numbers between the given range. And 50 is the default value.
5. Example 1
9. Creating a matrix array with bunch of zeroes: 1st element represent rows and 2nd element columns
10. Using np.ones() function – instead of zero we’ll get a matrix with ones
11. Example 1
15. Example 1 – First we define an array, then using the reshape method (it is not called a function, it’s called reshape as it is defined inside an
object name. So it doesn’t change the shape of an actual array.
16. Reshaping the array with insufficient elements – Here 2,6 requires 12 elements, whereas the array which we chose contains only 10. So it
throws an error
18. Trigonometric function: these functions are available only inside the numpy package. We can also assign list inside this
19. Assigning array inside the trigonometric functions:
23. Example 1
25. We can also assign base in log function, if not given, it takes e as default
26. Arithmetic operations on list – It does not sum the values rather it just combine both the lists
Step 2: Using arithmetic operations with 2 matrices- only in division- where a number is divided by 0 it gives the result as inf (infinity)
29. Linear algebra matrix multiplication – defining 2 matrices and performing linear algebra multiplication – eg: 1*11+1*12+1*13 = 90
30. Transpose of a matrix – transpose just mirrors the matrix. It turns the rows into columns and columns into rows
35. Generating random values in a matrix (it contains numbers between 0 and 1 only)
39. Checking the mean and standard deviation of the above matrix
42. Generating random values and creating a list inside the array – here 1 is the starting 10 is the end which is exclusive, and 5,5 is the matrix
3. Accessing multiple non-consecutive entries using np.arange – it gives us 3 rd, 6th and 9th elements
7. Accessing the second row in the matrix – if we give the value inside the square bracket for a matrix it will display the row
8. Accessing 3rd element of the 2nd row – we can enter each element separately inside square bracket or together
10. Accessing matrices using logical operations – but it doesn’t display the output in the matrix structure
11. Modifying the entries of an array
13. Modifying entries using logical operations – assigning 65 to the values which are greater than 0
14. Modifying entries of a matrix – 1:3 denotes rows and 3:5 denotes column
15. Changing all the values of the extracted matrices – we might think that, as we have made these changes in the sub mat. It does not
change the values of the original matrix, but it isn’t
16. What happened to the original matrix – the values are changed in the original matrix also
Under the defined path, it will create a file called saved file name and store the mentioned matrix as a reference which can be used
later
3. Using np.savez function –left of the equal sign is the name which we define and right of the equal sign is the actual name of the matrix
4. Loading the saved files – assigning a new variable to the stores path
To access the savez files, we need to give the new variable and the previously defined name
5. Load/save text files – delimiter is nothing but the separator which we’re using inbetween each value. 2 nd output contains values with
points as we have saved it in text format