Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I would like to create the 2D array with respect to elements, something like:

np.array([[1, 0], [1, 0], [1, 0]])

And wanted the shape to be (1000, 2).

1 Answer

0 votes
by (36.8k points)

Try the below code:

import numpy as np

arr=np.tile(np.array([0,1]),(1000,1))

which gives out put as fallows:

>>> print(arr)

[[0 1]

 [0 1]

 [0 1]

 ...

 [0 1]

 [0 1]

 [0 1]]

And has a shape:

>>> arr.shape

(1000, 2)

Learn data science with python course to improve your technical knowledge.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...