Skip to content

sc.midpoints does not operate on vector-valued data #3751

Closed

Description

@g5t

sc.midpoint does not operate on vector-valued data, but a simple alternative works fine (probably missing the corner cases mentioned in the sc.midpoint doc string)

import scipp as sc
dim='x'
vecs = sc.vectors(values=[[0, 0, 0], [1, 1, 1], [2, 2, 2]], dims=[dim], unit='m')
midpoint = sc.vectors(values=[[0.5, 0.5, 0.5], [1.5, 1.5, 1.5]], dims=[dim], unit='m')
try:
    calculated = sc.midpoints(vecs, dim)
except sc.DTypeError as er:
    print(f'sc.midpoints failed with error `{er}`')
    calculated = (vecs[dim,:-1] + vecs[dim,1:]) / 2

if not sc.allclose(midpoint, calculated):
    print('Failed calculating the midpoint')

raises an exception in the try statement which causes the following output on my machine:

sc.midpoints failed with error `'midpoints' does not support dtypes 'vector3', 'vector3', `

Activity

  1. self-assigned this
    on Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions