Skip to content
Advertisement

How to create a new matrix using MIN and MAX from original array

I have a matrix named A, and I want to create a new matrix named B, where each element value is generated by this formula:

B[i][j] = (A[i][j] - MIN) / (MAX - MIN), where

  • i is the line index
  • j is the column index.
  • MIN is the minimum from A
  • MAX is the value with highest value from A.

I tried a for loop but I want to increase efficiency, I want to use numpy function but I don’t know which function I have to use and how to use this function, with my problem.

Advertisement

Answer

I’m not sure whether the MIN&MAX are standing for

  1. the MIN&MAX value of the column/row from A, or
  2. the MIN&MAX value of the entire matrix(A).

Plz leave a comment if I’m misunderstanding and here’s the solution for second meaning of MIN&MAX.

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement