In this post we are going to take a look at data management functions in numpy. Following post will contain syntax, code snippets and description of the functions specified.
Hello Readers,
This article is the part 1 of the 2 part series for the data management functions in Numpy.
Following are the functions or attributes of the numpy array which we will study:
1. np.newaxis
2. squeeze()
3. transpose()
4. T
1. numpy.newaxis
Newaxis can be used to increase the dimension of the numpy array. In cases where we need increase the dimensionality of the ndarray or need to convert row vector to column vector and vice versa, we can use the newaxis object.
But there is also another way to add a new dimension to the numpy array using the None object. For more details refer the following link to the numpy documentation. None in Numpy.
Following is the syntax to use the newaxis and None
arr_ref [:,numpy.newaxis] - adding newaxis after the existing dimensions
arr_ref [numpy.newaxis,:] - adding newaxis before the existing dimension
In both of the above examples numpy.newaxis can be replace with None and the results will be the same.
Following is the code snippet for the newaxis and None:
Snippet 1:
Snippet 2:
Snippet 3:
2. squeeze()
Squeeze function is used to remove the dimension with single entries from the numpy array.
The syntax for using the squeeze function is as follows:
arr_ref.squeeze()
Following is the code snippet for the squeeze function:
3. transpose()
Transpose function is used to get the transpose of the specified numpy array.
Syntax for using the transpose function is as follows:
arr_ref.transpose() - where arr_ref is the numpy array reference
Following is the code snippet for the transpose function:
4. T
T attribute is same as the transpose function but the axis attribute cannot be specified with T as it can be done with the transpose function.
Following is the syntax for using the T attribute:
arr_ref.T - returns transpose of the specified matrix
Following is the code snippet for the T attribute:
Thank you.
That's all for this post!!
Thank you for reading this post.
If you have any suggestions regarding the post contents or if you need some more details on any other topic, please post it in the comments section.
Your suggestions are too valuable so they should not be missed.
References
1. https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html#numpy.newaxis
2. https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.squeeze.html
3. https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.transpose.html
4. https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.ndarray.T.html
Hello Readers,
This article is the part 1 of the 2 part series for the data management functions in Numpy.
Following are the functions or attributes of the numpy array which we will study:
1. np.newaxis
2. squeeze()
3. transpose()
4. T
1. numpy.newaxis
Newaxis can be used to increase the dimension of the numpy array. In cases where we need increase the dimensionality of the ndarray or need to convert row vector to column vector and vice versa, we can use the newaxis object.
But there is also another way to add a new dimension to the numpy array using the None object. For more details refer the following link to the numpy documentation. None in Numpy.
Following is the syntax to use the newaxis and None
arr_ref [:,numpy.newaxis] - adding newaxis after the existing dimensions
arr_ref [numpy.newaxis,:] - adding newaxis before the existing dimension
In both of the above examples numpy.newaxis can be replace with None and the results will be the same.
Following is the code snippet for the newaxis and None:
Snippet 1:
Snippet 3:
2. squeeze()
Squeeze function is used to remove the dimension with single entries from the numpy array.
The syntax for using the squeeze function is as follows:
arr_ref.squeeze()
Following is the code snippet for the squeeze function:
3. transpose()
Transpose function is used to get the transpose of the specified numpy array.
Syntax for using the transpose function is as follows:
arr_ref.transpose() - where arr_ref is the numpy array reference
Following is the code snippet for the transpose function:
4. T
T attribute is same as the transpose function but the axis attribute cannot be specified with T as it can be done with the transpose function.
Following is the syntax for using the T attribute:
arr_ref.T - returns transpose of the specified matrix
Following is the code snippet for the T attribute:
Thank you.
That's all for this post!!
Thank you for reading this post.
If you have any suggestions regarding the post contents or if you need some more details on any other topic, please post it in the comments section.
Your suggestions are too valuable so they should not be missed.
References
1. https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html#numpy.newaxis
2. https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.squeeze.html
3. https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.transpose.html
4. https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.ndarray.T.html
Comments
Post a Comment