Python

import numpy as np
*# Create an array of 3 elements.*
array_one = **np.array**([5, 10, 15])
print(array_one)
*# An array can be multiplied by an int.*
*# ... This is an array broadcasting example.*
array_two = array_one * 2
print(array_two)[ 5 10 15]
[10 20 30]

import numpy as np
*# Create a 1-dimensional array of 5 random values.*
random_values = np.**random**.normal(size=[1, 5])
print(random_values)[[ 0.49786323 0.81794554 -0.63191935 0.25130401 0.80529426]]

import numpy as np
*# Get values using arange method.*
*# ... This is an exclusive bound.*
values = np.**arange**(*5*)
print(values)
*# Two arguments can be used.*
*# ... The second argument is an exclusive bound.*
values = np.**arange**(*3*, *6*)
print(values)
*# A step can be used.*
values = np.**arange**(*0*, *5*, *2*)
print(values)[0 1 2 3 4]
[3 4 5]
[0 2 4]

Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.

Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.

This page was last updated on Sep 18, 2023 (edit).