Python import numpy ; numpy.array (list, dtype = numpy.int16); typing : np.ndarray

加入好友
加入社群
Python import numpy ; numpy.array (list, dtype = numpy.int16); typing : np.ndarray - 儲蓄保險王

 

int8 8 位元有號整數
int16 16 位元有號整數
int32 32 位元有號整數
int64 64 位元有號整數
uint8 8 位元無號整數
uint16 16 位元無號整數
uint32 32 位元無號整數
uint64 64 位元無號整數
float16 16 位元浮點數
float32 32 位元浮點數

import numpy as np
x=np.array([1,2,3],dtype=np.int16)
print(x,type(x))
print(x[0],type(x[0]))

Python import numpy ; numpy.array (list, dtype = numpy.int16); typing : np.ndarray - 儲蓄保險王

Python import numpy ; numpy.array (list, dtype = numpy.int16); typing : np.ndarray - 儲蓄保險王

 

import numpy as np

def myfun(a:np.ndarray):
    return sum(a)

lst = [1,2,3]
ary = np.array(lst)
print(“list: %r, Type: %r”%(lst,type(lst)) )
print(“Array: %r, Type: %r” %( ary ,type(ary)))
print(“Summation:”,myfun(ary) )

lst2D = [
       [1,2,3],
       [4,5,6]
       ]

ary2D = np.array(lst2D)
print(ary2D)
print( “Type of 2D array:”,type(ary2D)  )
#一樣是numpy.ndarray,沒有顯示維度

Python import numpy ; numpy.array (list, dtype = numpy.int16); typing : np.ndarray - 儲蓄保險王

 

加入好友
加入社群
Python import numpy ; numpy.array (list, dtype = numpy.int16); typing : np.ndarray - 儲蓄保險王

儲蓄保險王

儲蓄險是板主最喜愛的儲蓄工具,最喜愛的投資理財工具則是ETF,最喜愛的省錢工具則是信用卡

You may also like...

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *