A note for Python beginners. Please be careful about mistakes in the content.
import numpy as np
def test():
a = np.zeros ([5,1]) # 2D array column is created b = np.ones ([5]) # 1D array without column.
print a
print
print "Dimension a: ", a.shape
print
print b, b.shape
print
print "Dimension b: ", b.shape
print
print a + b # 1D + 2D operation print
a = np.squeeze(a)
Change to print a, # 1D print print a + b
if __name__ == '__main__':
test()
Output:
[[ 0.]
[ 0.]
[ 0.]
[ 0.]
[ 0.]]
Dimension a: (5, 1)
[ 1. 1. 1. 1. 1.](5,)
Dimension b: (5,)
[[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]]
[ 0. 0. 0. 0. 0.]
[ 1. 1. 1. 1. 1.]
Recommended Posts