美文网首页我爱编程
numpy newaxis 使用方法

numpy newaxis 使用方法

作者: sherrysack | 来源:发表于2017-06-27 20:37 被阅读0次

import numpy as np
x1 = np.array([10, 20, 30], float)
print "shape of x1 is ", x1.shape
print x1

x2 = x1[:, np.newaxis]
print "shape of x2 is ", x2.shape
print x2

x3 = x1[np.newaxis, :]
print "shape of x3 is ", x2.shape
print x2

---result---
shape of x1 is  (3,)
[ 10.  20.  30.]
shape of x2 is  (3, 1)
[[ 10.]
 [ 20.]
 [ 30.]]

shape of x3 is (1L, 3L)
[[ 10. 20. 30.]]

相关文章

网友评论

    本文标题:numpy newaxis 使用方法

    本文链接:https://www.haomeiwen.com/subject/hstycxtx.html