简体   繁体   中英

How to fix 'numpy.ndarray' object is not callable’ error in python?

I've just begun to learn Python. However, there was a problem.

I try to connect it with a curve or a straight line using a few coordinate points.

Or... Can you change this code simple?

first_coordinate

A_lon = np.array([126.393, 127.012, 127.545, 128.035, 128.544, 128.768, 129.239])
A_lat = np.array([37.277, 37.553, 37.343, 37.576, 37.486, 37.924, 37.795])

A_lon_new = np.linspace(A_lon.min(), A_lon.max(),500)

f = interp1d(A_lon, A_lat, kind='quadratic')
A_lat_new = f(A_lon_new)

A_x, A_y = map(A_lon, A_lat)
A_x1, A_y1 = map(A_lon_new, A_lat_new)


m.plot (A_x, A_y, "ko", markersize=5)

straight_line

m.plot(A_x, A_y, color='b', linestyle = '--', linewidth=1.5)

curve_line

m.scatter (A_x1, A_y1, color='r', linestyle = '--', linewidth=1.5)

Second_coordinate

B_lon = np.array([126.285, 127.314, 127.653, 128.214, 128.92, 129.057, 129.735])
B_lat = np.array([36.132, 35.847, 35.93, 36.406, 36.102, 36.4, 36.816])

B_lon_new = np.linspace(B_lon.min(), B_lon.max(),500)

f = interp1d(B_lon, B_lat, kind='quadratic')
B_lat_new = f(B_lon_new)

B_x, B_y= map(B_lon, B_lat)
B_x1, B_y1 = map(B_lon_new, B_lat_new)


m.plot (B_x, B_y, "ko", markersize=5)

straight_line

m.plot (B_x, B_y, color='b', linestyle = '--', linewidth=1.5)

curve_line

m.plot(B_x1, B_y1, color='r', linestyle = '-', linewidth=1.5)

plt.show()

I've this error :

    TypeError                                 Traceback (most recent call last)
<ipython-input-2-6e05a05d2dab> in <module>()
     76 A_lat_new = f(A_lon_new)
     77 
---> 78 A_x, A_y = map(A_lon, A_lat)
     79 A_x1, A_y1 = map(A_lon_new, A_lat_new)
     80 

TypeError: 'numpy.ndarray' object is not callable

It looks like the offending line of code is

A_x, A_y = map(A_lon, A_lat)

The map function applies a function to some kind of list or iterable. Eg

map(lambda x: 2*x, [1, 2, 3])
# [2, 4, 6]

The object in A_lon is definitely an array rather than a function. Are you trying to combine those two arrays together with a function like zip ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM