Questions tagged [python-cmath]

A standard-library module in Python that provides access to mathematical functions for complex numbers.

9 questions
2
votes
2 answers

Multiplying a float Number to a Function in Python and getting can't multiply sequence by non-int of type 'float'

I have the following code written in python 2.7. Here I've defined two function, a cosine function and an exponential function and I need to multiply these functions to a float Value, but I am getting this error. I assume we can't multiply a float…
Vahid Talebi
  • 175
  • 1
  • 9
1
vote
1 answer

Is there a difference between math.inf and cmath.inf in Python?

Is there any difference between the infinities returned by the math module and cmath module? Does the complex infinity have an imaginary component of 0?
Alec
  • 8,529
  • 8
  • 37
  • 63
1
vote
2 answers

Can cmath.sqrt be applied to a NumPy array?

I want to calculate the square root of a numpy array of negative numbers. I tried with np.sqrt() but it gives error beacuse the domain. Then, I found that for complex numbers you can use cmath.sqrt(x) but it also gives me an error. Here's my…
1
vote
2 answers

The values of a vector in python are shown as nan value

I have a vector y with size, for example, (1,64). I create a vector in python as follows: vec = np.pi * np.sqrt(-1) * range(len(y)) I get the output values of the vector vec are all nan or the majority of them are nan. What i'm trying to…
Fatima_Ali
  • 194
  • 9
0
votes
1 answer

Count the number of complex, real and pure imaginary numbers in a numpy matrix

Given a Numpy array/matrix, what is pythonic way to count the number of complex, pure real and pure imaginary number: [[ 1. +0.j 1. +0.j 1. +0.j 1. +0.j 1. +0.j ] [ 1. +0.j 0.309+0.951j -0.809+0.588j -0.809-0.588j …
Rajesh Swarnkar
  • 601
  • 1
  • 6
  • 18
0
votes
1 answer

Generating Numpy Arrays of Complex Numbers

How can I quickly generate a numpy array of calculated complex numbers? By which I mean, the imaginary component is calculated from an array of values. I have tried using python's literal j without luck. It seems to only accept float and int cases.…
Matt
  • 190
  • 2
  • 12
0
votes
2 answers

Quadratic formula: python treating floats as strings

I am making a program that asks the user to input values for a, b and c which are then used to compute the roots using the quadratic formula. The only problem I have is that python treats a and the square root term as two strings and they are not…
lain
  • 5
  • 1
-1
votes
3 answers

Python Complex Number Operations

I have an equation (0.125-(1j*(mu1)*0.125))/(0.125 - cmath.sqrt((0.125**2)-(0.125**2)-((mu1**2)*(0.125**2)))) This is suppose to be 1 for any value of mu1 but it seems I am getting 1 only if mu1 is real... what am I missing? For mu1 = 1, the above…
user3873617
  • 374
  • 1
  • 3
  • 15
-1
votes
1 answer

Inserting complex functions in a python code

I have been trying to insert $e^ix$ as matrix element. The main aim is to find the eigenvalue of a matrix which has many complex functions as elements. Can anyone help me how to insert it? My failed attempt is below: for i in range(0,size): …