0
x=np.array([1, 2, 3])
v=np.array([1,0,0])

delta=0.001
xp=x+v*delta
xm=x-v*delta

I have seen various threads asking the same question, but none of them resolves my problem. Particularly, this link: Why do I get TypeError: can't multiply sequence by non-int of type 'float'? was relevant, but I still get the same error while calculating xp and xm. I want to multiply delta by the entire array (as is obvious). Numpy arrays are a solution to this, as I saw in other threads, but I can't discern why my code isn't working. Any help will be appreciated.

Asad Raza
  • 1
  • 5
  • 1
    Your code seems to work fine – sacuL Jun 09 '18 at 12:01
  • It's working without error in my environment. – CrazyElf Jun 09 '18 at 12:01
  • @sacul Me to, it works perfectly fine for me, no error – U13-Forward Jun 09 '18 at 12:02
  • I see this error only if I remove np.array constructors and do calculations with python lists. – CrazyElf Jun 09 '18 at 12:03
  • But your calculation relies on them being numpy arrays. Your question suggests that the error can be replicated with the code you've posted, but it cannot. Numpy arrays support array programming, python lists do not; what's wrong with the numpy approach? – roganjosh Jun 09 '18 at 12:34
  • And actually, if you did provide an integer (as the error indicates), it will not do what you expect. You would have to use a `for` loop. The numpy approach is both intuitive and probably hundreds of times faster; that's the whole purpose of the library. – roganjosh Jun 09 '18 at 12:45

0 Answers0