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

ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (13,13)->(13,13) (10000,10)->(10000,newaxis,10) #1790

strawberry1996 opened this issue Mar 18, 2019 · 1 comment


Copy link

commented Mar 18, 2019


I import myself nii file and this file is 4-dimension (90,160,13,10) where(height, width, direction, number of slice), I want to get fa file ,but when I run'' The program reported an error

My code is as follows:
nii_path = 'F:\project_python\run_on_server\dicom\data\mask_slice_all.nii'
bval_path = 'F:\project_python\run_on_server\dicom\data\20120314_190357Z565B0200DTITD850s001a1001.bval'
bvec_path = 'F:\project_python\run_on_server\dicom\data\20120314_190357Z565B0200DTITD850s001a1001.bvec'

nii_img, affine = load_nifti(nii_path)
bval, bvec = read_bvals_bvecs(bval_path, bvec_path)
gtab = gradient_table(bval, bvec)
print("nii: ",nii_img.shape)
print("affine: ",affine.shape)

tenmodel = TensorModel(gtab)
print("tenmodel: ",tenmodel)
tenfit =,mask = None)

save_nifti('colorfa.nii.gz', tenfit.color_fa, affine)

report error:
Traceback (most recent call last):
File "C:\Users\Administrator\Anaconda3\lib\site-packages\IPython\core\", line 2963, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
runfile('F:/project_python/run_on_server/dicom/', wdir='F:/project_python/run_on_server/dicom')
File "D:\pycharm\PyCharm 2018.2.4\helpers\pydev_pydev_bundle\", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "D:\pycharm\PyCharm 2018.2.4\helpers\", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "F:/project_python/run_on_server/dicom/", line 69, in
tenfit =,mask = None)
File "C:\Users\Administrator\Anaconda3\lib\site-packages\dipy\reconst\", line 794, in fit
File "C:\Users\Administrator\Anaconda3\lib\site-packages\dipy\reconst\", line 1304, in wrapped_fit_tensor
*args, **kwargs)
File "C:\Users\Administrator\Anaconda3\lib\site-packages\dipy\reconst\", line 1382, in wls_fit_tensor
w = np.exp(np.einsum('...ij,...j', ols_fit, log_s))
File "C:\Users\Administrator\Anaconda3\lib\site-packages\numpy\core\", line 1069, in einsum
return c_einsum(*operands, **kwargs)
ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (13,13)->(13,13) (10000,10)->(10000,newaxis,10)


This comment has been minimized.

Copy link

commented Mar 18, 2019

This was closed, but I will still reply here for the sake of posterity. I think that there are two issues here. The first is that you need to read the data into memory before fitting:

data = nii_img.get_fdata()
tenfit =, mask = None)

The second thing that seems to be happening here is because DIPY expects the directions to be the last dimension of your data (which is a common case). In this case, you'd probably want to swap the last and second to last axes, before fitting the model. Something like:

data = nii_img.get_fdata()
new_data = np.swapaxes(data, -2, -1)
tenfit =, mask = None)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.