• Register

Recent questions tagged python-numpy

0 votes
1 answer 12 views
Problem: I am trying to evaluate a formula, np is numpy: Ds = pow(10,5) D = np.linspace(0, pow(10,6), 100) alpha=1.44 beta=0.44 A=alpha*(D/Ds) L=1.65 buf2=L/4.343 buf=pow(-(alpha*[D/Ds]),beta) value=exp(buf) and then I will plot this data but I get: buf=pow(-(alpha*[D/Ds]),beta) TypeError: can't multiply sequence by non-int of type 'float' How can I overcome this?
asked Feb 17 Mashhoodch 9.1k points
0 votes
1 answer 28 views
Problem: Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index (1) in Python? list.index(x[, start[, end]]) Return zero-based index in the list of the first item whose value is equal to x. Raises a ValueError if there is no such item.
asked Jan 10 Mashhoodch 9.1k points
0 votes
1 answer 37 views
Problem: I have such Python code: import numpy as np import matplotlib.pyplot as plt def f(x): return np.int(x) x = np.arange(1, 15.1, 0.1) plt.plot(x, f(x)) plt.show() And such error: TypeError: only length-1 arrays can be converted to Python scalars How can I fix it?
asked Jan 10 Mashhoodch 9.1k points
0 votes
1 answer 24 views
Problem: I am creating a program that reads a file and if the first line of the file is not blank, it reads the next four lines. Calculations are performed on those lines and then the next line is read. If that line is not empty it continues. However, I am getting this error: ... with base 10: ''. It is reading the first line but can't convert it to an integer. What can I do to fix this problem?
asked Jan 9 Mashhoodch 9.1k points
0 votes
1 answer 13 views
Problem: f=np.loadtxt('Single Small Angle 1.txt',unpack=True,skiprows=2) g=np.loadtxt('Single Small Angle 5.txt',unpack=True,skiprows=2) x = f-g[:,:11944] t=range(len(x)) m=math.log10(abs(x)) np.polyfit(t,m) plt.plot(t,abs(x)) plt.show() I'm just not sure on how to fix my issue. It keeps saying: m=math.log10(abs(x)) TypeError: only length-1 arrays can be converted to Python scalars
asked Jan 7 Mashhoodch 9.1k points
0 votes
1 answer 33 views
I know there is a method for a Python list to return the first index of something: >>> l = [1, 2, 3] >>> l.index(2) 1 Is there something like that for NumPy arrays?
asked Oct 26, 2020 psandprop 2.4k points
0 votes
2 answers 163 views
In numpy, I have two "arrays", X is (m,n) and y is a vector (n,1) using X*y I am getting the error ValueError: operands could not be broadcast together with shapes (97,2) (2,1) When (97,2)x(2,1) is clearly a legal matrix operation and should give me a (97,1) vector EDIT: I have corrected this using X.dot(y) but the original question still remains.
asked Oct 24, 2020 psandprop 2.4k points
1 vote
1 answer 174 views
Problem: I wrote a program in python to check if two numbers are equal without using arithmetic and comparison operators. The code I wrote is: def Same(a, b): while (a & b != 0): summon = a & b a = a ^ b b = summon << 1 return a if Same( ... . So, I can not check if two numbers are equal without using arithmetic and comparison operators. Can anyone provide me any code of this. Thanks in advance.
asked Apr 22, 2020 samhaz 5k points
1 vote
2 answers 1.5K views
Problem: I have an array with some data in a text file. I want to load it to my program and run an adding function in my program. I got this error &ldquo;numpy.ndarray object is not callable&rdquo; When I run my program. Any solution? Array and sample codes attached below. [ 1 3 2 4 3 5 2 ... .txt")## to load the above two column xy= data for XY in xy: n=0 Z=XY(n,0)+XY(n,1) n=i+1 print (Z)
asked Mar 6, 2020 Gavin 15.3k points
To see more, click for the full list of questions or popular tags.