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)
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.
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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With