Reputation: 45
I have create a code where it takes numbers from my RangeInKM_Manufacturer
array and subtract which each element in a matrix, and then creates a new matrix, this works good!
Now I want to use this new matrix and divide it by RangeInKM_By_Manufacturer
and then multiply by 100 to get current percentage battery status, how do I do this?
My code:
Electric_car = np.array({'Nissan Leaf 24 kWh pack', 'Nissan Leaf 30 kWh pack', 'Volkswagen e-Golf','Tesla Model S 90(D)','BMW i3 22kWh','BMW i3 33 kWh','KIA SOUL','Volkswagen e-Up(2016)','Renault ZOE R90 Z.E 40','Hyundai IONIQ','Mercedes-Benz B250E','Tesla model X 90D'});
RangeInKM_By_Manufacturer = np.array([199, 250, 300, 557, 190, 300, 250, 160, 403, 280, 200, 489])
City = ['city1', 'city2', 'city3', 'city4', 'city5', 'city6', 'city7', 'city8' , 'city9', 'city10', 'city11','city12', 'city13', 'city14', 'city15', 'city16', 'city17', 'city18', 'city19', 'city20']
distances = [[0, 3.4, 4.5, 4, 5, 12.2, 5.4, 6.1, 5.7, 10.6, 12.8, 7.7, 7.4, 5, 12.4, 12.6, 8.7, 4.2, 3.8, 1.9],
[3.4, 0, 2.2, 2.4, 4.3, 10.1, 2.8, 4.7, 4.5, 9.4, 11.6, 9.4, 9.4, 7.6, 14.6, 11.9, 8.7, 4.3, 4.5, 1.7],
[4.5, 2.1, 0, 1.6, 4.5, 6.8, 1.6, 3.1, 3.8, 8.7, 11, 8.5, 9, 9.4, 17.2, 10.9, 8.1, 3.8, 4.8, 3.4],
[4.1, 2, 1.6, 0, 2.7, 6.3, 1.6, 4.6, 5, 9.9, 12.1, 9.2, 9.4, 8.3, 15.9, 8.8, 9.3, 4.9, 5.2, 2.3],
[5.1, 4.2, 4.5, 2.7, 0, 5.5, 3.5, 9.3, 7.5, 12.4, 14.7, 14.8, 12, 9.6, 15.8, 6.3, 11.8, 7.5, 7.8, 3.3],
[12.2, 10.1, 6.8, 6.3, 5.5, 0, 5.7, 10.7, 12, 17, 19.2, 17, 17.2, 14.5, 21.9, 4.1, 16.3, 12, 14.3, 8.1],
[5.4, 3.4, 1.6, 1.6, 3.5, 5.7, 0, 5.5, 5.8, 10.7, 12.9, 10.8, 10.2, 9.6, 17.2, 9, 10, 5.7, 6, 3.8],
[6.1, 4.7, 3.1, 4.6, 9.3, 10.7, 5.5, 0, 4.1, 9.1, 11.3, 8.8, 10.9, 11.3, 20.8, 13.9, 8.4, 4.1, 6.4, 5.9],
[5.7, 4.5, 3.8, 5, 7.5, 12, 5.8, 4.1, 0, 5.4, 7.7, 5.8, 9.4, 10.3, 17.2, 15.3, 4.8, 2.5, 5.3, 5.9],
[10.6, 9.4, 8.7, 9.9, 12.4, 17, 10.7, 9.1, 5.4, 0, 2.6, 5.2, 10.2, 14.2, 20.5, 19.8, 4.1, 7.3, 9.1, 10.4],
[ 12.8, 11.6, 11, 12.1, 14.7, 19.2, 12.9, 11.3, 7.7, 2.6, 0, 8.6, 13.6, 17.2, 23.6, 22.4, 6.7, 10.7, 11.9, 13],
[ 7.7, 9., 8.5, 9.2, 14.8, 17, 10.8, 8.8, 5.8, 5.2, 8.6, 0, 6.6, 9.9, 17.4, 19.8, 2.3, 5, 6, 9],
[7.4, 9.4, 9, 9.4, 12, 17.2, 10.2, 10.9, 9.4, 10.2, 13.6, 6.6, 0, 5.1, 9.8, 17.8, 7.9, 6.6, 5.3, 9.5],
[5, 7.6, 9.4, 8.3, 9.6, 14.5, 9.6, 11.3, 10.3, 14.2, 17.2, 9.9, 5.1, 0, 8.3, 13.9, 12.1, 8.2, 7.1, 5.7],
[12.4, 14.6, 17.2, 15.9, 15.8, 21.9, 17.2, 20.8, 17.2, 20.5, 23.6, 17.4, 9.8, 8.3, 0, 22.5, 18.2, 14.4, 13.2, 13.1],
[12.6, 11.9, 10.9, 8.8, 6.3, 4.1, 9, 13.9, 15.3, 19.8, 22.4, 19.8, 17.8, 13.9, 22.5, 0, 19.3, 15.1, 17, 9.6],
[8.7, 8.7, 8.1, 9.3, 11.8, 16.3, 10, 8.4, 4.8, 4.1, 6.7, 2.3, 7.9, 12.1, 18.2, 19.3, 0, 6.3, 6.8, 9.9],
[4.2, 4.3, 3.8, 4.9, 7.5, 12, 5.7, 4.1, 2.5, 7.3, 10.7, 5, 6.6, 8.2, 14.4, 15.1, 6.3, 0, 3.2, 5],
[3.8, 4.5, 4.8, 5.2, 7.8, 14.3, 6, 6.4, 5.3, 9.1, 11.9, 6, 5.3, 7.1, 13.2, 17, 6.8, 3.2, 0, 4.8],
[1.9, 1.7, 3.4, 2.3, 3.3, 8.1, 3.8, 5.9, 5.9, 10.4, 13, 9, 9.5, 5.7, 13.1, 9.6, 9.9, 5, 4.8, 0]]
for EV_Start in RangeInKM_By_Manufacturer:
for start_Driving in distances:
Remaining_Range = [EV_Start-start_Driving]
print(Remaining_Range)
I am thinking of create a new matrix called "SoC", and inside here I have something like this: [(Remaining_Range/RangeInKM_By_Manufacturer) * 100]
Am I thinking correct?
Upvotes: 2
Views: 78
Reputation: 6669
If I have understood it correctly, you want to divide Remaining_Range with RangeInKM_By_Manufacture and I will pick up from where you have left.
Your Remaining_Range looks like:
[array([ 487.1, 487.3, 485.6, 486.7, 485.7, 480.9, 485.2, 483.1,
483.1, 478.6, 476. , 480. , 479.5, 483.3, 475.9, 479.4,
479.1, 484. , 484.2, 489. ])]
Since both the arrays you are trying to divide are not equal, let's first get them to a proper format else np.divide throws in errors.
Remaining_Range = np.array(Remaining_Range)
Remaining_Range = Remaining_Range.flatten()
RangeInKM_By_Manufacturer = np.array(RangeInKM_By_Manufacturer)
RangeInKM_By_Manufacturer = np.vstack(RangeInKM_By_Manufacturer)
Now perform the division:
SoC = np.divide(Remaining_Range, RangeInKM_By_Manufacturer)
This gives you values for each value in the Remaining_Range is divided by RangeInKM_By_Manufacturer. For example, 487.1/199, 487.3/199.......489/199. And then the cycle follows with each value from RangeInKM_By_Manufacture.
I am not sure what you mean by percentage but if you simply want to multiply this result by 100, then:
SoC = np.multiply(SoC, 100)
Is this what you expect?
Upvotes: 2