1. 程式人生 > >np.expand_dims函式

np.expand_dims函式

# -*- coding: utf-8 -*-
"""
Created on Wed Nov 21 01:51:42 2018
#QQ群:476842922(歡迎加群討論學習)
"""
import numpy as np
x = np.array([1,2])
print(x.shape)
print(x)
y = np.expand_dims(x, axis=0)#expand_dims(a, axis)就是在axis的那一個軸上把資料加上去
print(y.shape)
print(y)

n = np.expand_dims(x, axis=1)
print(n.shape) 
print
(n)

(2,)
[1 2]
(1, 2)
[[1 2]]
(2, 1)
[[1]
[2]]