Changes

Jump to navigation Jump to search

Workshop: Advanced Computation (with Python)

1,579 bytes added, 20:48, 7 October 2019
Added intro and Reformatting Arrays
This workshop focuses on developing your computational skills with python. What does this mean? Over the course of this workshop you will learn NumPy and Matplotlib (two popular libraries for python). Using these libraries, you can run computations over matrices. This might not mean much to you now, but what this effectively means is that after taking this workshop you will have the tools to build scripts with the ability to do linear algebra, convolution, image analysis, and much more.
 
==Modules and Packages==
Modules and packages are a feature of Python wherein, you can import subtasks (or modules) into your code. Using modules and packages leads to cleaner code because the files you create are less verbose.
*3+ refers to additional arbitrary axes
==== numpy.concatenate ====
Maybe instead of appending data to your array line-by-line you want to take data from multiple arrays and add them to the end of an existing axis. In this case you should use the concatenate method. It takes 2 main arguments; a list of arrays to concatenate and an integer to differentiate which axis it should be appended to. '''It is important to note that this command only works if the arrays are the same size EXCEPT in the axis which they are being concatenated to.'''
==== numpy.stack ====
''(See also: [https://docs.scipy.org/doc/numpy/reference/generated/numpy.dstack.html?highlight=dstack#numpy.dstack numpy.dstack], [https://docs.scipy.org/doc/numpy/reference/generated/numpy.hstack.html?highlight=hstack#numpy.hstack numpy.hstack], [https://docs.scipy.org/doc/numpy/reference/generated/numpy.vstack.html?highlight=vstack#numpy.vstack numpy.vstack])''
Let’s imagine you have many arrays of data and you want to stack them onto of each other. (Example: You have x,y arrays of light intensity on different materials like plastic, wood and glass. You want to create a new matrix with size x,y,z where z represents different materials.) This is the perfect use for numpy.stack. The command takes two main arguments; a list of arrays to stack ('''It is important to note that the stack command only works for array with the same shape''') and an integer representing the new axis where the stacked arrays will grow.  <br /> === Reformatting Arrays === ==== '''Numpy.reshape''' ====The reshape command is super useful if you have an array of good data and you just want to change the arrangement. Maybe you have a 5x5 matrix that you want to convert to a list, or maybe you have a 6x4 matrix that you want to be a 8x3 matrix. Whatever the case, the syntax to this command is straightforward:  <code>np.transpose(A,new_shape)</code> Here A is the original matrix and new_shape is a tuple of integers (a tuple is basically a list surrounded by parentheses, so don’t forget those parenthesis!).  '''Remember: The components of the new array size must multiply to equal the total number of elements in the array.''' ==== '''Numpy.transpose''' ====If you have taken Linear Algebra before then you know the importance of the “transpose matrix”. For those of you who haven’t taken Linear Algebra, the transpose matrix is the matrix that forms when you flip the x and y components of an array. The syntax is simply np.transpose(A), where A is the original matrix. This is best seen with an example. <br />
118
edits

Navigation menu