Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
dpiparo opened this issue Feb 15, 2025 · 0 comments
Open
1 task done

Comments

@dpiparo
Copy link
Member

dpiparo commented Feb 15, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants