vector

Create a matrix using a certain vector in Python

Create a matrix using a certain vector in Python Question: I have this vector m = [1,0.8,0.6,0.4,0.2,0] and I have to create the following matrix in Python: I create a matrix of zeros and a double mm = np.zeros((6, 6)) for j in list(range(0,6,1)): for i in list(range(0,6,1)): ind = abs(i-j) m[j,i] = mm[ind] But, …

Total answers: 2

__rand__ across np array dimensions

__rand__ across np array dimensions Question: How to compare values in val against arr based on operators o? import numpy as np from operator import gt, lt val = np.array([[3,7,1], [4,8,5], [5,10,3]]) arr = np.array([[1,2,3,4,5], [6,7,8,9,10], [9,7,5,3,1]]) o = (gt, gt, lt) # [3,7,1] # (3 gt [1,2,3,4,5]) & (7 gt [6,7,8,9,10] & (1 lt …

Total answers: 1

How do I write a function that returns mean, median and trimmed mean in python?

How do I write a function that returns mean, median and trimmed mean in python? Question: I am attempting to write a function that will give me an output of mean, median and trimmed mean depending on what is chosen. This is the problem: Suppose x is a vector. Write a function f(x,type) where the …

Total answers: 1

How do I check if two vectors are equal using a function?

How do I check if two vectors are equal using a function? Question: I am attempting to check if two vectors are equal using a function. I don’t know if I am using the correct function because I am not getting true or false as a return. Here is my code: import numpy as np …

Total answers: 1

Multiply 3D array with vectors in all three dimensions in Python

Multiply 3D array with vectors in all three dimensions in Python Question: I am trying to multiply 3D array f by vectors x, y and z in all three dimensions. import numpy as np f = np.ones((2, 3, 4)) x = np.linspace(0, 10, 2) y = np.linspace(0, 10, 3) z = np.linspace(0, 10, 4) print(z …

Total answers: 1

Rotate timeseries values around an angle with Python

Rotate timeseries values around an angle with Python Question: I have a timeseries which for the sake of simplicity looks like this: import pandas as pd points = [0, 1, 0, 0, -1, 0] df = pd.DataFrame(points) df.plot(legend=False) Now I want to rotate the values based on a specific angle, which will be between 0 …

Total answers: 1

I am trying to define the following vector function, but keep getting an error

I am trying to define the following vector function, but keep getting an error Question: Where am I going wrong? The function: The code I have written is as follows! Note the second def function is an attempt to integrate it using solve_ivp! please let me know if there are any issues there as well: …

Total answers: 1

Is there a R function or Python for finding the covariance-matrix of a random vector?

Is there a R function or Python for finding the covariance-matrix of a random vector? Question: https://www.biostat.jhsph.edu/~iruczins/teaching/140.751/notes/ch3.pdf Every R function or Python function I found finds the covariance between two vectors or returns a scalar, but I want a function that takes vector and returns a matrix. Asked By: TransIndigenous || Source Answers: There is …

Total answers: 1

loop for, and arrays in python

loop for, and arrays in python Question: VALOR_VETOR = 6 nota1 = [] nota2 = [] nota3 = [] mediaAluno = [] soma1 = 0 soma2 = 0 soma3 = 0 somaMedia = 0 mediaTurma = 0 print("Digite as notas dos alunosnn") for i in range (VALOR_VETOR): print(f"Aluno {i}") valor = float(input(f"Nota 1: ")) nota1.append(valor) …

Total answers: 2

Python For Vector

Python For Vector Question: n = int(input("Enter how many numbers will be stored : ")) vet1 = [n] vet2 = [n] print("Enter the numbers to be stored") for i in range(n): vet1 = int(input(f"number {i}: ")) for i in range(n): if (vet1%2 == 0): vet2 = vet1 + 1 print(f"nThe number entered was {vet1}nYour successor …

Total answers: 2