Skip to content

[Python Interface] Regression: can't properly convert a vector to 2D/3D numpy array #17729

@dpiparo

Description

@dpiparo

Check duplicate issues.

  • Checked for duplicates

Description

Issue opened fom a Forum post

Reproducer

import ROOT
import numpy as np

a = ROOT.vector("vector<vector<float>>")() # 3D
a1 = ROOT.vector("vector<float>")() # 2D
a2 = ROOT.vector("float")()
a2.push_back(1.)
a2.push_back(2.)
a2.push_back(3.)
a1.push_back(a2)
a1.push_back(a2)
a1.push_back(a2)
a.push_back(a1)
a.push_back(a1)
a.push_back(a1)

print(a)

print(np.array(a).shape) # 3D
print(np.array(a1).shape) # 2D

The output should be, as given by 6.30.06:

{ { { 1.00000f, 2.00000f, 3.00000f }, { 1.00000f, 2.00000f, 3.00000f }, { 1.00000f, 2.00000f, 3.00000f } }, { { 1.00000f, 2.00000f, 3.00000f }, { 1.00000f, 2.00000f, 3.00000f }, { 1.00000f, 2.00000f, 3.00000f } }, { { 1.00000f, 2.00000f, 3.00000f }, { 1.00000f, 2.00000f, 3.00000f }, { 1.00000f, 2.00000f, 3.00000f } } }
(3, 3, 3)
(3, 3)

However, for 6.34.04 it is:

{ { { 1.00000f, 2.00000f, 3.00000f }, { 1.00000f, 2.00000f, 3.00000f }, { 1.00000f, 2.00000f, 3.00000f } }, { { 1.00000f, 2.00000f, 3.00000f }, { 1.00000f, 2.00000f, 3.00000f }, { 1.00000f, 2.00000f, 3.00000f } }, { { 1.00000f, 2.00000f, 3.00000f }, { 1.00000f, 2.00000f, 3.00000f }, { 1.00000f, 2.00000f, 3.00000f } } }
(3,)
(3,)

ROOT version

6.34.04

Installation method

all

Operating system

all

Additional context

No response

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions