Questions tagged [linspace]

56 questions
65
votes
4 answers

What is the difference between np.linspace and np.arange?

I have always used np.arange. I recently came across np.linspace. I am wondering what exactly is the difference between them... Looking at their documentation: np.arange: Return evenly spaced values within a given interval. np.linspace: Return…
10
votes
3 answers

Equidistant points between two points?

I am trying to know equidistant points between two points. For example: p1 = (1,1) p2 = (5,5) The answer that I am expecting is: def getEquidistantPoints(p1, p2, HowManyParts): #some code return (array with points) In this example, with…
mikesneider
  • 772
  • 2
  • 10
  • 28
6
votes
2 answers

How to exclude starting point from linspace function under numpy in python?

I want to exclude starting point from a array in python using numpy. How I can execute? For example I want to exclude 0, but want to continue from the very next real number(i.e want to run from greater than 0) following code x=np.linspace(0,2,10)
Moslem Uddin
  • 61
  • 1
  • 4
3
votes
3 answers

how to efficiently create a range of float numbers

Suppose I want to create a set of float numbers starting from 0.1 to 0.00001 as first diving by two and then diving by 5. In other words, I'd like to get the numbers shown below. 0.1 0.05 0.01 0.005 0.001 0.0005 0.0001 0.00005 0.00001 For this…
whitepanda
  • 471
  • 2
  • 12
3
votes
1 answer

Open interval (a,b) and half-open interval (a,b] using Python's linspace

A half-open interval of the form [0,0.5) can be created using the following code: rv = np.linspace(0., 0.5, nr, endpoint=False) where nr is the number of points in the interval. Question: How do I use linspace to create an open interval of the form…
jonem
  • 429
  • 4
  • 12
2
votes
2 answers

TypeError: only size-1 arrays can be converted to Python scalars when trying to plot a function

I've got the current code: from math import cos, sin, pi import numpy as np import matplotlib.pyplot as plt def f(x): values = [] s = 0 for n in range(1, 6, 1): s += -((2/(n*pi))*(((cos((n*pi)/2))-1)*(sin((n/2)*x)))) …
2
votes
2 answers

np.where() with np.linspace()

I am trying to find index of an element in x_norm array with np.where() but it doesn' t work well. Is there a way to find index of element? x_norm = np.linspace(-10,10,1000) np.where(x_norm == -0.19019019) Np.where works with np.arange() and can…
madracoon
  • 23
  • 2
2
votes
1 answer

Make a color grid with different colors for each index

Ideally using Numpy and PIL, I'd like to make a grid of colors for a image segmentation program I'm making. Not all of the colors have to be unique, but, each color should be distinct from its neighbors and recognizable for its position. The idea…
chenjesu
  • 734
  • 6
  • 14
2
votes
2 answers

Linearly Spaced Array in C

I'm trying to replicate the linspace functions from Matlab and numpy (python) in C however, I keep getting the warning about dereferencing NULL pointer. I'm very much a novice at C and having only worked in Matlab, python and lua before, pointers…
SamuraiMelon
  • 297
  • 3
  • 11
2
votes
0 answers

Create numpy array of arrays with leading zeros and different start- and stop-points

I have different integer start and stop values and need all integer values in between as arrays in one array of shape (theRange, finalLength). Example: finalLength = 6 start = 2 stop = 3456 theRange = (stop - start) + 1 >>> array([[0, 0, 0, 0, 0,…
STARmin
  • 25
  • 1
  • 9
2
votes
3 answers

Replace items in list with another items (small lists) depending on several conditions

I have a list of numbers and I want to replace each number with a list binary pattern depending on several conditions. I have a working code for doing so, but I am wondering if there is a faster more efficient one because if I wanted to add more…
motaha
  • 363
  • 2
  • 5
  • 19
1
vote
1 answer

Matplotlib Contour Graphs

I am a student using matplotlib for research, and I am trying to plot some data points for two variables alongside the ratio (z) of x/y or the previous two variables. I am a bit new to this, but where would I insert my points? Right now I have…
1
vote
1 answer

Why does numpy linspace() function result in equally-spaced float values instead of integers?

vec4=np.linspace(0,100,10) print(vec4) Running this results in [ 0. 11.11111111 22.22222222 33.33333333 44.44444444 55.55555556 66.66666667 77.77777778 88.88888889 100. ] Why is this not giving integers? I was expecting…
xxxstack
  • 11
  • 2
1
vote
1 answer

Non-evenly spaced np.array with more points near the boundary

I have an interval, say (0, 9) and I have to generate points between them such that they are denser at the both the boundaries. I know the number of points, say n_x. alpha decides the "denseness" of the system such that points are evenly spaced if…
Jarwin
  • 1,045
  • 1
  • 9
  • 30
1
vote
1 answer

How to loop through a series and create a new series based on values from the original series?

I am trying to create a new series that uses entries from a series of two columns. Each column contains a limit, upper and lower and I want to create an array for each entry of the new series. Series…
1
2 3 4