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
#1
Suppose I have the following code:
import numpy as np
a=np.zeros((2),dtype=np.object)
b=np.array([[11],[13]])
a[0]=b[0]
a[1]=b[1]
print(a)
This gives me the wanted result of "[array([11]) array([13])]". But if I have a big array, it's too tedious to add a line for each index. So I wanna do it in some way like this:
a[0:2]=b[0:2]
But that gives me the error "ValueError: could not broadcast input array from shape (2,1) into shape (2)". So how do I have to write that one line to accomplish the same as the code at the beginning?
Reply


Messages In This Thread
Inserting slice of array objects into different slice - by ThemePark - Mar-30-2020, 07:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  slice per group Progressive 3 5,329 Jul-20-2019, 06:52 AM
Last Post: scidam
  TypeError: '(slice(None, None, None), 0)' is an invalid key zaki424160 1 15,198 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