# -*- coding: utf-8 -*-
"""
Created on Fri May 12 22:59:30 2017
@author: Administrator
"""
import numpy as np
print (np.version.full_version)
#numpy 对象:数组
a = np.arange(20)
print (a)
print (type(a)) # numpy ndarray
a = a.reshape(4, 5)
print (a)
print('----------------------')
a = a.reshape(2,2,5)
print (a)
print('----------------------')
a = a.reshape(4,1,5)
print (a)
#创建数组
raw = [0, 1, 2, 3, 4]
a = np.array(raw)
print(a)
raw = [ [0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
a = np.array(raw)
print (a)
print('----------------------')
d = (4, 5)
print (np.zeros(d))
d = (4, 5)
print (np.ones(d, dtype=int))
print('----------------------')
#[0, 1)区间随机数组
print(np.random.rand(5))
print('----------------------')
#数组操作 +, - , * ,/
a = np.array([[1.0, 2], [2, 4]])
print (a)
b = np.array([[3.2, 1.5], [2.7, 4]])
print (b)
print (a+b)
输出:
1.11.3
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19]
[15 16 17 18 19]]
[[[ 0 1 2 3 4]
[ 5 6 7 8 9]]
[[10 11 12 13 14]
[15 16 17 18 19]]]
[[[ 0 1 2 3 4]]
[[ 5 6 7 8 9]]
[[10 11 12 13 14]]
[[15 16 17 18 19]]]
[0 1 2 3 4]
[[0 1 2 3 4]
[5 6 7 8 9]]
[[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]]
[[1 1 1 1 1]
[1 1 1 1 1]
[1 1 1 1 1]
[1 1 1 1 1]]
[ 0.47855591 0.42948858 0.09254653 0.25487156 0.82612193]
[[ 1. 2.]
[ 2. 4.]]
[[ 3.2 1.5]
[ 2.7 4. ]]
[[ 4.2 3.5]
[ 4.7 8. ]]