Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between (N,) and (N,1) in numpy? [duplicate]

I am not sure about the difference between (N,) and (N,1) in numpy. Assuming both are some features, they have same N dimension, and both have one sample. What's the difference?

a = np.ones((10,))
print(a.shape) #(10,)
b = np.ones((10,1))
print(b.shape) #(10,1)
like image 341
jef Avatar asked Mar 19 '17 04:03

jef


People also ask

What does N mean in NumPy?

In Python, arrays from the NumPy library, called N-dimensional arrays or the ndarray, are used as the primary data structure for representing data. In this tutorial, you will discover the N-dimensional array in NumPy for representing numerical and manipulating data in Python.

What does NumPy repeat do?

The NumPy repeat function essentially repeats the numbers inside of an array. It repeats the individual elements of an array. Having said that, the behavior of NumPy repeat is a little hard to understand sometimes.

What does array [: n mean in Python?

If an array has shape (n,) , that means it's a 1-dimensional array with a length of n along its only dimension. It's not a row vector or a column vector; it doesn't have rows or columns.

Is NumPy copy a Deepcopy?

Copy: This is also known as Deep Copy. The copy is completely a new array and copy owns the data. When we make changes to the copy it does not affect the original array, and when changes are made to the original array it does not affect the copy.


1 Answers

In Python, (10,) is a one-tuple (the , being necessary to distinguish it from the use of parentheses for grouping: (10) just means 10), whereas (10,1) is a pair (a 2-tuple). So np.ones((10,)) creates a one-dimensional array of size 10, whereas np.ones((10,1)) creates a two-dimensional array of dimension 10×1. This is directly analogous to, say, the difference between a single number and a one-dimensional array of length 1.

like image 172
ruakh Avatar answered Sep 22 '22 03:09

ruakh