Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

numpy

>>> import numpy as np
>>> a = np.array([2,3,4])
>>> a
array([2, 3, 4])
>>> a.dtype
dtype('int64')
>>> b = np.array([1.2, 3.5, 5.1])
>>> b.dtype
dtype('float64')
Comment

numpy

import numpy as np


speed = [10, 20, 30, 40]

# mean of an array - sum(speed) / len(speed)
x = np.mean(speed)
print(x)
# output 25.0

# return the median number - If there are two numbers in the middle, divide the sum of those numbers by two.
x = np.median(speed)
print(x)
# output 25.0

# return standard deviation - the lower the number return the closer the data is related
x = np.std(speed)
print(x)
# output 11.180339887498949

# return Variance of array - show how spread out the data is. The smaller the number the closer the data is related
x = np.var(speed)
print(x)
# output 125.0

# returns percentile of an array.
x = np.percentile(speed, 20)
print(f"20 percent of speed is {x} or lower")
# output 20 percent of speed is 16.0 or lower

x = np.percentile(speed, 90)
print(f"90 percent of speed is {x} or lower")
# output 90 percent of speed is 37.0 or lower

# We specify that the mean value is 5.0, and the standard deviation is .2.
# the lower the scale the closer the random numbers are to the loc number
# returns size of 100 floats in array
# normal distribution
x = np.random.normal(loc=5.0, scale=.2, size=100)
print(x)

# create array
arr = np.array([10, 20, 20, 30, 30, 20])
print("Original array:")
print(arr)

print("Mode: Most frequent value in the above array:")
print(np.bincount(arr).argmax())
# output
# Most frequent value in the above array:
# 20
# returns the least common multiple
x = np.lcm(3, 4)
print(x)
# output 12


# returns the lowest common multiple of items in array
arr = np.array([3, 6, 9])
x = np.lcm.reduce(arr)
print(x)
# 18

# returns the greatest common multiple of 2 numbers
x = np.gcd(3, 4)
print(x)
# output 1

# return the highest common multiple of items in array
arr = np.array([20, 8, 32, 36, 16])
x = np.gcd.reduce(arr)
print(x)
# output 4
Comment

numpy

def quicksort(arr):
    if len(arr) <= 1:
        return arr
    pivot = arr[len(arr) // 2]
    left = [x for x in arr if x < pivot]
    middle = [x for x in arr if x == pivot]
    right = [x for x in arr if x > pivot]
    return quicksort(left) + middle + quicksort(right)

print(quicksort([3,6,8,10,1,2,1]))
# Prints "[1, 1, 2, 3, 6, 8, 10]"
Comment

numpy

>>> # The standard way to import NumPy:
>>> import numpy as np

>>> # Create a 2-D array, set every second element in
>>> # some rows and find max per row:

>>> x = np.arange(15, dtype=np.int64).reshape(3, 5)
>>> x[1:, ::2] = -99
>>> x
array([[  0,   1,   2,   3,   4],
       [-99,   6, -99,   8, -99],
       [-99,  11, -99,  13, -99]])
>>> x.max(axis=1)
array([ 4,  8, 13])

>>> # Generate normally distributed random numbers:
>>> rng = np.random.default_rng()
>>> samples = rng.normal(size=2500)
Comment

python numpy

print(np.zeros((4,4)))
Comment

NumPy

<div>
  <article class="print:hidden">
    <h1>My Secret Pizza Recipe</h1>
    <p>This recipe is a secret, and must not be shared with anyone</p>
    <!-- ... -->
  </article>
  <div class="hidden print:block">
    Are you seriously trying to print this? It's secret!
  </div>
</div>
Comment

python numpy

numpy.zeros(shape, dtype=float, order='C')
Comment

numpy

>>> p = numpy.poly1d([1, 0, 1])
>>
>>> print q
2 x
>>> q(5)
10
Comment

PREVIOUS NEXT
Code Example
Python :: url python 
Python :: how to convert ui file to py file 
Python :: serialization in python 
Python :: what does << do in python 
Python :: how to open an application with python 
Python :: python plot confidence interval 
Python :: how to change directory in python 
Python :: python object has no attribute 
Python :: temporary table pyspark 
Python :: python class variable 
Python :: print hello world 
Python :: signup view django 
Python :: python endless loop 
Python :: def tkinter 
Python :: random forest classifier python 
Python :: padding figures in pyplot 
Python :: Python If ... Else 
Python :: round down decimal python 
Python :: package python 
Python :: python len 
Python :: get chrome version with python 
Python :: python conditional statement 
Python :: positive and negative number in python 
Python :: matplotlib subplots share x axis 
Python :: calculator python tutorial 
Python :: runtime errors in python 
Python :: average of a list in function with python 
Python :: find last element in list python 
Python :: indent python 
Python :: open chrome console in selenium 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =