Python Forum
ValueError: shape mismatched: objects cannot be broadcast to a single shape
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: shape mismatched: objects cannot be broadcast to a single shape
#1
I'm trying to save a txt file by manually entering the energy values in our experiment, but the code runs an error:

b = np.broadcast(*args[:32])

ValueError: shape mismatch: objects cannot be broadcast to a single shape
The code looks like this:

name='I1'
scan_number=np.array([23, 24, 25, 26, 27, 28, 29, 30, 
                      31, 32, 33, 34, 35, 36, 37, 38, 39, 40])
n_pts = 701
n_chnl = 4096
mca_start = 3116

name='I0'
scan_number=np.array([45, 46, 47])
n_pts = 701
n_chnl = 4096
mca_start = 17138

x=np.arange(1, n_pts+1)
energy=np.arange(7.65e+03, 8e+03, 0.5)
np.savetxt(file,
       np.transpose(([energy, area[:,0], area[:,0]])),
       header='Energy I0 I1 {}'.format(name))
How do I fix this error? I should have energy values from 7.65 to 8.00 keV with 0.5 step / 701 points in the energy column, but the np.arange command doesn't seem to work.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  output shape problem with np.arange alan6690 5 668 Dec-26-2023, 05:44 PM
Last Post: deanhystad
  convert address and broadcast to network object Skaperen 9 1,787 Mar-09-2023, 06:55 PM
Last Post: Skaperen
  simplekml change shape&color issac_n 2 2,822 Aug-20-2022, 07:15 PM
Last Post: Joseph_Paintsil
  operands could not be broadcast together with shapes (337,451) (225,301) kevinabbot 0 1,559 Dec-14-2021, 04:02 PM
Last Post: kevinabbot
  Can't properly shape an array maaaa2401 3 2,314 Dec-18-2020, 09:32 AM
Last Post: maaaa2401
  Pyspark SQL Error - mismatched input 'FROM' expecting <EOF> Ariean 3 48,042 Nov-20-2020, 03:49 PM
Last Post: Ariean
  Receiving ValueError("bad input shape {0}".format(shape)) error SuryaCitizen 2 3,503 Jun-01-2020, 06:45 AM
Last Post: pyzyx3qwerty
  Fill a value in triangle shape in Matrix lynx 0 1,869 Dec-07-2019, 06:32 AM
Last Post: lynx
  My objective is to get the shape parameters of the particles in attached image chad221 0 1,778 Oct-26-2019, 10:27 AM
Last Post: chad221
  Pyspark "mismatched input FIELDS" Mabooka 1 4,061 Aug-31-2019, 08:51 AM
Last Post: Mabooka

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020