接着上篇博文更新
Numpy进阶之字符串操作
字符串操作 | 描述 |
---|---|
add() | 返回两个str或Unicode数组的逐个字符串连接 |
multiply() | 返回按元素多重连接后的字符串 |
center() | 返回给定字符串的副本,其中元素位于特定字符串的中央 |
capitalize() | 返回给定字符串的副本,其中只有第一个字符串大写 |
title() | 返回字符串或Unicode的元素标题转换版本 |
lower() | 返回一个数组,其元素转换为小写 |
upper() | 返回一个数组,其元素转换为大写 |
split() | 返回字符串的单词列表,并使用分隔符来分割 |
splitlines() | 返回元素中的行列表,以换行符分割 |
strip() | 返回数组副本,其中元素移除了开头或结尾处的特定字符 |
join() | 返回一个字符串,它是序列中字符串的连接 |
replace() | 返回字符串的副本,其中所有子字符串的出现位置都被新字符串取代 |
decode() | 按元素调用str.decode |
encode() | 按元素调用str.encode |
举例说明几个
- add()
>>>a = 'hi'
>>>b = 'world'
>>>c = np.char.add(a,b)
>>>print(c)
>hiworld
- split() 与splitlines()
>>>a = 'hi#how#what#who'
>>>b = np.char.split(a,'#')
>>>print(b)
>['hi', 'how', 'what', 'who']
>>>a = 'hi\nhow\nwhat\nwho'
>>>b = np.char.splitlines(a) #只打印换行符分割
>>>print(b)
>['hi', 'how', 'what', 'who']
- strip()
>>>a = 'bahello bubble'
>>>b = np.char.strip(a,'b')
>>>print(b)
>ahello bubble
- join()
>>>a = 'hello'
>>>b = np.char.join('-',a)
>>>print(b)
>h-e-l-l-o
- replace()
>>>a = 'she is a good girl'
>>>b = np.char.replace(a,'good','beautiful')
>>>print(b)
>she is a beautiful girl
- capitalize()
>>>a = 'hello world'
>>>b = np.char.capitalize(a)
>>>print(b)
>Hello world
- title()
>>>a = 'hello world'
>>>b = np.char.title(a)
>>>print(b)
>Hello World
Numpy还有一些数学函数
-
Numpy高级之数学算术函数
三角函数:sin \ cos \ tan
反三角函数:arcsin \ arccos \ arctan
舍入函数:floor(向下取整) \ ceil(向上取整)
算术运算:add \ subract \ mutiply \ divide -
Numpy高级之数学算数运算
算数运算:reciprocal(返回参数逐元素的倒数) \ power(幂函数) \ mod(取模)
复数运算:real(复数实部) \ imag(复数虚部) \ conj(共轭复数) \ angle(复数参数的角度) -
Numpy高级之数学统计函数
统计函数:amin \ amax \ ptp \ median \ mean \ average \ std \ var -
Numpy高级之其他函数
其他函数:sort \ argmax \ agrmin \ where \ extract -
Numpy高级之矩阵库
矩阵库:
np.matlib.empty
np.matlib.zeros
np.matlib.ones
np.matlib.eye
np.matlib.identity
np.matlib.rand -
Numpy高级之线性代数
线性代数:dot(两个数组的点积) \ vdot(两个向量的点积) \ inner(两个数组的内积) \ matmul(两个数组的矩阵积)
这篇博文讲了一些大概可能会用到的函数,下篇博文主要将Numpy的函数库,如果上述函数有不懂的,可以去Numpy官网看看。