Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

what does .shape do in python

#The shape attribute for numpy arrays returns the dimensions of the array. 
#If Y has n rows and m columns, then Y. shape is (n,m) .
import numpy as np
arr= np.array([[6, 1, 2, 1],
               [5, 4, 6, 7,],
               [6, 7, 2, 1,]])
result = np.shape(arr)
print(result)
#will return (3,4)
Comment

shape of variable python

variable.shape()
Comment

shape function python

# Example from https://numpy.org/doc/stable/reference/generated/numpy.ndarray.shape.html
y = np.zeros((2, 3, 4))
y.shape # this returns (2, 3, 4)
Comment

shape in python

If you want to draw a shape download/install a GUI Library for Python like Pygame

import pygame as pg #Optional, just write: import pygame



#Draw a rectangle: pg.draw.rect(surface, (r, g, b), pg.Rect(x, y, width, height)

#Draw a circle: pg.draw.circle(surface, (r, g, b), (x, y), radius)

#Draw a line: pg.draw.circle(surface, (r, g, b), (x1, y1), (x2, y2), width))

#Draw a custom shape: pg.draw.polygon(surface, (r, g, b), points, width) #points is a list of
#points like: points = [(x1, y1), (x2, y2), (x3, y3)... (xn, yn)]

#Draw an ellipse: pg.draw.ellipse(surface, (r, g, b), pg.Rect(x, y, width, height))
#The rectangle is just for the location and dimensions of the ellipse

#Draw an arc: pg.draw.arc(surface, (r, g, b), pg.Rect(x, y, width, height), start_angle, stop_angle)
#The rect is for dimensions and location of the arc

#There is also anti-aliased (aa) shapes which I wont get into but it means the shapes will
#be 'smoother'.

Comment

PREVIOUS NEXT
Code Example
Python :: add key value in each dictonary in the list 
Python :: python if loop 
Python :: fill na with average pandas 
Python :: Pass a variable to dplyr "rename" to change columnname 
Python :: Check if all values in list are greater than a certain number 
Python :: numpy difference between two arrays 
Python :: RSA with python 
Python :: python 3.9 release date 
Python :: django values_list 
Python :: text detection from image using opencv python 
Python :: find last element in list python 
Python :: python string: immutable string 
Python :: python pattern 
Python :: NEW CALENDAR MODULE 
Python :: csv to txt code pandas 
Python :: stringindexer pyspark 
Python :: python rabbitmq 
Python :: 2d array python initialize 
Python :: camp cretaceous.com 
Python :: python dataframe limit rows 
Python :: django.db.utils.IntegrityError: NOT NULL constraint failed 
Python :: sublime autocomplete python 
Python :: python numpy euler 
Python :: get_int python 
Python :: utils/decorators.py", line 11, in __get__ raise AttributeError("This method is available only on the class, not on instances.") AttributeError: This method is available only on the class, not on instances. 
Python :: generate 50 characters long for django 
Python :: linux pyspark select java version 
Python :: how many orders has customer made database python 
Shell :: copy ssh key mac 
Shell :: git allow unrelated histories 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =