Slice an array into multiple arrays - Python

0 votes

I have an array that I would like to slice into multiple arrays in the form of:

M = [1,2,3         
     4,5,6
     7,8,9]
 to [ [1],[2]....[9] ]  (List of arrays)
May 29 in Python by Meena
11 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

can use numpy.reshape. 

In your case, pass 1 as 2nd dimension, and let the method infer the first dimension by passing -1:

M = [1, 2, 3,
     4, 5, 6,
     7, 8, 9]

np.reshape(M, (-1, 1))
answered May 29 by Alia

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

Is arr.__len__() the preferred way to get the length of an array in Python?

my_list = [1,2,3,4,5,6,7] len(my_list) # 7 The same works for ...READ MORE

answered Oct 8, 2018 in Python by SDeb
• 11,080 points
33 views
0 votes
1 answer

How can I turn an input date into a readable string in Python?

The datetime class has a method strftime. strftime() ...READ MORE

answered Dec 11, 2018 in Python by ariaholic
• 7,320 points
27 views
0 votes
1 answer

how do I check the length of an array in a python program?

lets say we have a list mylist = ...READ MORE

answered Mar 12 in Python by Mohammad
• 1,400 points
20 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
69 views
+4 votes
6 answers
+4 votes
7 answers
0 votes
1 answer

I'm using Python 2.7 to convert an XML response (from a REST call to Atlassian Fisheye) into an HTML table.

You don't have a template matching tabularQueryResult in your ...READ MORE

answered Oct 4, 2018 in Python by Priyaj
• 56,140 points
24 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.