https://docs.scipy.org/doc/numpy/reference/generated/numpy.amax.html
numpy.amax(a, axis=None, out=None, keepdims=<no value>, initial=<no value>, where=<no value>)
Return the maximum of an array or maximum along an axis.
返回数组的最大值或沿轴的最大值。
a : array_like
Input data.
axis : None or int or tuple of ints, optional
Axis or axes along which to operate. By default, flattened input is used.
沿其运行的一个或多个轴。By default, flattened input is used.
If this is a tuple of ints, the maximum is selected over multiple axes, instead of a single axis or all the axes as before.
如果这是一个整数元组,则在多个轴上选择最大值,而不是像以前那样在单个轴或所有轴上进行选择。
out : ndarray, optional
Alternative output array in which to place the result. Must be of the same shape and buffer length as the expected output. See doc.ufuncs (Section “Output arguments”) for more details.
放置结果的替代输出数组。必须具有与预期输出相同的形状和缓冲区长度。See doc.ufuncs (Section “Output arguments”) for more details.
keepdims : bool, optional
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
如果将其设置为 True,则缩小的轴将保留为尺寸 1。With this option, the result will broadcast correctly against the input array.
If the default value is passed, then keepdims will not be passed through to the amax method of sub-classes of ndarray, however any non-default value will be. If the sub-class’ method does not implement keepdims any exceptions will be raised.
如果传递了默认值,则 keepdims 不会传递给 ndarray 子类的 amax 方法,但是任何非默认值都将传递。如果子类的方法未实现 keepdims,则将引发任何异常。
initial : scalar, optional
The minimum value of an output element. Must be present to allow computation on empty slice. See reduce for details.
输出元素的最小值。必须存在以允许在空片上进行计算。See reduce for details.
where : array_like of bool, optional
Elements to compare for the maximum. See reduce for details.
要比较的最大元素。
amax : ndarray or scalar
Maximum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1
.
如果 axis 为 None,则结果为标量值。如果给定 axis,则结果为维度为 a.ndim - 1
的数组。
NaN values are propagated, that is if at least one item is NaN, the corresponding max value will be NaN as well. To ignore NaN values (MATLAB behavior), please use nanmax.
NaN values are propagated,即,如果至少一项是 NaN,则相应的最大值也将是 NaN。要忽略 NaN 值 (MATLAB 行为),请使用 nanmax。
propagate [ˈprɒpəɡeɪt]:vt. 传播,传送,繁殖,宣传 vi. 繁殖,增殖
Don’t use amax for element-wise comparison of 2 arrays; when a.shape[0] is 2, maximum(a[0], a[1]) is faster than amax(a, axis=0).
不要将 amax 用于 2 个数组的逐元素比较。当 a.shape [0] 为 2 时,maximum(a[0], a[1]) 比 amax(a, axis=0) 快。
>>> a = np.arange(4).reshape((2,2))
>>> a
array([[0, 1],
[2, 3]])
>>> np.amax(a) # Maximum of the flattened array
3
>>> np.amax(a, axis=0) # Maxima along the first axis
array([2, 3])
>>> np.amax(a, axis=1) # Maxima along the second axis
array([1, 3])
>>> np.amax(a, where=[False, True], initial=-1, axis=0)
array([-1, 3])
>>> b = np.arange(5, dtype=float)
>>> b[2] = np.NaN
>>> np.amax(b)
nan
>>> np.amax(b, where=~np.isnan(b), initial=-1)
4.0
>>> np.nanmax(b)
4.0
You can use an initial value to compute the maximum of an empty slice, or to initialize it to a different value:
您可以使用初始值来计算空切片的最大值,或将其初始化为其他值:
>>> np.max([[-50], [10]], axis=-1, initial=0)
array([ 0, 10])
Notice that the initial value is used as one of the elements for which the maximum is determined, unlike for the default argument Python’s max function, which is only used for empty iterables.
请注意,初始值用作确定最大值的元素之一,这与默认参数 Python 的 max 函数不同,后者仅用于空的可迭代对象。
>>> np.max([5], initial=6)
6
>>> max([5], default=6)
5
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Yongqiang Cheng
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
current_directory = os.path.dirname(os.path.abspath(__file__))
import numpy as np
# import tensorflow as tf
import cv2
import time
print(16 * "++--")
print("current_directory:", current_directory)
PIXEL_MEAN = [123.68, 116.779, 103.939] # R, G, B. In TensorFlow, channel is RGB. In OpenCV, channel is BGR.
print("Python list")
print("PIXEL_MEAN:", PIXEL_MEAN)
print("type(PIXEL_MEAN):", type(PIXEL_MEAN))
print("type(PIXEL_MEAN[0]):", type(PIXEL_MEAN[0]), "\n")
PIXEL_MEAN_array = np.array(PIXEL_MEAN)
print("NumPy array")
print("PIXEL_MEAN_array:", PIXEL_MEAN_array)
print("type(PIXEL_MEAN_array):", type(PIXEL_MEAN_array))
print("type(PIXEL_MEAN_array[0]):", type(PIXEL_MEAN_array[0]))
print("PIXEL_MEAN_array.dtype:", PIXEL_MEAN_array.dtype, "\n")
image_array = np.array(
[[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], [[21, 22, 23], [24, 25, 26], [27, 28, 29], [30, 31, 32]]])
print("image_array:", image_array)
print("type(image_array):", type(image_array))
print("type(image_array[0]):", type(image_array[0]))
print("image_array.dtype:", image_array.dtype, "\n")
image_array_fusion = image_array + np.array(PIXEL_MEAN)
print("image_array_fusion:", image_array_fusion)
print("type(image_array_fusion):", type(image_array_fusion))
print("type(image_array_fusion[0]):", type(image_array_fusion[0]))
print("image_array_fusion.dtype:", image_array_fusion.dtype, "\n")
image_array_fusion_int64 = image_array_fusion.astype(np.int64)
print("image_array_fusion_int64:", image_array_fusion_int64)
print("type(image_array_fusion_int64):", type(image_array_fusion_int64))
print("type(image_array_fusion_int64[0]):", type(image_array_fusion_int64[0]))
print("image_array_fusion_int64.dtype:", image_array_fusion_int64.dtype, "\n")
image_array_fusion_int32 = image_array_fusion.astype(np.int32)
print("image_array_fusion_int32:", image_array_fusion_int32)
print("type(image_array_fusion_int32):", type(image_array_fusion_int32))
print("type(image_array_fusion_int32[0]):", type(image_array_fusion_int32[0]))
print("image_array_fusion_int32.dtype:", image_array_fusion_int32.dtype, "\n")
image_max = np.max(image_array_fusion)
print("image_max:", image_max)
image_amax = np.amax(image_array_fusion)
print("image_amax:", image_amax)
/usr/bin/python2.7 /home/strong/tensorflow_work/R2CNN_Faster-RCNN_Tensorflow/yongqiang.py --gpu=0
++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--
current_directory: /home/strong/tensorflow_work/R2CNN_Faster-RCNN_Tensorflow
Python list
PIXEL_MEAN: [123.68, 116.779, 103.939]
type(PIXEL_MEAN): <type 'list'>
type(PIXEL_MEAN[0]): <type 'float'>
NumPy array
PIXEL_MEAN_array: [123.68 116.779 103.939]
type(PIXEL_MEAN_array): <type 'numpy.ndarray'>
type(PIXEL_MEAN_array[0]): <type 'numpy.float64'>
PIXEL_MEAN_array.dtype: float64
image_array: [[[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
[[21 22 23]
[24 25 26]
[27 28 29]
[30 31 32]]]
type(image_array): <type 'numpy.ndarray'>
type(image_array[0]): <type 'numpy.ndarray'>
image_array.dtype: int64
image_array_fusion: [[[124.68 118.779 106.939]
[127.68 121.779 109.939]
[130.68 124.779 112.939]
[133.68 127.779 115.939]]
[[144.68 138.779 126.939]
[147.68 141.779 129.939]
[150.68 144.779 132.939]
[153.68 147.779 135.939]]]
type(image_array_fusion): <type 'numpy.ndarray'>
type(image_array_fusion[0]): <type 'numpy.ndarray'>
image_array_fusion.dtype: float64
image_array_fusion_int64: [[[124 118 106]
[127 121 109]
[130 124 112]
[133 127 115]]
[[144 138 126]
[147 141 129]
[150 144 132]
[153 147 135]]]
type(image_array_fusion_int64): <type 'numpy.ndarray'>
type(image_array_fusion_int64[0]): <type 'numpy.ndarray'>
image_array_fusion_int64.dtype: int64
image_array_fusion_int32: [[[124 118 106]
[127 121 109]
[130 124 112]
[133 127 115]]
[[144 138 126]
[147 141 129]
[150 144 132]
[153 147 135]]]
type(image_array_fusion_int32): <type 'numpy.ndarray'>
type(image_array_fusion_int32[0]): <type 'numpy.ndarray'>
image_array_fusion_int32.dtype: int32
image_max: 153.68
image_amax: 153.68
Process finished with exit code 0