When I try to get the right and left columns from the matrix

import numpy as np def createSystem(pts2d,pts3d): pts2d = np.array[[1.0486, -0.3645], [-1.6851, -0.4004], [-0.9437, -0.42], [1.0682, 0.0699], [0.6077, -0.0771], [1.2543, -0.6454], [-0.2709, 0.8635], [-0.4571, -0.3645], [-0.7902, 0.0307], [0.7318, 0.6382], [-1.058, 0.3312], [0.3464, 0.3377], [0.3137, 0.1189], [-0.431, 0.0242], [-0.4799, 0.292], [0.6109, 0.083], [-0.4081, 0.292], [-0.1109, -0.2992], [0.5129, -0.0575], [0.1406, -0.4527]] # ....ещё один массив u = pts2d([:,1]) v = pts2d([:,2]) 

error is displayed:

  u = pts2d([:,1]) ^ SyntaxError: invalid syntax 
  • You should not change the question after the answer. It only confuses the rest. If there is a new problem, it is necessary to issue a new question. - Timofei Bondarev

2 answers 2

There are several errors in your code.

  1. np.array is a function, and you need to use parentheses to call it:

     pts2d = np.array([[1.0486, -0.3645], [-1.6851, -0.4004], [-0.9437, -0.42], [1.0682, 0.0699], [0.6077, -0.0771], [1.2543, -0.6454], [-0.2709, 0.8635], [-0.4571, -0.3645], [-0.7902, 0.0307], [0.7318, 0.6382], [-1.058, 0.3312], [0.3464, 0.3377], [0.3137, 0.1189], [-0.431, 0.0242], [-0.4799, 0.292], [0.6109, 0.083], [-0.4081, 0.292], [-0.1109, -0.2992], [0.5129, -0.0575], [0.1406, -0.4527]]) 
  2. To get a column from the np.ndarray object, which is created by the np.array function, parentheses are not needed, you need to use the access mechanism through indexing:

     u = pts2d[:,1] v = pts2d[:,2] 
  3. Arrays in Python and many other languages ​​start with a zero index, so if you want to take the first and second columns, you need to use indices 0 and 1:

     u = pts2d[:,0] v = pts2d[:,1] 
  4. So I did not understand what the declared, but not completed, function createSystem

  • 1,2,3, changed thanks a lot. 4- This is the function I am working with now, it will return the resulting matrix. - Tina Ch
  • @TinaCh The question is to place only what is directly related to the problem. - Timofei Bondarev

You can loop through the array and display the required column.