J
J
Johnem2020-08-18 15:10:43
Python
Johnem, 2020-08-18 15:10:43

How to implement similar code in numpy?

Hello, how to implement a similar algorithm, only not for a list, but for a row of a numpy 10000 by 5 array (for each row of 10000), thanks in advance

a = [0.999, 0.121, 0.230, 0.001]
for i in range(0, 4):
    a.insert(i, round(a[i] - (a[i] * 100 % 10) / 100, 1))
    a.pop(i + 1)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
ScriptKiddo, 2020-08-18
@Johnem

https://stackoverflow.com/a/37697840

import numpy as np

def trunc(values, decs=0):
    stepper = 10.0 ** decs
    return np.trunc(values * stepper) / stepper

a = np.random.sample((10, 5))

print(a)
a = trunc(a, 2)
print(a)

Execution result



Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question