python中shape用法

x_data.shape = -1, 1 # 将x_data调整为(任意行,1列)

import numpy as np
x_data = np.linspace(0,10,100)
print(type(x_data),x_data)

x_data.shape = -1, 1   # 将x_data调整为(任意行,1列)
print(type(x_data),x_data)

输出分别如下:

<class 'numpy.ndarray'> 
[ 0.          1.11111111  2.22222222  3.33333333  4.44444444  5.55555556
  6.66666667  7.77777778  8.88888889 10.        ]

<class 'numpy.ndarray'> 
[[ 0.        ]
 [ 1.11111111]
 [ 2.22222222]
 [ 3.33333333]
 [ 4.44444444]
 [ 5.55555556]
 [ 6.66666667]
 [ 7.77777778]
 [ 8.88888889]
 [10.        ]]
发布了71 篇原创文章 · 获赞 17 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qionggaobi9328/article/details/99169777