Arun Sivaraj
Arun Sivaraj

Reputation: 91

How to merge two arrays into one and find the biggest value from it in python?

I have two arrays

array1 = [400,723,433,509,345,232,654]
array2 = [105,200,330,390,400,420,500]

How to merge these two arrays into one and find the biggest value from array1 and its corresponding value from array2. From the above two arrays, i am expecting the output as [723, 200].

Here is the actual array value: array1 = ['10425', '450', '75', '75', '55725', '75', '1575', '150', '583200', '1725', '1200', '1200', '300', '600', '191025', '6750', '75', '25575', '17400', '525', '9750', '75', '461400', '3900', '72150', '2850', '39825', '750', '53325', '2100', '67800', '5625', '670500', '3600', '167625', '6450', '141450', '2550', '138825', '10050', '70725', '4725', '1484400', '7425', '134325', '7875', '335325', '9525', '213825', '6750', '180750', '4500', '1362225', '3450', '278775', '315300', '1275', '336825', '156600', '3075', '1616025', '3525', '99375', '75', '179100', '75', '70950', '63300', '865050', '129900', '115275', '125625', '65400', '1362825', '61950', '106875', '1425', '63300', '86475', '849675', '84600', '90750', '124200', '79650', '766200', '47325', '32325', '31500', '59025', '300000', '4350', '35625', '11700', '5625', '19425', '9000', '190725', '6975', '825', '138600', '2925']

array2 = ['6100.0', '6200.0', '6300.0', '6400.0', '6500.0', '6750.0', '6800.0', '6900.0', '7000.0', '7100.0', '7200.0', '7300.0', '7400.0', '7450.0', '7500.0', '7600.0', '7650.0', '7700.0', '7800.0', '7850.0', '7900.0', '7950.0', '8000.0', '8050.0', '8100.0', '8150.0', '8200.0', '8250.0', '8300.0', '8350.0', '8400.0', '8450.0', '8500.0', '8550.0', '8600.0', '8650.0', '8700.0', '8750.0', '8800.0', '8850.0', '8900.0', '8950.0', '9000.0', '9050.0', '9100.0', '9150.0', '9200.0', '9250.0', '9300.0', '9350.0', '9400.0', '9450.0', '9500.0', '9550.0', '9600.0', '9700.0', '9750.0', '9800.0', '9900.0', '9950.0', '10000.0', '10050.0', '10100.0', '10150.0', '10200.0', '10250.0', '10300.0', '10400.0', '10500.0', '10600.0', '10700.0', '10800.0', '10900.0', '11000.0', '11100.0', '11200.0', '11250.0', '11300.0', '11400.0', '11500.0', '11600.0', '11700.0', '11800.0', '11900.0', '12000.0', '12100.0', '12200.0', '12300.0', '12400.0', '12500.0', '12550.0', '12600.0', '12700.0', '12750.0', '12800.0', '12900.0', '13000.0', '13100.0', '13300.0', '13500.0', '13700.0']

Upvotes: 0

Views: 456

Answers (3)

rdas
rdas

Reputation: 21275

Try this:

array1 = [float(x) for x in array1]
array2 = [float(x) for x in array2]

array1 = [400,723,433,509,345,232,654]
array2 = [105,200,330,390,400,420,500]

max_in_1 = max(array1)
print([max_in_1, array2[array1.index(max_in_1)]])

Output:

[723, 200]

Upvotes: 1

RoadRunner
RoadRunner

Reputation: 26315

I don't see why you need to merge the arrays. Just zip them and get the max, which will hold both corresponding values inside a tuple.

>>> array1 = [400,723,433,509,345,232,654]
>>> array2 = [105,200,330,390,400,420,500]
>>> max(zip(array1, array2))
(723, 200)

If you want the final result as a list, then you can do this:

>>> list(max(zip(array1, array2)))
[723, 200]

Also those are not arrays, they are lists.

Upvotes: 0

rn0mandap
rn0mandap

Reputation: 333

here it is

idx = array1.index(max(array1))
output = [array1[idx], array2[idx]]
mergedarrays = array1 + array2

Upvotes: 2

Related Questions