0

I'm using a video processing tool that needs to input the processing data from each frame into an array.

for p in det.read(frame, fac):  

    point_values = np.array([])

    for j, (x, y) in enumerate(p):  #iteration through points
        point_values = np.append(point_values,y)
        point_values = np.append(point_values,x)

this code runs again each frame. I'm expecting "point_values = np.array([])" to reset the array and then start filling it again.

I'm not sure if my logic is wrong or is it a syntax issue.

7
  • What is det, frame, fac, etc? Please add some more details and desired input-output samples. Commented Jun 17, 2018 at 15:28
  • It's really inefficient to make arrays like this. You should use python lists if you're intending to append, or you should instantiate an empty array of fixed size and change those values by index. But numpy arrays are not designed to change size efficiently; this probably runs much slower than a for loop using regular python lists. Commented Jun 17, 2018 at 15:29
  • See this Commented Jun 17, 2018 at 15:37
  • @roganjosh The numpy array is supposed to stay in the same length. only change its values. Commented Jun 17, 2018 at 15:43
  • @J...S p a detection of a face in the image. Frame is the image that is analyzed and fac is data that is not used here but for the detection itself. Commented Jun 17, 2018 at 15:44

1 Answer 1

0

Your code does:

In [77]: p = [(0,0),(0,2),(1,0),(1,2)]
In [78]: arr = np.array([])
In [79]: for j,(x,y) in enumerate(p):
    ...:     arr = np.append(arr,y)
    ...:     arr = np.append(arr,x)
    ...:     
In [80]: arr
Out[80]: array([0., 0., 2., 0., 0., 1., 2., 1.])

No syntax error. The list equivalent is faster and cleaner:

In [85]: alist =[]
In [86]: for x,y in p: alist.extend((y,x))
In [87]: alist
Out[87]: [0, 0, 2, 0, 0, 1, 2, 1]

But you don't give any indication of how this action is supposed to fit within a larger context. You create a new point_values for each p, but then don't do anything with it.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, I'm not a professional programmer so I'm still getting the rights and wrongs of communicating here :) I'm then using np.linalg to get the 136 dimensional point distance between two points: np.linalg.norm(point_num - point_values)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.