numpy学习三
import numpy as np
a=np.array([1,1,1])
b=np.array([2,2,2])
np.vstack((a,b))
array([[1, 1, 1],
[2, 2, 2]])
np.hstack((a,b))
array([1, 1, 1, 2, 2, 2])
a[:,np.newaxis]
array([[1],
[1],
[1]])
a[np.newaxis,:]
array([[1, 1, 1]])
np.concatenate((a,b,b,a),axis=0)
array([1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1])
arr=np.arange(12).reshape((3,4))
arr
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
np.split(arr,2,axis=1)
[array([[0, 1],
[4, 5],
[8, 9]]), array([[ 2, 3],
[ 6, 7],
[10, 11]])]
np.split(arr,3,axis=0)
[array([[0, 1, 2, 3]]), array([[4, 5, 6, 7]]), array([[ 8, 9, 10, 11]])]
np.array_split(arr,3,axis=1)
[array([[0, 1],
[4, 5],
[8, 9]]), array([[ 2],
[ 6],
[10]]), array([[ 3],
[ 7],
[11]])]
arr
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
np.vsplit(arr,3)
[array([[0, 1, 2, 3]]), array([[4, 5, 6, 7]]), array([[ 8, 9, 10, 11]])]
np.hsplit(arr,2)
[array([[0, 1],
[4, 5],
[8, 9]]), array([[ 2, 3],
[ 6, 7],
[10, 11]])]
a=arr
a
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
a is arr
True
b=arr.copy()
b
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])