ximport numpy as np a = np.arange(12).reshape(3,4) print ('原数组:')print (a)print ('\n') print ('转置数组:')print (a.T)
# 输出结果如下:原数组:[[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]]
转置数组:[[ 0 4 8] [ 1 5 9] [ 2 6 10] [ 3 7 11]]xxxxxxxxxxNDArray a = manager.arange(12).reshape(3, 4);System.out.println("原数组:");System.out.println(a.toDebugString(100, 10, 100, 100));System.out.println("转置数组:");NDArray b = a.transpose();System.out.println(b.toDebugString(100, 10, 100, 100));
# 输出结果如下:原数组:ND: (3, 4) cpu() int32[[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11],]
转置数组:ND: (4, 3) cpu() int32[[ 0, 4, 8], [ 1, 5, 9], [ 2, 6, 10], [ 3, 7, 11],]xxxxxxxxxximport numpy.matlib import numpy as np print (np.matlib.zeros((2,2)))
# 输出结果如下:[[0. 0.] [0. 0.]]xxxxxxxxxxa = manager.zeros(new Shape(2, 2));System.out.println(a.toDebugString(100, 10, 100, 100));
# 输出结果如下:ND: (2, 2) cpu() float32[[0., 0.], [0., 0.],]xxxxxxxxxximport numpy.matlib import numpy as np print (np.matlib.ones((2,2)))
# 输出结果如下:[[1. 1.] [1. 1.]]xxxxxxxxxxa = manager.ones(new Shape(2, 2));System.out.println(a.toDebugString(100, 10, 100, 100)); # 输出结果如下:ND: (2, 2) cpu() float32[[1., 1.], [1., 1.],]xxxxxxxxxximport numpy.matlib import numpy as np print (np.matlib.eye(n = 3, M = 4, k = 0, dtype = float))
# 输出结果如下:[[1. 0. 0. 0.] [0. 1. 0. 0.] [0. 0. 1. 0.]]xxxxxxxxxxa = manager.eye(3,4,0, DataType.INT32);System.out.println(a.toDebugString(100, 10, 100, 100)); # 输出结果如下:ND: (3, 4) cpu() int32[[ 1, 0, 0, 0], [ 0, 1, 0, 0], [ 0, 0, 1, 0],]xxxxxxxxxximport numpy.matlib import numpy as np print (np.matlib.rand(3,3))
# 输出结果如下:[[0.23966718 0.16147628 0.14162 ] [0.28379085 0.59934741 0.62985825] [0.99527238 0.11137883 0.41105367]]xxxxxxxxxxa = manager.randomUniform(0,1,new Shape(3,3));System.out.println(a.toDebugString(100, 10, 100, 100)); # 输出结果如下:ND: (3, 3) cpu() float32[[0.356 , 0.9904, 0.1063], [0.8469, 0.5733, 0.1028], [0.7271, 0.0218, 0.8271],]xxxxxxxxxximport numpy.matlibimport numpy as np a = np.array([[1,2],[3,4]])b = np.array([[11,12],[13,14]])print(np.dot(a,b))
# 计算式为:# [[1*11+2*13, 1*12+2*14],[3*11+4*13, 3*12+4*14]]
# 输出结果如下:[[37 40] [85 92]]xxxxxxxxxxNDArray a = manager.create(new int[][]{{1, 2}, {3, 4}});NDArray b = manager.create(new int[][]{{11, 12}, {13, 14}});NDArray c = a.dot(b);// 计算式为:// [[1*11+2*13, 1*12+2*14],[3*11+4*13, 3*12+4*14]]System.out.println(c.toDebugString(100, 10, 100, 100));
# 输出结果如下:ND: (2, 2) cpu() int32[[37, 40], [85, 92],]xxxxxxxxxximport numpy.matlib import numpy as np a = [[1,0],[0,1]] b = [[4,1],[2,2]] print (np.matmul(a,b))
# 输出结果如下:[[4 1] [2 2]]xxxxxxxxxxa = manager.create(new int[][]{{1, 0}, {0, 1}});b = manager.create(new int[][]{{4, 1}, {2, 2}});c = a.matMul(b);System.out.println(c.toDebugString(100, 10, 100, 100));
# 输出结果如下:ND: (2, 2) cpu() int32[[ 4, 1], [ 2, 2],]