in Education by
I have the 4D array, which is defined as follows: B = np.array( [[[[0.5000, 0.5625], [0.5000, 0.5625]], [[1.2500, 0.5000], [0.5625, 0.6875]], [[0.5625, 0.6250], [0.5000, 0.5625]]]] ) I want to take a max of each 2D matrix, such that I get the result of: array([0.5625, 1.250, 0.6250]) Similarly, I want to take the min of each 2D matrix, such that I get the result of: array([0.5000, 0.5000, 0.5000]) However, when doing np.max(B, axis=0), np.max(B, axis=1), np.max(B, axis=2), or np.max(B, axis=3) -- none of these gives a right answer. Is there another argument I need to specify to do this operation? The correct solution should not use any loops and ideally one function call. Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
I think, issue is the misunderstanding of how a axis argument works. For most of these aggregation methods of axis keyword is a axis (or axes) to project along, i.e. these axes are "removed" from a result. So in this case you want to call something like: In [7]: B.max((0, 2, 3)) Out[7]: array([0.5625, 1.25 , 0.625 ]) same thing for min In [8]: B.min((0, 2, 3)) Out[8]: array([0.5, 0.5, 0.5]) Or you can call the numpy method directly In [9]: np.max(B, axis=(0, 2, 3)) Out[9]: array([0.5625, 1.25 , 0.625 ]) Do check out Data Science with Python course which helps you understand from scratch.

Related questions

0 votes
    How do you think I can get the intersection of the below-given array? a=np.array([[[[0,0],[0,1]],[[1,1],[1,1]]] ... , [[0, 1], [1, 1]]] Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    I have an array of the shape (100000, 1) with each element in an array of type positive integer and not ... help would be appreciated. Select the correct answer from above options...
asked Jan 8, 2022 in Education by JackTerrance
0 votes
    I have the pandas data frame with a column designated to town names. After each town name, I am adding a word " ... .csv', index=False) Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have a set of oil wells compiled in the panda's data frame. It looks like this: wells = pd.DataFrame({'date ... -01-01 FIELDZ 10.8 Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I want to save files for each result from the loop. For example, I wrote the code but it only saves one file ... do I modify my code? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have the pandas data frame with the column designated to town names. After each town name, I am adding a word ... .csv', index=False) Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    This is my function: def sub(number): tmp = [] tmp.append(number) while len(str(number)) > 1: tmp.append( ... do this in the python? Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    What are the steps to use shape for a 1D array, 2D array and 3D/ND array respectively in NumPy?...
asked Apr 24, 2021 in Technology by JackTerrance
0 votes
    List the steps to create a 1D array and 2D array in NumPy?...
asked Apr 24, 2021 by JackTerrance
0 votes
    I have a dataset that only contains y-values in one column. I want to insert a column of x- ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I want to encode a 1-D numpy array: x = array([1,0,3]) As a 2-D 1-hot array y = array([ ... some faster technique other than looping. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Suppose I have a Tensorflow tensor. How do I get the dimensions (shape) of the tensor as integer values? I ... 'Dimension' instead. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    While training a tensorflow seq2seq model I see the following messages : W tensorflow/core/common_runtime/gpu/pool_allocator ... GB GPU Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    While training a tensorflow seq2seq model I see the following messages : W tensorflow/core/common_runtime/gpu/pool_allocator ... GB GPU Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    Classification problems, such as logistic regression or multinomial logistic regression, optimize a cross-entropy loss. ... jungle. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
...