0

Suppose I have a numpy array like so:

a = ([[4, 9], [38, 8], [90, 10]...[8545, 17]])

Where the first element is a location ID and the second is the amount of time spent at each location in minutes. I want to convert these times into seconds which requires me to multiply every other value by 60.

As this is a very long array, what would be the most time-efficient method for converting these times?

0

1 Answer 1

2

Use this:

import numpy as np
# a is your original list of [location, time] pairs
a = np.array(a)
a[:, 1] *= 60

It simply multiplies the second column of your array a by 60 to convert the time values into seconds.

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

3 Comments

Thank you, much simpler than the for loop I was trying to use
You'd be better off using a[:, 1] *= 60. It's an in-place operation and won't allocate a temp array.
@Mad Physicist: Thanks for the comment. Noted.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.