Changes

Jump to navigation Jump to search

Workshop: Advanced Computation (with Python)

629 bytes added, 22:28, 3 October 2019
Added numpy.concatenate and numpy.stack
=== '''Building / Appending to Arrays''' ===
==== numpy.append ====
We can append a new row or column to our matrix using the “append” method. Referring to the documentation you can see that the append method takes 3 arguments. 2 ‘array-like’ variables and an integer. The first variable is the original matrix that you want to add to. The second variable is the row or column of information to append. Finally, the last variable refers to the axis in which the row should be added to the end of. Numpy differentiates between axes like this:
* 0 refers to X* 1 refers to Y* 2 refers to Z* 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])''
Maybe instead Let’s imagine you have many arrays of appending data to your array line-by-line and you want to add all the data from one array 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 the end of an existing arraycreate a new matrix with size x,y,z where z represents different materials. ) This is where the perfect use for numpy.stack method shines. According to the documentation, it The command takes 2 two main arguments; a list of arrays to stack and a integer to differentiate which axis it should be appended to. ('''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 />
118
edits

Navigation menu