- 1
One-dimensional and two-dimensional
How to make two-dimensional into a one-dimensional vector? And can display 1 in ndim THX
6 Respostas
+ 3
I'm guessing you're talking about numpy arrays. In that case, you can use the flatten method:
import numpy as np
a = np.array([[1, 2], [3, 4]])
b = a.flatten()
print(b) # [1 2 3 4]
print(b.ndim) # 1
Docs: https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.ndarray.flatten.html
+ 3
If you want the shape to be (1,35), you can use reshape()
arrayB=arrayA.reshape((1,35))
But then arrayB would technically remain 2-dimensional. np.ndim(arrayB) would print 2.
+ 2
The tuple (1, 35) has length two. Thus ndim() on an array of shape (1, 35) will always return 2.
More generally, the length of the tuple given by shape() will always be equal to ndim().
+ 2
Thanksgiving😀😀
+ 1
https://code.sololearn.com/cj7V45vYnA34/?ref=app
I want to ask is to use arrayB=np.ravel (arrayA), then print(np.shape(arrayB)) will run out (35,), can it run out (1,35)?
0
So how to make np.shape (1,35) and np.ndim() as two-dimensional