Difference between numpy.array shape (R, 1) and (R,)
Last Updated :
24 Apr, 2025
Difference between numpy.array shape (R, 1) and (R,). In this article, we are going to see the difference between NumPy Array Shape (R,1) and (R,).
Prerequisite: NumPy Array Shape
What is (R, ) ?
(R, ) is a shape tuple of the 1-D array in Python. This shape tuple shows the number of columns in the 1-D array, i.e., the number of elements in that array. Since a 1-D array only has one row, the number of rows is not shown in the shape tuple.
Example: In the given example, we have created a one-dimensional array consisting of 5 elements. 5 elements can also mean that the array has 5 columns. Thus, the shape of the array is outputted as (5, ). One-dimensional arrays can only have one row. Therefore, the shape tuple does not show the number of rows.
Python3
# importing numpy library
import numpy as np
# creating an one-dimensional array
arr_1dim = np.array([1, 2, 3, 4, 5])
# printing the created array and its shape
print('Array: {} \nShape of the array: {}'.format(arr_1dim, arr_1dim.shape))
Output
Array: [1 2 3 4 5]
Shape of the array: (5,)
What is (R, 1)?
The number of elements in the shape tuple of an array can tell us the dimension of that array. Just as when the shape tuple contains one element, it says that the array is 1D, we can infer that when the shape tuple has 2 elements, then the array is 2-dimensional. The first element of the shape tuple of a 2-D array shows the number of rows in that array, while the second element shows the number of columns. The shape (R, 1), thus, says that the 2-D array has only one column.
Example: In the given example, we can see that the 2-D array has 5 rows and only one column. Since the shape tuple of 2-D array first shows the number of rows in the array, the first element of shape tuple contains the number 5. The 2D array has only one column, and therefore, the second element of the 2D array contains the number 1.
Python3
# importing numpy library
import numpy as np
# creating an one-dimensional array
arr_2dim = np.array([[1], [2], [3], [4], [5]])
# printing the created array and its shape
print('Array:\n{} \nShape of the array: {}'.format(arr_2dim, arr_2dim.shape))