0

Buenas tengo el siguiente arreglo, y deseo seleccionar el valor máximo y mínimo de dicho arreglo, cómo puedo hacerlo?

ytra01=[array([1.18182126307657e-125, -0.0119506376551417, -0.0238653670087153,
        -0.0357093641553568, -0.0474489881673787, -0.0590517810947708,
        -0.0704864679651997, -0.0817229567840087, -0.0927323385342183,
        -0.103486887176526, -0.113960059649305, -0.124126495868608,
        -0.133962018728162, -0.143443634099373, -0.152549530831321,
        -0.161259080750767, -0.169552838662145, -0.177412542347568,
        -0.184821112566827, -0.191762653057386, -0.198222450534390,
        -0.204186974690659, -0.209643878196690, -0.214581996700658,
        -0.218991348828412, -0.222863136183482, -0.226189743347072,
        -0.228964737878063, -0.231182870313016, -0.232840074166164,
        -0.233933465929421, -0.234461345072376, -0.234423194042295,
        -0.233819678264123, -0.232652646140478, -0.230925129051658,
        -0.228641341355637, -0.225806680388066, -0.222427726462272,
        -0.218512242869262, -0.214069175877715, -0.209108654733991,
        -0.203641991662125, -0.197681681863830, -0.191241403518495,
        -0.184336017783187, -0.176981568792647, -0.169195283659298,
        -0.160995572473234, -0.152402028302231, -0.143435427191739,
        -0.134117728164886, -0.124472073222477, -0.114522787342993,
        -0.104295378482593, -0.0938165375751110, -0.0831141385320608,
        -0.0722172382426312, -0.0611560765736884, -0.0499620763697752,
        -0.0386678434531117, -0.0273071666235948, -0.0159150176587985,
        -0.00452755131397313, 0.00681789467795345, 0.0180827996063767,
        0.0292274597830153, 0.0402109885419106, 0.0509913162394275,
        0.0615251902542539, 0.0717681749874005, 0.0816746518622012,
        0.0911978193243132, 0.100289692841717, 0.108901104904715,
        0.116981705025934, 0.124479959740323, 0.131343152605155,
        0.137517384200026, 0.142947572126853, 0.147577451009879,
        0.151349572495669, 0.154205305253110, 0.156084834973414,
        0.156927164370114, 0.156670113179067, 0.155250318158455,
        0.152603233088780, 0.148663128772868, 0.143363093035869,
        0.136635030725257, 0.128409663710825, 0.118616530884694,
        0.107183988161304, 0.0940392084774217, 0.0791081817921341,
        0.0623157150868521, 0.0435854323653106, 0.0228397746535661,
        -3.25260651745651e-16], dtype=object),
 array([1.18182126307657e-125, -0.0249772674435424, -0.0519907845042112,
        -0.0809050263018950, -0.111586833911836, -0.143905414364630,
        -0.177732340646228, -0.212941551697932, -0.249409352416401,
        -0.287014413653646, -0.325637772217032, -0.365162830869278,
        -0.405475358328457, -0.446463489267996, -0.488017724316676,
        -0.530030930058630, -0.572398339033347, -0.615017549735669,
        -0.657788526615792, -0.700613600079266, -0.743397466486994,
        -0.786047188155233, -0.828472193355595, -0.870584276315045,
        -0.912297597215901, -0.953528682195836, -0.994196423347878,
        -1.03422207872041, -1.07352927231715, -1.11204399409721,
        -1.14969459997501, -1.18641181182037, -1.22212871745841,
        -1.25678077066966, -1.29030579118996, -1.32264396471053,
        -1.35373784287793, -1.38353234329408, -1.41197474951625,
        -1.43901471105707, -1.46460424338452, -1.48869772792194,
        -1.51125191204800, -1.53222590909676, -1.55158119835760,
        -1.56928162507529, -1.58529340044991, -1.59958510163693,
        -1.61212767174716, -1.62289441984676, -1.63186102095725,
        -1.63900551605550, -1.64430831207375, -1.64775218189956,
        -1.64932226437588, -1.64900606430099, -1.64679345242853,
        -1.64267666546750, -1.63665030608224, -1.62871134289246,
        -1.61885911047322, -1.60709530935493, -1.59342400602335,
        -1.57785163291959, -1.56038698844014, -1.54104123693682,
        -1.51982790871680, -1.49676290004262, -1.47186447313217,
        -1.44515325615869, -1.41665224325077, -1.38638679449237,
        -1.35438463592278, -1.32067585953667, -1.28529292328403,
        -1.24827065107025, -1.20964623275603, -1.16945922415744,
        -1.12775154704592, -1.08456748914824, -1.03995370414653,
        -0.993959211678288, -0.946635397336348, -0.898036012668906,
        -0.848217175179511, -0.797237368327065, -0.745157441525825,
        -0.692040610145400, -0.637952455510755, -0.582960924902207,
        -0.527136331555429, -0.470551354661445, -0.413281039366636,
        -0.355402796772732, -0.296996403936824, -0.238144003871350,
        -0.178930105544105, -0.119441583878238, -0.0597676797522508,
        -6.50521303491303e-16], dtype=object)]

deberia arrojarme los valores 0.1569 (maximo) y -1.649 minimo he aplicado esto pero no salen los valores correctos

float(max(ytra01, key = lambda x: x[2])[0])
float(min(ytra01, key = lambda x: x[2])[0])

agradezco su ayuda

1 respuesta 1

1

Con float(max(ytra01, key = lambda x: x[2])[0]) estas obteniendo el array anidado (x) cuyo tercer elemento (x: x[2]) es mayor y luego obtienes el primer elemento de dicho array ([0]), en tu caso 1.18182126307657e-125 en ambos casos.

Si quieres el máximo y mínimo de uno de los subarrays, por ejemplo el segundo deberías simplemente indizar:

>>> max(ytra01[1])
1.18182126307657e-125

Si quieres el máximo y mínimo teniendo en cuenta los valores de todos los subarrays:

>>> max(max(sub) for sub in ytra01)
0.156927164370114

>>> min(min(sub) for sub in ytra01)
-1.64932226437588

No obstante, dado que pareces estar usando NumPy (directa o indirectamente), deberías usar numpy.min y numpy.max:

 >>> import numpy as np

 >>> np.min(ytra01)
 -1.64932226437588

 >>> np.max(ytra01)
 0.156927164370114

Si ytra01 es un array NumPy también puedes simplemente hacer:

>>> ytra01.min()
>>> ytra01.max()

Esto es si quieres el valor mínimo/máximo teniendo en cuenta todos los subarrays, si quieres el valor mínimo teniendo en cuenta solo el segundo, simplemente indexa:

>>> ytra01[1].min()
>>> ytra01[1].max()

Si quieres los valores máximo y mínimo para cada subarray usa numpy.amin y numpy.amax:

>>> np.amax(ytra01, axis=1))
[0.156927164370114 1.18182126307657e-125]

>>> np.amin(ytra01, axis=1))
[-0.234461345072376 -1.64932226437588]

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.