0

I was surprised I couldn't find this more easily. How do we set the number of digits to truncate to when reading in a numpy array?

import numpy as np

np.set_printoptions(threshold=sys.maxsize)
pose_raw =  [0.8646331429481506, -0.22936344146728516, -0.4469817578792572, 0.0, 0.3616204857826233, 0.9017571806907654, 0.2367781400680542, 0.0, 0.3487676680088043, -0.3663671910762787, 0.8626390695571899, 0.0, -0.534120500087738, -2.0878100395202637, -0.4539491534233093, 1.0]

pose = np.array(pose_raw).reshape((4,4)).T
print("raw ", p["pose"])
print("processed ", pose)

Gives the following

raw [0.8646331429481506, -0.22936344146728516, -0.4469817578792572, 0.0, 0.3616204857826233, 0.9017571806907654, 0.2367781400680542, 0.0, 0.3487676680088043, -0.3663671910762787, 0.8626390695571899, 0.0, -0.534120500087738, -2.0878100395202637, -0.4539491534233093, 1.0] Blockquote

processed [[ 0.86463314 0.36162049 0.34876767 -0.5341205 ] [-0.22936344 0.90175718 -0.36636719 -2.08781004] [-0.44698176 0.23677814 0.86263907 -0.45394915] [ 0. 0. 0. 1. ]]

Alberto MQ
  • 373
  • 2
  • 16
  • 1
    In other words, `threshold` doesn't seem to be the correct option - you're looking for `precision`. Try `np.set_printoptions(precision=16)`. – ForceBru Feb 07 '22 at 20:35
  • Are you sure it's truncated or it's just that `print` only gets you so many digits. – Guillaume Feb 07 '22 at 20:35
  • You're totally right about the threshold/precision thing. When I later passed the numpy array to something else it was using numpy's string representation and was therefore truncated. – Alberto MQ Feb 07 '22 at 20:39

0 Answers0