简体   繁体   中英

How to iterate over the rows of a single column of a numpy array?

I have a NumPy array made up of two columns and 8269 rows. I want to be able to multiply all of the values of the second column by 10^-10. I'm new to programming and I'm not sure how to refer to every row of a single column of a NumPy array. Thanks!

Using numpy.nditer from @karma4917's answer:

import numpy as np

with np.nditer(your_array[:,1], op_flags=['readwrite']) as it:
    for x in it:
        x *= 10**(-10)

for me, it took 0.0045 seconds for an array with 2696 lines.

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