0% found this document useful (0 votes)
5 views3 pages

Numpy Array Creation and Manipulation Guide

Uploaded by

srujjanbelamgi12
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Numpy Array Creation and Manipulation Guide

Uploaded by

srujjanbelamgi12
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Create a Numpy array of 4 elements without initialization


2. Array of 5 with initilzation to 0
3. Get the following output

4. Get the following output

5. Create new empty array with the same shape and type as a given
array.(empty_like)

6.

7.

an array of ones with the same shape and type as a given array.

Array with Zeros with custom data type

[Link]((2,), dtype=[('x', 'i4'), ('y', 'i4')]) # custom dtype


an array of zeros with the same shape and type as a given array.

numpy.zeros_like
a new array of given shape and type, filled with fill_value.

[Link]
a full array with the same shape and type as a given array.

numpy.full_like
out of the following
import numpy as np
[Link]((2,2), 1) == [Link]((2,2))

[Link](2, dtype=int).reshape(4, 1)

print first item of an array

print the number 8 from the array below:

arr = [Link]([[1,2,3,4,5], [6,7,8,9,10]])

print the numbers [3, 4, 5] from the array below:

arr = [Link]([1,2,3,4,5,6,7])

print the last 4 numbers from the array below:

arr = [Link]([1,2,3,4,5,6,7])

vprint every other item from the array below:

arr = [Link]([1,2,3,4,5,6,7])

create an array of type float?

Original arrays:
[[ 11 22 33 44 55]
[ 66 77 88 99 100]]
New array:
[[ 22 44 11 55 33]
[ 77 99 66 100 88]]

How to convert a 1D array into a 2D array (how to add a new axis to an array)

You might also like