Numpy 的 fromstring(~)
方法根據指定的字符串構造 Numpy 數組。
參數
1. string
| str
將用於構造 Numpy 數組的字符串。
2. dtype
| string
或 type
| optional
Numpy 數組中存儲的數據類型。默認情況下,dtype=float
。
3. count
| int
| optional
從字符串開頭讀取的數據數。
4. sep
| string
用於分隔輸入字符串中的元素的分隔符。默認值已被棄用,因此請始終指定此參數。
返回值
具有指定數據類型的 Numpy 數組。
例子
基本用法
要讀取空格分隔的格式:
np.fromstring("4 5.6", sep=" ")
array([4. , 5.6])
指定計數
要僅讀取前兩個data-points,請像這樣設置count=2
:
np.fromstring("4,5,6,7", count=2, sep=",")
array([4., 5.])
相關用法
- Python Django fromstr用法及代碼示例
- Python dict fromkeys()用法及代碼示例
- Python NumPy fromfunction方法用法及代碼示例
- Python NumPy frombuffer方法用法及代碼示例
- Python Django fromfile用法及代碼示例
- Python Django from_queryset用法及代碼示例
- Python NumPy fromiter方法用法及代碼示例
- Python frozenset()用法及代碼示例
- Python frexp()用法及代碼示例
- Python fractions.Fraction用法及代碼示例
- Python fractions.Fraction.limit_denominator用法及代碼示例
- Python fractions.Fraction.__floor__用法及代碼示例
- Python NumPy fliplr方法用法及代碼示例
- Python BeautifulSoup find_next方法用法及代碼示例
- Python functools.wraps用法及代碼示例
- Python NumPy floor方法用法及代碼示例
- Python functools.singledispatchmethod用法及代碼示例
- Python float轉exponential用法及代碼示例
- Python calendar firstweekday()用法及代碼示例
- Python NumPy full方法用法及代碼示例
- Python NumPy flatten方法用法及代碼示例
- Python float.is_integer用法及代碼示例
- Python Django format_lazy用法及代碼示例
- Python format()用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | fromstring method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。