Pad the arrays effectively using numpy.pad()

Have you ever come across a situation where you have to add a border to an array or a tensor? Wondering how to go about it? The answer is to use the numpy.pad() The NumPy module has a function named pad() that can be used to pad certain values to the array. In this article, let us discuss the numpy.pad() function and also explore different ways of using it.  What is Padding an Array? Padding means adding some contents to the border of an array. After padding the array, the array would have a different size. But same dimensions. Have … Read more

How to print the full NumPy array without any truncation in the output?

NumPy module in Python is extensively used while working with arrays. When you are working on large arrays, if you try to print the elements of the array, you see that the output is being truncated. For example, consider the following code snippet: import numpy as np arr=np.arange(1001) print(arr)   Output : [ 0 1 2 … 998 999 1000]   As you can see from the output, the elements after the 3rd element are being truncated and the last few elements are being shown. This happens when the elements in the array exceed 1000 elements. While this might not … Read more