Useful statistics script - Copy and paste this code into the editor above!
from scipy.stats import norm
p_value = norm.sf(2) # Right tail probability for Z > 2
print(f"P(Delta > 0) = {p_value:.4f}")
t-distribution one tail probability
To calculate the one-tail probability for a t-distribution with 10 degrees of freedom and a t-value of 2.228, you can use the following Python code:
from scipy.stats import t
# Parameters
df = 10 # degrees of freedom
t_value = 2.228
# Calculate one-tail probability
p_value = t.sf(t_value, df) # Right tail probability for t > t_value
print(f"P(T > {t_value}) = {p_value:.4f}")
Code Example
Here's a simple example of using NumPy, PIL, and SciPy in the browser with Pyodide. The code loads an image from a URL, performs edge detection using convolution, and displays the result.
Click the Run Code button to execute the Python code and see the output below.
from PIL import Image
import numpy as np
from scipy.ndimage import convolve
from js import fetch
from io import BytesIO
import asyncio
import base64
from js import fetch, document
KERNEL_Y = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]])
KERNEL_X = np.array([[1, 0, -1], [2, 0, -2], [1, 0, -1]])
async def load_image(url="https://dorpascal.com/favicon.png"):
response = await fetch(url)
array_buffer = await response.arrayBuffer()
binary_data = BytesIO(bytes(array_buffer.to_py()))
img = Image.open(binary_data)
print(f"Loaded image: {img.format}, {img.size}, {img.mode}")
return np.array(img)
def edge_detection(image_array):
gray_image = np.mean(image_array, axis=2)
edgeY = convolve(gray_image, KERNEL_Y, mode='constant', cval=0.0)
edgeX = convolve(gray_image, KERNEL_X, mode='constant', cval=0.0)
edgeMAG = np.sqrt(edgeX**2 + edgeY**2)
return edgeMAG
async def main():
url = "https://raw.githubusercontent.com/yotam-biu/ps12/refs/heads/main/.tests/lena.jpg"
image = await load_image(url)
edges = edge_detection(image)
print(f"Edge-detected image shape: {edges.shape}")
img = Image.fromarray((edges / edges.max() * 255).astype(np.uint8))
if img.mode == "RGBA":
img = img.convert("RGB")
output_buffer = BytesIO()
img.save(output_buffer, format="JPEG", quality=95)
output_buffer.seek(0)
base64_data = base64.b64encode(output_buffer.read()).decode('utf-8')
data_url = f"data:image/jpeg;base64,{base64_data}"
link = document.querySelector("#cta1")
link.href = data_url
link.download = "edges.jpg"
document.querySelector("#cta1").textContent = "Download Image"
print("Base64 download link created. Click the link to download the image.")
main()