Python Forum
Inserting slice of array objects into different slice
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inserting slice of array objects into different slice
#5
(Apr-01-2020, 04:35 AM)perfringo Wrote: The problem is exactly described in error message: you can't broadcast shape 2,1 into shape 2.
But it obviously doesn't describe a solution, and a ton of research hasn't led me any nearer on a solution.

(Apr-01-2020, 04:35 AM)perfringo Wrote: Before any advice it would be good to know what is the objective i.e. what do you want to accomplish.
The exact same result that I said I got in the first post, but without having to do it one by one. It's fine with an array of a size 2, but what if I had a size 10, 1000 or even higher? Then part of my code would look like this:

a[0]=b[0]
a[1]=b[1]
a[2]=b[2]
a[3]=b[3]
a[4]=b[4]
a[5]=b[5]
...
a[997]=b[997]
a[998]=b[998]
a[999]=b[999]
But there must be an easier way of doing this, using slicing, or list comprehension perhaps. And that's what I can't figure out how to do.
Reply


Messages In This Thread
RE: Inserting slice of array objects into different slice - by ThemePark - Apr-01-2020, 01:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  slice per group Progressive 3 5,332 Jul-20-2019, 06:52 AM
Last Post: scidam
  TypeError: '(slice(None, None, None), 0)' is an invalid key zaki424160 1 15,199 Jul-17-2019, 11:53 PM
Last Post: scidam
  Melt or Slice Grin 0 2,178 Jun-24-2018, 06:02 PM
Last Post: Grin

Forum Jump:

User Panel Messages

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