pythonのnumpy学習


# -*- 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 16 17 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. ]]
リファレンス