-3

I would like to know if there is any way to get a square root to a list?

TypeError: only size-1 arrays can be converted to Python scalars

import math
import numpy as np 

secuencia_1=5
secuencia_2=[7, 2, 4, 8, -1, -6, 5, -3]

ar=np.array(secuencia_2)

r=np.prod((math.sqrt(secuencia_1*secuencia_1)))

g=((ar*ar))      
d=(math.sqrt(ar*ar))    

print(d)
Blorgbeard
  • 101,031
  • 48
  • 228
  • 272

2 Answers2

2

I suppose you want to iterate a function (in this case square root) on a list.

Would recommend using map(function,list)

e.g.

x = [1,2,3,4]
sqr_x = map(math.sqrt,x)

Or if you want to stick with numpy:

See numpy vectorize : https://docs.scipy.org/doc/numpy/reference/generated/numpy.vectorize.html

and/or any of the other answers here : Most efficient way to map function over numpy array

Born Tbe Wasted
  • 610
  • 3
  • 13
0

I think that you're asking: "I want to make a condition in python that uses a square root."

Going off of that, I would point you to the Math library.

Math.sqrt

bobjoe
  • 673
  • 6
  • 11