| ndarray.take
(indices[, axis, out, mode]) | Return an array formed from the elements of a at the given indices. |
| ndarray.put
(indices, values[, mode]) | Set a.flat[n] = values[n]
for all n in indices. |
| ndarray.repeat
(repeats[, axis]) | Repeat elements of an array. |
| ndarray.choose
(choices[, out, mode]) | Use an index array to construct a new array from a set of choices. |
| ndarray.sort
([axis, kind, order]) | Sort an array in-place. |
| ndarray.argsort
([axis, kind, order]) | Returns the indices that would sort this array. |
| ndarray.partition
(kth[, axis, kind, order]) | Rearranges the elements in the array in such a way that the value of the element in kth position is in the position it would be in a sorted array. |
| ndarray.argpartition
(kth[, axis, kind, order]) | Returns the indices that would partition this array. |
| ndarray.searchsorted
(v[, side, sorter]) | Find indices where elements of v should be inserted in a to maintain order. |
| ndarray.nonzero
() | Return the indices of the elements that are non-zero. |
| ndarray.compress
(condition[, axis, out]) | Return selected slices of this array along given axis. |
| ndarray.diagonal
([offset, axis1, axis2]) | Return specified diagonals. |
| ndarray.max
([axis, out, keepdims, initial, …]) | Return the maximum along a given axis. |
| ndarray.argmax
([axis, out]) | Return indices of the maximum values along the given axis. |
| ndarray.min
([axis, out, keepdims, initial, …]) | Return the minimum along a given axis. |
| ndarray.argmin
([axis, out]) | Return indices of the minimum values along the given axis of a. |
| ndarray.ptp
([axis, out, keepdims]) | Peak to peak (maximum - minimum) value along a given axis. |
| ndarray.clip
([min, max, out]) | Return an array whose values are limited to [min, max]
. |
| ndarray.conj
() | Complex-conjugate all elements. |
| ndarray.round
([decimals, out]) | Return a with each element rounded to the given number of decimals. |
| ndarray.trace
([offset, axis1, axis2, dtype, out]) | Return the sum along diagonals of the array. |
| ndarray.sum
([axis, dtype, out, keepdims, …]) | Return the sum of the array elements over the given axis. |
| ndarray.cumsum
([axis, dtype, out]) | Return the cumulative sum of the elements along the given axis. |
| ndarray.mean
([axis, dtype, out, keepdims]) | Returns the average of the array elements along given axis. |
| ndarray.var
([axis, dtype, out, ddof, keepdims]) | Returns the variance of the array elements, along given axis. |
| ndarray.std
([axis, dtype, out, ddof, keepdims]) | Returns the standard deviation of the array elements along given axis. |
| ndarray.prod
([axis, dtype, out, keepdims, …]) | Return the product of the array elements over the given axis |
| ndarray.cumprod
([axis, dtype, out]) | Return the cumulative product of the elements along the given axis. |
| ndarray.all
([axis, out, keepdims]) | Returns True if all elements evaluate to True. |
| ndarray.any
([axis, out, keepdims]) | Returns True if any of the elements of a evaluate to True. |
put 与 take函数
#函数中参数axis的意义就是对应的维度
#看下面的例子
import numpy as np
array = np.random.randint(10,size=(3,3,3))
print(array)
[[[2 2 6]
[0 5 7]
[5 7 0]]
[[7 4 4]
[0 5 8]
[5 6 4]]
[[2 8 4]
[6 0 4]
[1 9 3]]]
print(array.sum(axis=0))
[[11 14 14]
[ 6 10 19]
[11 22 7]]
print(array.sum(axis=1))
print(array.sum(axis=2))
[[ 7 14 13]
[12 15 16]
[ 9 17 11]]
[[10 12 12]
[15 13 15]
[14 10 13]]
# take 函数从数组中取数
print(array)
print(array.take(1)) #先把数组变成一维在取数
print(array.take([1,1]))
[[[2 2 6]
[0 5 7]
[5 7 0]]
[[7 4 4]
[0 5 8]
[5 6 4]]
[[2 8 4]
[6 0 4]
[1 9 3]]]
2
[2 2]
print(array.take([[1,1],[2,2]])) #把数组变成一维然后取数
print(array.take([[1,1],[2,2]],axis=None))
[[2 2]
[6 6]]
[[2 2]
[6 6]]
print(array.take([[1,1],[2,2]],axis=0))#按第一个维度取然后构成新数组
print(array.take([[1,1],[2,2]],axis=1))
print(array.take([[1,1],[2,2]],axis=2))
[[[[7 4 4]
[0 5 8]
[5 6 4]]
[[7 4 4]
[0 5 8]
[5 6 4]]]
[[[2 8 4]
[6 0 4]
[1 9 3]]
[[2 8 4]
[6 0 4]
[1 9 3]]]]
[[[[0 5 7]
[0 5 7]]
[[5 7 0]
[5 7 0]]]
[[[0 5 8]
[0 5 8]]
[[5 6 4]
[5 6 4]]]
[[[6 0 4]
[6 0 4]]
[[1 9 3]
[1 9 3]]]]
[[[[2 2]
[6 6]]
[[5 5]
[7 7]]
[[7 7]
[0 0]]]
[[[4 4]
[4 4]]
[[5 5]
[8 8]]
[[6 6]
[4 4]]]
[[[8 8]
[4 4]]
[[0 0]
[4 4]]
[[9 9]
[3 3]]]]
#ndarray.put(indices, values, mode='raise')
#put函数先调用了flat转换成一维数组
print ( array )
array.put( ( 1, 2, 3 ), ( 11, 12, 13, 14) ) #根据indices中对应下标,到values中取值,用来修改数组中对应位置的值
print ( array )
[[[ 2 11 12]
[13 5 7]
[ 5 7 0]]
[[ 7 4 4]
[ 0 5 8]
[ 5 6 4]]
[[ 2 8 4]
[ 6 0 4]
[ 1 9 3]]]
[[[ 2 11 12]
[13 5 7]
[ 5 7 0]]
[[ 7 4 4]
[ 0 5 8]
[ 5 6 4]]
[[ 2 8 4]
[ 6 0 4]
[ 1 9 3]]]
sort,argsort,searchsorted
#ndarray.sort(axis=-1, kind='quicksort', order=None)
matrix = np.random.randint(10,size=(3,4))
print(matrix)
[[0 5 5 1]
[8 4 6 0]
[4 4 6 7]]
matrix.sort() #axis默认为1按行排序
print(matrix)
[[0 1 5 5]
[0 4 6 8]
[4 4 6 7]]
matrix.sort(axis=0) #列排序
print(matrix)
[[0 1 5 5]
[0 4 6 7]
[4 4 6 8]]
#ndarray.argsort(axis=-1, kind='quicksort', order=None) 返回排序的下标
print ( matrix )
print ( matrix.argsort ( ) ) #默认按照axis=1排序(每行排序)
print ( matrix )
print ( matrix.argsort ( axis = 0 ) ) #按照axis = 0排序(每列排序)
print ( matrix )
[[0 1 5 5]
[0 4 6 7]
[4 4 6 8]]
[[0 1 2 3]
[0 1 2 3]
[0 1 2 3]]
[[0 1 5 5]
[0 4 6 7]
[4 4 6 8]]
[[0 0 0 0]
[1 1 1 1]
[2 2 2 2]]
[[0 1 5 5]
[0 4 6 7]
[4 4 6 8]]
#ndarray.searchsorted(v, side='left', sorter=None) #找出v应该排序的位置
m = np.array ( [
[ 5, 3, 8, 4, 2 ],
[ 7, 1, 6, 9, 3 ],
[ 8, 2, 6, 3, 7]
] )
#print ( m.searchsorted ( 5 , sorter=m.argsort( ) ) ) # 只作用于1-D数组
m=np.array( [ 1,2,5,6,9] )
print ( m.searchsorted ( 8 ) ) #返回8在m数组排序应该在对的位置,只对有序作用
m=np.array( [ 2, 5, 4, 9, 7 ] )
print ( m.searchsorted ( 8 ) ) #对无序可以运行,意义不大
print ( m.searchsorted ( 8 , sorter=m.argsort( ) ) ) #先排序在search
4
5
4
repeat函数
#ndarray.repeat(repeatnum, axis=None) #按照指定axis维度复制指定次数
m = np.array ( [
[ 5, 3, 8 ],
[ 7, 1, 6 ],
[ 8, 2, 6 ]
] )
print ( m.repeat ( 2 ) ) #复制2次,没有指定在哪个维度先flat,再复制
print ( m.repeat ( 2 ,axis = 0) ) #按照行复制2次
print ( m.repeat ( 2 ,axis = 1) ) #按照列复制两次
[5 5 3 3 8 8 7 7 1 1 6 6 8 8 2 2 6 6]
[[5 3 8]
[5 3 8]
[7 1 6]
[7 1 6]
[8 2 6]
[8 2 6]]
[[5 5 3 3 8 8]
[7 7 1 1 6 6]
[8 8 2 2 6 6]]
#ndarray.choose(choices, out=None, mode='raise') #把数组当做下标。从choices中取对应的值。
m = np.array ( [ #索引
[ 1, 2, 3 ],
[ 3, 2, 1 ],
[ 2, 2, 3 ]
] )
#print ( m.choose ( [ -1, -2, -3, -4, -5 ] ) ) #被选的值
print(m.choose([1,2,3,4]))
[[2 3 4]
[4 3 2]
[3 3 4]]
# ndarray.nonzero() 返回非零元素的下标索引
m = np.array ( [
[ 1, 1, 3 ],
[ 1, 0, 0 ],
[ 2, 2, 0 ]
] )
print ( m )返回非零的下标
print ( m.nonzero( ) ) #。返回两个数组,一个按照行,一个按照列,行列对应形成非零的下标
[[1 1 3]
[1 0 0]
[2 2 0]]
(array([0, 0, 0, 1, 2, 2], dtype=int64), array([0, 1, 2, 0, 0, 1], dtype=int64))
#ndarray.compress(condition, axis=None, out=None)
#返回按照axis维度的切片,条件是1-D布尔数组
m = np.array ( [
[ 1, 0, 3 ],
[ 4, 2, 0 ],
[ 2, 2, 0 ]
] )
print ( m.compress ( [False , True, False, True ] ) ) #按照条件返回元素axis=None,等于先flat再操作
print ( m.compress ( [True , False, True ], axis = 1 ) ) #对行切片
print( m.compress ( [True , False, True],axis = 0 )) #对列切
[0 4]
[[1 3]
[4 0]
[2 0]]
[[1 0 3]
[2 2 0]]
# partition函数的用法
#建设我们想找出一个二维数组列中第二小的元素
#有下面两种方法
n = np.random.randint(10,size=(4,6))
print(n)
print(n[1])
[[3 9 0 1 9 0]
[1 0 0 7 7 4]
[8 7 6 3 4 5]
[7 3 6 9 7 1]]
[1 0 0 7 7 4]
r1 = np.sort(n,axis=0) #按列进行排序
print(r1)
print(r1[1]) #用sort方法进行排序之后在输出每列第二小的元素
n.partition(1,axis=0) #将每列中元素第二大的元素放在每列索引为1的位置
print(n)
print(n[1]) #按顺序输出每列中第二小的元素
[[1 0 0 1 4 0]
[3 3 0 3 7 1]
[7 7 6 7 7 4]
[8 9 6 9 9 5]]
[3 3 0 3 7 1]
[[1 0 0 1 4 0]
[3 3 0 3 7 1]
[8 7 6 7 9 5]
[7 9 6 9 7 4]]
[3 3 0 3 7 1]
有人肯定会问既然用sort排序就可以得到结果为什么还要多此一举用partition嘞?
原因就在于在数组的元素很多的时候partition要比sort快的多因为sort要对
所有元素排序但是partition有点类似于快排只要找出第而小的位置放在与sort升序
排列对应的索引位置其他的元素比第二小元素小的放在其索引之前大的放在之后
且其他的元素并不关系没有按照顺序排列如用sort和partition之后的数组中比较其
最后一列,sort的为0145顺序排列,partition的为0154没有顺序
#ndarray.argpartition(kth, axis=-1, kind='introselect', order=None)
#返回下标
m = np.array ( [ 5, 2, 7, 1, 8, 3, 4, 6 ] )
print ( m.argpartition ( 1 ) ) #找出第二大的数据,放在索引为1的位置,其他元素小的放前面,大的放后面
print(m.argpartition(2))
[3 1 2 0 4 5 6 7]
[3 1 5 0 4 2 6 7]
数组的计算处理
#ndarray.argmax(axis=None, out=None) 返回最大值下标
m = np.array ( [ 5, 8, 7, 1, 8, 3, 4, 6 ] )
print ( m.argmax ( ) ) #只返回第一个最大值下标
#ndarray.max(axis=None, out=None) 返回最大值下标
print ( m.max ( ) )
m = np.array ( [
[ 1, 4, 3, 6 ],
[ 4, 2, 1, 0 ],
[ 2, 7, 4, 1 ]
] )
print ( m.argmax ( ) ) #先flat后下标
print ( m.max ( ) )
print ( m.max ( axis = 0 ) ) #每列最大值
print ( m.max ( axis = 1 ) ) #每行最大值
1
8
9
7
[4 7 4 6]
[6 4 7]
#ndarray.sum(axis=None, dtype=None, out=None, keepdims=False) #求和
m = np.array ( [
[ 1, 4, 3, 6 ],
[ 4, 2, 1, 0 ],
[ 2, 7, 4, 1 ]
] )
print ( m.sum ( ) )
print ( m.sum ( keepdims = True ) ) #保持维度
print ( m.sum ( dtype = np.float32 ) )
print ( m.sum ( axis = 0 ) ) #每列想加
print ( m.sum ( axis = 0, keepdims = True ) )
35
[[35]]
35.0
[ 7 13 8 7]
[[ 7 13 8 7]]
#ndarray.cumsum(axis=None, dtype=None, out=None) #累加和
m = np.array ( [
[ 1, 4, 3, 6 ],
[ 4, 2, 1, 0 ],
[ 2, 7, 4, 1 ]
] )
print ( m.cumsum ( ) )
print ( m.cumsum ( dtype = np.float32 ) )
print ( m.cumsum ( axis = 0 ) ) #按列累加
[ 1 5 8 14 18 20 21 21 23 30 34 35]
[ 1. 5. 8. 14. 18. 20. 21. 21. 23. 30. 34. 35.]
[[ 1 4 3 6]
[ 5 6 4 6]
[ 7 13 8 7]]
#ndarray.trace(offset=0, axis1=0, axis2=1, dtype=None, out=None)
# 返回对角线的和
m = np.array ( [
[ 1, 4, 3, 6 ],
[ 4, 2, 1, 0 ],
[ 2, 7, 4, 1 ]
] )
print ( m.trace ( ) ) #对角线1,2,4 (偏移为0 )的和
print ( m.trace ( offset = 1 ) ) #对角线4,1,1
print(m.trace(offset=-1)) #对角线4 7
print ( m.trace ( offset = 1,axis1 = 1, axis2 = 0 ) ) #对角线4,7(偏移为1, 列的偏移为O)的和
print(m.T )
print(m.T.trace(offset=1))
7
6
11
11
[[1 4 2]
[4 2 7]
[3 1 4]
[6 0 1]]
11
# ndarray.mean(axis=None, dtype=None, out=None, keepdims=False)
# 求均值
m = np.array ( [
[ 1, 4, 3, 6 ],
[ 4, 2, 1, 0 ],
[ 2, 7, 4, 1 ]
] )
print ( m.mean ( ) ) #全部元素的平均值
print ( m.mean ( dtype = np.int32) ) #全部元素的平均值
print ( m.mean ( keepdims = True) ) #全部元素的平均值
print ( m.mean ( axis = 0 ) ) #行的平均值(行想加,除以行数)
print ( m.mean ( axis = (0,1) ) ) #行列的平均值
2.9166666666666665
2
[[2.91666667]]
[2.33333333 4.33333333 2.66666667 2.33333333]
2.9166666666666665
#ndarray.var(axis=None, dtype=None, out=None, ddof=0, keepdims=False)
#标准方差
m = np.array ( [
[ 1, 4, 3, 6 ],
[ 4, 2, 1, 0 ],
[ 2, 7, 4, 1 ]
] )
print ( m.var ( ) )
#下面是等价计算方式
mn=m.mean ( ) # 样本平均值
#print ( mn )
m=m-mn #计算均值离差
#print ( m )
m=m*m #离差的平方
#print ( m ) #差的平方的均值
print ( m.mean ( ) )
4.243055555555556
4.243055555555556
#ndarray.std(axis=None, dtype=None, out=None, ddof=0, keepdims=False)
#标准偏差
m = np.array ( [
[ 1, 4, 3, 6 ],
[ 4, 2, 1, 0 ],
[ 2, 7, 4, 1 ]
] )
print ( m.std ( ) )
# 下面是标准偏差的计算方式
print ( np.sqrt ( m.var ( ) ) ) #方差开根号
2.0598678490513795
2.0598678490513795
#ndarray.var(axis=None, dtype=None, out=None, ddof=0, keepdims=False)
m = np.array ( [
[ 1, 4, 3, 6 ],
[ 4, 2, 1, 0 ],
[ 2, 7, 4, 1 ]
] )
print ( m.var ( axis = 0 ) )
#输出每列的方差列表
print ( [ m [ : , 0 ].var ( ), m [ : , 1 ].var ( ), m [ : , 2 ].var ( ), m [ : , 3 ].var ( ) ] )
[1.55555556 4.22222222 1.55555556 6.88888889]
[1.5555555555555556, 4.222222222222222, 1.5555555555555554, 6.888888888888889]
m = np.array ( [
[ 1, 4, 3, 6 ],
[ 4, 2, 1, 0 ],
[ 2, 7, 4, 1 ]
] )
print ( m.var ( ddof = 1 ) ) #无偏方差 ,按公式比有偏大
print ( m.var ( ddof = 0 ) ) #有偏方差
print ( m.var ( ) )
4.628787878787879
4.243055555555556
4.243055555555556
# ndarray.prod(axis=None, dtype=None, out=None, keepdims=False)
m = np.array ( [
[ 1, 4, 3, 6 ],
[ 4, 2, 1, 3 ],
[ 2, 7, 4, 1 ]
] )
print ( m.prod ( ) ) #全部累乘
96768
print(m.cumprod()) #累乘列表
[ 1 4 12 72 288 576 576 1728 3456 24192 96768 96768]
#ndarray.all(axis=None, out=None, keepdims=False)
m = np.array ( [
[ 1, 4, 0, 6 ],
[ 4, 2, 1, 3 ],
[ 2, 7, 4, 1 ]
] )
print (a m.all ( ) ) #all elements is true return true
False
print(m.any()) # a element is true return true
True
#ndarray.diagonal(offset=0, axis1=0, axis2=1) 按照坐标轴axis1与axis2返回对角线,返回的是1-D数组
m = np.array ( [
[ 1, 0, 3 ],
[ 4, 2, 0 ],
[ 2, 2, 0 ]
] )
print ( m.diagonal ( ) )
print ( m.diagonal (1 ) )
print ( m.diagonal (1, axis1 = 1, axis2 = 0) ) #下三角对角
[1 2 0]
[0 0]
[4 2]
m = np.array ( [
[ 1, 4, 3, 6 ],
[ 4, 2, 1, 3 ],
[ 2, 7, 4, 1 ]
] )
x = np.array ( [1,2,3,4] )
print ( m @ x)
# print ( x @ m) 不满足内积的条件行不等于列
y = np.array ( [1,2,3] )
print ( y @ m)
[42 23 32]
[15 29 17 15]
其他运算符
<colgroup><col width="10%"><col width="90%"></colgroup>
| ndarray.__lt__
(self, value, /) | Return self<value. |
| ndarray.__le__
(self, value, /) | Return self<=value. |
| ndarray.__gt__
(self, value, /) | Return self>value. |
| ndarray.__ge__
(self, value, /) | Return self>=value. |
| ndarray.__eq__
(self, value, /) | Return self==value. |
| ndarray.__ne__
(self, value, /) | Return self!=value. |
Truth value of an array (bool
):
<colgroup><col width="10%"><col width="90%"></colgroup>
| ndarray.__bool__
(self, /) | self != 0 |
Note
Truth-value testing of an array invokes ndarray.__bool__
, which raises an error if the number of elements in the array is larger than 1, because the truth value of such arrays is ambiguous. Use .any()
and .all()
instead to be clear about what is meant in such cases. (If the number of elements is 0, the array evaluates to False
.)
Unary operations:
<colgroup><col width="10%"><col width="90%"></colgroup>
| ndarray.__neg__
(self, /) | -self |
| ndarray.__pos__
(self, /) | +self |
| ndarray.__abs__
(self) | |
| ndarray.__invert__
(self, /) | ~self |
Arithmetic:
<colgroup><col width="10%"><col width="90%"></colgroup>
| ndarray.__add__
(self, value, /) | Return self+value. |
| ndarray.__sub__
(self, value, /) | Return self-value. |
| ndarray.__mul__
(self, value, /) | Return self*value. |
| ndarray.__truediv__
(self, value, /) | Return self/value. |
| ndarray.__floordiv__
(self, value, /) | Return self//value. |
| ndarray.__mod__
(self, value, /) | Return self%value. |
| ndarray.__divmod__
(self, value, /) | Return divmod(self, value). |
| ndarray.__pow__
(self, value[, mod]) | Return pow(self, value, mod). |
| ndarray.__lshift__
(self, value, /) | Return self<<value. |
| ndarray.__rshift__
(self, value, /) | Return self>>value. |
| ndarray.__and__
(self, value, /) | Return self&value. |
| ndarray.__or__
(self, value, /) | Return self|value. |
| ndarray.__xor__
(self, value, /) | Return self^value. |
Note
- Any third argument to
pow
is silently ignored, as the underlyingufunc
takes only two arguments. - The three division operators are all defined;
div
is active by default,truediv
is active when__future__
division is in effect. - Because
ndarray
is a built-in type (written in C), the__r{op}__
special methods are not directly defined. - The functions called to implement many arithmetic special methods for arrays can be modified using
__array_ufunc__
.
Arithmetic, in-place:
<colgroup><col width="10%"><col width="90%"></colgroup>
| ndarray.__iadd__
(self, value, /) | Return self+=value. |
| ndarray.__isub__
(self, value, /) | Return self-=value. |
| ndarray.__imul__
(self, value, /) | Return self=value. |
| ndarray.__itruediv__
(self, value, /) | Return self/=value. |
| ndarray.__ifloordiv__
(self, value, /) | Return self//=value. |
| ndarray.__imod__
(self, value, /) | Return self%=value. |
| ndarray.__ipow__
(self, value, /) | Return self*=value. |
| ndarray.__ilshift__
(self, value, /) | Return self<<=value. |
| ndarray.__irshift__
(self, value, /) | Return self>>=value. |
| ndarray.__iand__
(self, value, /) | Return self&=value. |
| ndarray.__ior__
(self, value, /) | Return self|=value. |
| ndarray.__ixor__
(self, value, /) | Return self^=value. |
Warning
In place operations will perform the calculation using the precision decided by the data type of the two operands, but will silently downcast the result (if necessary) so it can fit back into the array. Therefore, for mixed precision calculations, A {op}= B
can be different than A = A {op} B
. For example, suppose a = ones((3,3))
. Then, a += 3j
is different than a = a + 3j
: while they both perform the same computation, a += 3
casts the result to fit back in a
, whereas a = a + 3j
re-binds the name a
to the result.
Matrix Multiplication:
<colgroup><col width="10%"><col width="90%"></colgroup>
| ndarray.__matmul__
(self, value, /) | Return self@value. |
Note
Matrix operators @
and @=
were introduced in Python 3.5 following PEP465. NumPy 1.10.0 has a preliminary implementation of @
for testing purposes. Further documentation can be found in the matmul
documentation.
Special methods
For standard library functions:
<colgroup><col width="10%"><col width="90%"></colgroup>
| ndarray.__copy__
() | Used if copy.copy
is called on an array. |
| ndarray.__deepcopy__
() | Used if copy.deepcopy
is called on an array. |
| ndarray.__reduce__
() | For pickling. |
| ndarray.__setstate__
(state, /) | For unpickling. |
Basic customization:
<colgroup><col width="10%"><col width="90%"></colgroup>
| ndarray.__new__
(*args, **kwargs) | Create and return a new object. |
| ndarray.__array__
() | Returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array. |
| ndarray.__array_wrap__
() | |
Container customization: (see Indexing)
<colgroup><col width="10%"><col width="90%"></colgroup>
| ndarray.__len__
(self, /) | Return len(self). |
| ndarray.__getitem__
(self, key, /) | Return self[key]. |
| ndarray.__setitem__
(self, key, value, /) | Set self[key] to value. |
| ndarray.__contains__
(self, key, /) | Return key in self. |
Conversion; the operations int
, float
and complex
. . They work only on arrays that have one element in them and return the appropriate scalar.
<colgroup><col width="10%"><col width="90%"></colgroup>
| ndarray.__int__
(self) | |
| ndarray.__float__
(self) | |
| ndarray.__complex__
() | |
String representations:
<colgroup><col width="10%"><col width="90%"></colgroup>
| ndarray.__str__
(self, /) | Return str(self). |
| ndarray.__repr__
(self, /) | Return repr(self). |
代码下载地址:
【https://github.com/luozekun1230/MyPyhonAIprogram/tree/master/Python%E5%9F%BA%E7%A1%80】
python函数很多忘了的时候要学会随时查看文档
网友评论