numpy.broadcast_to() function – Python (original) (raw)
Last Updated : 18 Aug, 2020
numpy.broadcast_to() function broadcast an array to a new shape.
Syntax : numpy.broadcast_to(array, shape, subok = False)
Parameters :
array : [array_liket] The array to broadcast.
shape : [tuple] The shape of the desired array.
subok : [bool, optional] If True, then sub-classes will be passed-through, otherwise by default, the returned array will be forced to be a base-class array.
Return : [array] The output array.
Code #1 :
Python3
import
numpy as geek
arr
=
geek.array([
1
,
2
,
3
,
4
])
gfg
=
geek.broadcast_to(arr, (
4
,
4
))
print
(gfg)
Output :
[[1 2 3 4]
[1 2 3 4]
[1 2 3 4]
[1 2 3 4]]
Code #2 :
Python3
import
numpy as geek
arr
=
geek.array([
1
,
2
,
3
,
4
,
5
])
gfg
=
geek.broadcast_to(arr, (
5
,
5
))
print
(gfg)
Output :
[[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]]
Similar Reads
- numpy.fromstring() function – Python numpy.fromstring() function create a new one-dimensional array initialized from text data in a string. Syntax : numpy.fromstring(string, dtype = float, count = -1, sep = ' ') Parameters : string : [str] A string that contained the data. dtype : [data-type, optional] Data-type of the array. Default d 1 min read
- numpy.fromiter() function – Python NumPy's fromiter() function is a handy tool for creating a NumPy array from an iterable object. This iterable can be any Python object that provides elements one at a time. The function is especially useful when you need to convert data from a custom data source, like a file or generator, into a Num 2 min read
- numpy.who function - Python numpy.who() function print the NumPy arrays in the given dictionary. Syntax : numpy.who(vardict = None) Parameters : vardict : [dict, optional] A dictionary possibly containing ndarrays. Return : Returns ‘None’. If there is no dictionary passed in or vardict is None then returns NumPy arrays in the 1 min read
- numpy.fromfunction() function – Python numpy.fromfunction() function construct an array by executing a function over each coordinate and the resulting array, therefore, has a value fn(x, y, z) at coordinate (x, y, z). Syntax : numpy.fromfunction(function, shape, dtype) Parameters : function : [callable] The function is called with N para 2 min read
- numpy.frombuffer() function – Python numpy.frombuffer() function interpret a buffer as a 1-dimensional array. Syntax : numpy.frombuffer(buffer, dtype = float, count = -1, offset = 0) Parameters : buffer : [buffer_like] An object that exposes the buffer interface. dtype : [data-type, optional] Data-type of the returned array, default da 1 min read
- How to call a function in Python Python is an object-oriented language and it uses functions to reduce the repetition of the code. In this article, we will get to know what are parts, How to Create processes, and how to call them. In Python, there is a reserved keyword "def" which we use to define a function in Python, and after "d 5 min read
- numpy.matrix.A() function - Python numpy.matrix.A() function return self as an ndarray object. Syntax : numpy.matrix.A() Parameters : None Return : [ndarray] Return self as an ndarray. Code #1 : # Python program explaining # numpy.matrix.A() function # importing numpy as geek import numpy as geek mat = geek.matrix(geek.arange(9).resh 1 min read
- numpy.i0() function | Python numpy.i0() function is the modified Bessel function of the first kind, order 0. it's usually denoted by I0. Syntax : numpy.i0(x) Parameters : x : [array_like, dtype float or complex] Argument of the Bessel function. Return : [ndarray, shape = x.shape, dtype = x.dtype] The modified Bessel function ev 1 min read
- Python | Numpy.broadcast_arrays() method With the help of Numpy.broadcast_arrays() method, we can get the one broadcasted array with the help of two or more arrays by using Numpy.broadcast_arrays() method. Syntax : Numpy.broadcast_arrays() Return : Return the broadcasted array using numpy. Example #1 : In this example we can see that by us 1 min read
- Pass a List to a Function in Python In Python, we can pass a list to a function, allowing to access or update the list's items. This makes the function more versatile and allows us to work with the list in many ways. Passing list by Reference When we pass a list to a function by reference, it refers to the original list. If we make an 2 min read