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))
Output
Array:
[[1]
[2]
[3]
[4]
[5]]
Shape of the array: (5, 1)
Difference between numpy.array shape (R, 1) and (R,)
We shall now see the difference between the numpy.array shape (R, 1) and (R, ) with the help of given example.
Python3
# importing the NumPy library
import numpy as np
# creating a 1D array
arr_1d = np.array([1, 2, 3, 4])
# creating a 2D array
arr_2d = np.array([[1],[2],[3],[4]])
print(arr_1d, '\nShape of the array: ', arr_1d.shape)
print()
print(arr_2d, '\nShape of the array: ', arr_2d.shape)
Output
[1 2 3 4]
Shape of the array: (4,)
[[1]
[2]
[3]
[4]]
Shape of the array: (4, 1)
Here, the shape of the 1D array is (4, ) and the shape of the 2D array is (4, 1).
|
Shape tuple contains two elements.
| Shape tuple has only one element.
|
The 1st element of shape tuple shows the number of rows and the 2nd element shows the number of columns.
| There is only one element and that element shows the number of columns in that array.
|
It can have multiple rows.
| It has only one row.
|
It has only one column.
| It can have multiple columns.
|
The size of the array is R x 1 (Rows x Columns).
| The size of the array is 1 x R (Rows x Columns).
|
Array is 2-Dimensional.
| Array is 1-Dimensional.
|
Similar Reads
Difference between Numpy array and Numpy matrix
While working with Python many times we come across the question that what exactly is the difference between a numpy array and numpy matrix, in this article we are going to read about the same. What is np.array() in PythonThe Numpy array object in Numpy is called ndarray. We can create ndarray using
3 min read
Difference between List and Array in Python
In Python, lists and arrays are the data structures that are used to store multiple items. They both support the indexing of elements to access them, slicing, and iterating over the elements. In this article, we will see the difference between the two.Operations Difference in Lists and ArraysAccessi
6 min read
Difference between NumPy and SciPy in Python
There are two important packages in Python: NumPy and SciPy. In this article, we will delve into the key differences between NumPy and SciPy, their features, and their integration into the ecosystem. and also get to know which one is better. What is NumPy?NumPy also known as Numerical Python, is a f
3 min read
Difference between Tensor and Variable in Pytorch
In this article, we are going to see the difference between a Tensor and a variable in Pytorch. Pytorch is an open-source Machine learning library used for computer vision, Natural language processing, and deep neural network processing. It is a torch-based library. It contains a fundamental set of
3 min read
Is there any difference between int[] a and int a[] in Java?
An array in Java is a group of like-typed variables referred to by a common name. Arrays in Java work differently than they do in C/C++. In Java, Array can be declared in the following ways: One-Dimensional Arrays: The general form of a one-dimensional array declaration is type var-name[];ORtype[] v
6 min read
What's the Difference Between Reshape and View in PyTorch?
PyTorch, a popular deep learning framework, offers two methods for reshaping tensors: torch.reshape and torch.view. While both methods can be used to change the shape of tensors, they have distinct differences in their behavior, constraints, and implications for memory usage. This article delves int
5 min read
Differences between Flatten() and Ravel() Numpy Functions
We have two similar kinds of ways to convert a ndarray to a 1D array of Flatten() and Ravel() Numpy function in Python programming language. Example of Flatten() Numpy function Here, we will create a Numpy array, and then by using flatten function we have changed the element in the flattened 1D NumP
3 min read
Difference between NumPy.dot() and '*' operation in Python
In Python if we have two numpy arrays which are often referred as a vector. The '*' operator and numpy.dot() work differently on them. It's important to know especially when you are dealing with data science or competitive programming problem. Working of '*' operator '*' operation caries out element
2 min read
Find the sum and product of a NumPy array elements
In this article, let's discuss how to find the sum and product of NumPy arrays. Sum of the NumPy array Sum of NumPy array elements can be achieved in the following ways Method #1:  Using numpy.sum() Syntax: numpy.sum(array_name, axis=None, dtype=None, out=None, keepdims=<no value>, initial=
5 min read
Different Ways to Create Numpy Arrays in Python
Creating NumPy arrays is a fundamental aspect of working with numerical data in Python. NumPy provides various methods to create arrays efficiently, catering to different needs and scenarios. In this article, we will see how we can create NumPy arrays using different ways and methods. Ways to Create
3 min read