numpy.array_repr()function用於將數組轉換為字符串。
用法: numpy.array_repr(arr, max_line_width=None, precision=None, suppress_small=None)
參數:
arr :[數組]輸入數組。
max_line_width :[int,可選]字符串應跨越的最大列數。換行符會在數組元素之後適當地分割字符串。
precision :[int,可選]浮點精度。默認值為當前的打印精度(通常為8)。
suppress_small :[布爾,可選]它表示非常小的數字,為零,默認值為False。很小的數字由精度定義,如果精度為8,則小於5e-9的數字表示為零。
Return :[str]數組的字符串表示形式。
代碼1:工作
# Python program explaining
# array_repr() function
import numpy as geek
arr = geek.array([4, -8, 7 ])
print ("Input array:", arr)
print(type(arr))
out_arr = geek.array_repr(arr)
print ("The string representation of input array:", out_arr)
print(type(out_arr))
輸出:
Input array: [ 4 -8 7] class 'numpy.ndarray' The string representation of input array: array([ 4, -8, 7]) class 'str'
代碼2:工作
# Python program explaining
# array_repr() function
import numpy as geek
in_arr = geek.array([5e-8, 4e-7, 8, -4])
print ("Input array:", in_arr)
print(type(in_arr))
out_arr = geek.array_repr(in_arr, precision = 6, suppress_small = True)
print ("The string representation of input array:", out_arr)
print(type(out_arr))
輸出:
Input array: [ 5.00000000e-08 4.00000000e-07 8.00000000e+00 -4.00000000e+00] class 'numpy.ndarray' The string representation of input array: array([ 0., 0., 8., -4.]) class 'str'
相關用法
注:本文由純淨天空篩選整理自jana_sayantan大神的英文原創作品 numpy.array_repr() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。